|
Last change
on this file since 486 was 284, checked in by bird, 19 years ago |
|
Current make snaphot, 2005-05-16.
|
-
Property svn:eol-style
set to
native
|
|
File size:
1.2 KB
|
| Line | |
|---|
| 1 | #include <windows.h>
|
|---|
| 2 | #include "w32err.h"
|
|---|
| 3 |
|
|---|
| 4 | /*
|
|---|
| 5 | * Description: the windows32 version of perror()
|
|---|
| 6 | *
|
|---|
| 7 | * Returns: a pointer to a static error
|
|---|
| 8 | *
|
|---|
| 9 | * Notes/Dependencies: I got this from
|
|---|
| 10 | * comp.os.ms-windows.programmer.win32
|
|---|
| 11 | */
|
|---|
| 12 | char *
|
|---|
| 13 | map_windows32_error_to_string (DWORD ercode) {
|
|---|
| 14 | /* __declspec (thread) necessary if you will use multiple threads on MSVC */
|
|---|
| 15 | #ifdef _MSC_VER
|
|---|
| 16 | __declspec (thread) static char szMessageBuffer[128];
|
|---|
| 17 | #else
|
|---|
| 18 | static char szMessageBuffer[128];
|
|---|
| 19 | #endif
|
|---|
| 20 | /* Fill message buffer with a default message in
|
|---|
| 21 | * case FormatMessage fails
|
|---|
| 22 | */
|
|---|
| 23 | wsprintf (szMessageBuffer, "Error %ld\n", ercode);
|
|---|
| 24 |
|
|---|
| 25 | /*
|
|---|
| 26 | * Special code for winsock error handling.
|
|---|
| 27 | */
|
|---|
| 28 | if (ercode > WSABASEERR) {
|
|---|
| 29 | HMODULE hModule = GetModuleHandle("wsock32");
|
|---|
| 30 | if (hModule != NULL) {
|
|---|
| 31 | FormatMessage(FORMAT_MESSAGE_FROM_HMODULE,
|
|---|
| 32 | hModule,
|
|---|
| 33 | ercode,
|
|---|
| 34 | LANG_NEUTRAL,
|
|---|
| 35 | szMessageBuffer,
|
|---|
| 36 | sizeof(szMessageBuffer),
|
|---|
| 37 | NULL);
|
|---|
| 38 | FreeLibrary(hModule);
|
|---|
| 39 | }
|
|---|
| 40 | } else {
|
|---|
| 41 | /*
|
|---|
| 42 | * Default system message handling
|
|---|
| 43 | */
|
|---|
| 44 | FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
|
|---|
| 45 | NULL,
|
|---|
| 46 | ercode,
|
|---|
| 47 | LANG_NEUTRAL,
|
|---|
| 48 | szMessageBuffer,
|
|---|
| 49 | sizeof(szMessageBuffer),
|
|---|
| 50 | NULL);
|
|---|
| 51 | }
|
|---|
| 52 | return szMessageBuffer;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.