Resolved TODOs in debug_windows.c.

This commit is contained in:
Pietro Gagliardi 2015-04-10 12:44:42 -04:00
parent 5dd6b46b30
commit 0b7a57917a
1 changed files with 22 additions and 10 deletions

View File

@ -1,5 +1,5 @@
// 25 february 2015 // 25 february 2015
#include "uipriv_windows.h" #include "tablepriv.h"
// uncomment the following line to enable debug messages // uncomment the following line to enable debug messages
#define tableDebug #define tableDebug
@ -14,19 +14,25 @@ HRESULT logLastError(const char *context)
{ {
DWORD le; DWORD le;
WCHAR *msg; WCHAR *msg;
int parenthesize = 0; BOOL parenthesize = FALSE;
BOOL localFreeFailed = FALSE;
DWORD localFreeLastError;
le = GetLastError(); le = GetLastError();
fprintf(stderr, "%s: ", context); fprintf(stderr, "%s: ", context);
if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, le, 0, (LPWSTR) (&msg), 0, NULL) != 0) { if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, le, 0, (LPWSTR) (&msg), 0, NULL) != 0) {
fprintf(stderr, "%S (", msg); fprintf(stderr, "%S (", msg);
// TODO check error if (LocalFree(msg) != NULL) {
LocalFree(msg); localFreeFailed = TRUE;
parenthesize = 1; localFreeLastError = GetLastError();
}
parenthesize = TRUE;
} }
fprintf(stderr, "GetLastError() == %I32u", le); fprintf(stderr, "GetLastError() == %I32u", le);
if (parenthesize) if (parenthesize)
fprintf(stderr, ")"); fprintf(stderr, ")");
if (localFreeFailed)
fprintf(stderr, "; local free of system message failed with last error %I32u", localFreeLastError);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
#ifdef tableDebugStop #ifdef tableDebugStop
DebugBreak(); DebugBreak();
@ -43,19 +49,25 @@ HRESULT logLastError(const char *context)
HRESULT logHRESULT(const char *context, HRESULT hr) HRESULT logHRESULT(const char *context, HRESULT hr)
{ {
WCHAR *msg; WCHAR *msg;
int parenthesize = 0; BOOL parenthesize = FALSE;
BOOL localFreeFailed = FALSE;
DWORD localFreeLastError;
fprintf(stderr, "%s: ", context); fprintf(stderr, "%s: ", context);
// this isn't technically documented, but everyone does it, including Microsoft (see the implementation of _com_error::ErrorMessage() in a copy of comdef.h that comes with the Windows DDK) // this isn't technically documented, but everyone does it, including Microsoft (see the implementation of _com_error::ErrorMessage() in a copy of comdef.h that comes with the Windows DDK)
if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, (DWORD) hr, 0, (LPWSTR) (&msg), 0, NULL) != 0) { if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, (DWORD) hr, 0, (LPWSTR) (&msg), 0, NULL) != 0) {
fprintf(stderr, "%S (", msg); fprintf(stderr, "%S (", msg);
// TODO check error if (LocalFree(msg) != NULL) {
LocalFree(msg); localFreeFailed = TRUE;
parenthesize = 1; localFreeLastError = GetLastError();
}
parenthesize = TRUE;
} }
fprintf(stderr, "HRESULT == 0x%I32X", hr); fprintf(stderr, "HRESULT == 0x%I32X", hr);
if (parenthesize) if (parenthesize)
fprintf(stderr, ")"); fprintf(stderr, ")");
if (localFreeFailed)
fprintf(stderr, "; local free of system message failed with last error %I32u", localFreeLastError);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
#ifdef tableDebugStop #ifdef tableDebugStop
DebugBreak(); DebugBreak();
@ -79,7 +91,7 @@ HRESULT logLastError(const char *reason)
DWORD le; DWORD le;
le = GetLastError(); le = GetLastError();
// technically (I think? TODO) we don't need to do this, but let's do this anyway just to be safe // we shouldn't need to do this, but let's do this anyway just to be safe
SetLastError(le); SetLastError(le);
if (le == 0) if (le == 0)
return E_FAIL; return E_FAIL;