make/w32/subproc/w32err.c

52 lines
1.2 KiB
C
Raw Normal View History

1996-07-19 21:41:07 +00:00
#include <windows.h>
#include "w32err.h"
/*
1997-04-07 07:21:16 +00:00
* Description: the windows32 version of perror()
1996-07-19 21:41:07 +00:00
*
* Returns: a pointer to a static error
*
* Notes/Dependencies: I got this from
* comp.os.ms-windows.programmer.win32
*/
char *
1997-04-07 07:21:16 +00:00
map_windows32_error_to_string (DWORD ercode) {
1996-07-19 21:41:07 +00:00
/* __declspec (thread) necessary if you will use multiple threads */
__declspec (thread) static char szMessageBuffer[128];
/* Fill message buffer with a default message in
* case FormatMessage fails
*/
wsprintf (szMessageBuffer, "Error %ld", ercode);
/*
* Special code for winsock error handling.
*/
if (ercode > WSABASEERR) {
HMODULE hModule = GetModuleHandle("wsock32");
if (hModule != NULL) {
FormatMessage(FORMAT_MESSAGE_FROM_HMODULE,
hModule,
ercode,
LANG_NEUTRAL,
szMessageBuffer,
sizeof(szMessageBuffer),
NULL);
FreeLibrary(hModule);
}
} else {
/*
* Default system message handling
*/
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
ercode,
LANG_NEUTRAL,
szMessageBuffer,
sizeof(szMessageBuffer),
NULL);
}
return szMessageBuffer;
}