# HG changeset patch # User Andre Heinecke # Date 1396349421 0 # Node ID 3595ea4fd3fb98fa412d997b4eef8dd7ca62d2d9 # Parent bd7fb50078b4d60c7eca8f2a26723d1a0c0a1c87 Use getLastErrorMsg from logging diff -r bd7fb50078b4 -r 3595ea4fd3fb cinst/windowsstore.c --- a/cinst/windowsstore.c Tue Apr 01 10:49:40 2014 +0000 +++ b/cinst/windowsstore.c Tue Apr 01 10:50:21 2014 +0000 @@ -6,32 +6,7 @@ #include "errorcodes.h" #include "listutil.h" #include "strhelp.h" - -static LPWSTR -getLastErrorMsg() -{ - LPWSTR bufPtr = NULL; - DWORD err = GetLastError(); - FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, err, 0, (LPWSTR) &bufPtr, 0, NULL); - if (!bufPtr) - { - HMODULE hWinhttp = GetModuleHandleW (L"crypt32"); - if (hWinhttp) - { - FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_HMODULE | - FORMAT_MESSAGE_IGNORE_INSERTS, - hWinhttp, HRESULT_CODE (err), 0, - (LPWSTR) &bufPtr, 0, NULL); - } - } - if (!bufPtr) - printf ("Error getting last error for code: %lx \n", err); - return bufPtr; -} +#include "logging.h" static PCCERT_CONTEXT b64_to_cert_context(char *b64_data, size_t b64_size) @@ -59,11 +34,11 @@ if (pCert == NULL) { - LPWSTR error = getLastErrorMsg(); + char *error = getLastErrorMsg(); if (error) { - printf ("Failed to create cert context: %S \n", error); - LocalFree (error); + printf ("Failed to create cert context: %s \n", error); + free (error); } return NULL; } @@ -90,11 +65,11 @@ if (pc_to_remove == NULL) { - LPWSTR error = getLastErrorMsg(); + char *error = getLastErrorMsg(); if (error) { - printf ("Failed to create cert context: %S \n", error); - LocalFree (error); + printf ("Failed to create cert context: %s \n", error); + free (error); } continue; } @@ -120,9 +95,9 @@ The CertDeleteCertificateFromStore function always frees pCertContext by calling the CertFreeCertificateContext function, even if an error is encountered. */ - LPWSTR error = getLastErrorMsg(); - printf ("Error deleting certificate. %S", error); - LocalFree (error); + char *error = getLastErrorMsg(); + printf ("Error deleting certificate. %s", error); + free (error); continue; } } @@ -174,11 +149,11 @@ CertFreeCertificateContext (pc_to_add); if (!ret) { - LPWSTR error = getLastErrorMsg(); + char *error = getLastErrorMsg(); if (error) { - printf ("Failed to add certificate: %S \n", error); - LocalFree (error); + printf ("Failed to add certificate: %s \n", error); + free (error); } } }