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 */
15
__declspec (thread) static char szMessageBuffer[128];
17
/* Fill message buffer with a default message in
18
* case FormatMessage fails
20
wsprintf (szMessageBuffer, "Error %ld", ercode);
23
* Special code for winsock error handling.
25
if (ercode > WSABASEERR) {
26
HMODULE hModule = GetModuleHandle("wsock32");
27
if (hModule != NULL) {
28
FormatMessage(FORMAT_MESSAGE_FROM_HMODULE,
33
sizeof(szMessageBuffer),
39
* Default system message handling
41
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
46
sizeof(szMessageBuffer),
49
return szMessageBuffer;