Fix crash - don't print DWORD error code directly, but decode it first.

This commit is contained in:
Riccardo 2020-05-08 01:09:26 +02:00 committed by GitHub
parent 28cb389130
commit 39686d5dd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -65,7 +65,16 @@ NSMutableDictionary *EnumeratePrinters(DWORD flags)
if (!EnumPrinters(flags, NULL,
2, (LPBYTE) prninfo, needed, &needed, &returned))
{
NSLog(@"Error: %s\n", GetLastError());
DWORD errorCode = GetLastError();
char *errorText = NULL;
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM||FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
errorCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&errorText,
0, NULL);
NSLog(@"Error: %lu: %s\n", errorCode, errorText);
LocalFree(errorText);
}
else
{