comparison common/logging.c @ 260:e7a8b70021b6

Merged
author Sascha Wilde <wilde@intevation.de>
date Tue, 01 Apr 2014 15:46:40 +0200
parents bd7fb50078b4
children 17e1c8f37d72
comparison
equal deleted inserted replaced
259:20d515604daa 260:e7a8b70021b6
1 #include "logging.h"
2 #include "strhelp.h"
3
4 #include <stdio.h>
5
6 #ifdef WIN32
7 char *
8 getLastErrorMsg()
9 {
10 LPWSTR bufPtr = NULL;
11 DWORD err = GetLastError();
12 char *retval = NULL;
13 FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER |
14 FORMAT_MESSAGE_FROM_SYSTEM |
15 FORMAT_MESSAGE_IGNORE_INSERTS,
16 NULL, err, 0, (LPWSTR) &bufPtr, 0, NULL);
17 if (!bufPtr)
18 {
19 HMODULE hWinhttp = GetModuleHandleW (L"crypt32");
20 if (hWinhttp)
21 {
22 FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER |
23 FORMAT_MESSAGE_FROM_HMODULE |
24 FORMAT_MESSAGE_IGNORE_INSERTS,
25 hWinhttp, HRESULT_CODE (err), 0,
26 (LPWSTR) &bufPtr, 0, NULL);
27 }
28 }
29 if (!bufPtr) {
30 fprintf (stderr, "Error getting last error for code: %lx \n", err);
31 return NULL;
32 }
33
34 retval = wchar_to_utf8(bufPtr, wcslen(bufPtr));
35 LocalFree (bufPtr);
36
37 return retval;
38 }
39
40 #endif

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