| 16 | namespace NError { |
| 17 | |
| 18 | static bool MyFormatMessage(DWORD errorCode, UString &message) |
| 19 | { |
| 20 | LPVOID msgBuf; |
| 21 | #ifndef _UNICODE |
| 22 | if (!g_IsNT) |
| 23 | { |
| 24 | if (::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
| 25 | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, |
| 26 | NULL, errorCode, 0, (LPTSTR) &msgBuf, 0, NULL) == 0) |
| 27 | return false; |
| 28 | message = GetUnicodeString((LPCTSTR)msgBuf); |
| 29 | } |
| 30 | else |
| 31 | #endif |
| 32 | { |
| 33 | if (::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
| 34 | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, |
| 35 | NULL, errorCode, 0, (LPWSTR) &msgBuf, 0, NULL) == 0) |
| 36 | return false; |
| 37 | message = (LPCWSTR)msgBuf; |
| 38 | } |
| 39 | ::LocalFree(msgBuf); |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | UString MyFormatMessage(DWORD errorCode) |
| 44 | { |
no test coverage detected