changeset 253:3595ea4fd3fb

Use getLastErrorMsg from logging
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 01 Apr 2014 10:50:21 +0000
parents bd7fb50078b4
children cb8d7af5ec3a
files cinst/windowsstore.c
diffstat 1 files changed, 13 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- 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);
             }
         }
     }

http://wald.intevation.org/projects/trustbridge/