-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwwperror.c
More file actions
36 lines (31 loc) · 934 Bytes
/
Copy pathwwperror.c
File metadata and controls
36 lines (31 loc) · 934 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
32
33
34
35
36
#define WIN32_LEAN_AND_MEAN
#include <winstrct.h>
#include <stdio.h>
#pragma comment(lib, "user32")
void win_perrorW(LPCWSTR __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!ws!: %2%%n", __errmsg, errmsg);
else
oem_printf(stderr, "%1!ws!: Win32 error %2!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);
}