-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwaperror.c
More file actions
31 lines (26 loc) · 870 Bytes
/
Copy pathwaperror.c
File metadata and controls
31 lines (26 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#define WIN32_LEAN_AND_MEAN
#include <winstrct.h>
#include <stdio.h>
#pragma comment(lib, "user32")
void win_perrorA(LPCSTR __errmsg)
{
LPSTR errmsg = NULL;
DWORD errcode = GetLastError();
FormatMessageA(FORMAT_MESSAGE_MAX_WIDTH_MASK |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, errcode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&errmsg, 0, NULL);
if (__errmsg ? !!*__errmsg : FALSE)
if (errmsg != NULL)
oem_printf(stderr, "%1: %2%%n", __errmsg, errmsg);
else
fprintf(stderr, "%s: Win32 error %u\n", __errmsg, (DWORD)errcode);
else
if (errmsg != NULL)
oem_printf(stderr, "%1%%n", errmsg);
else
fprintf(stderr, "Win32 error %u\n", (DWORD)errcode);
if (errmsg != NULL)
LocalFree(errmsg);
}