5 * Description: the windows32 version of perror()
7 * Returns: a pointer to a static error
9 * Notes/Dependencies: I got this from
10 * comp.os.ms-windows.programmer.win32
13 map_windows32_error_to_string (DWORD ercode
) {
14 /* __declspec (thread) necessary if you will use multiple threads on MSVC */
16 __declspec (thread
) static char szMessageBuffer
[128];
18 static char szMessageBuffer
[128];
20 /* Fill message buffer with a default message in
21 * case FormatMessage fails
23 wsprintf (szMessageBuffer
, "Error %ld\n", ercode
);
26 * Special code for winsock error handling.
28 if (ercode
> WSABASEERR
) {
29 HMODULE hModule
= GetModuleHandle("wsock32");
30 if (hModule
!= NULL
) {
31 FormatMessage(FORMAT_MESSAGE_FROM_HMODULE
,
36 sizeof(szMessageBuffer
),
42 * Default system message handling
44 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
,
49 sizeof(szMessageBuffer
),
52 return szMessageBuffer
;