Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | // Windows/Error.h |
michael@0 | 2 | |
michael@0 | 3 | #include "StdAfx.h" |
michael@0 | 4 | |
michael@0 | 5 | #include "Windows/Error.h" |
michael@0 | 6 | #ifndef _UNICODE |
michael@0 | 7 | #include "Common/StringConvert.h" |
michael@0 | 8 | #endif |
michael@0 | 9 | |
michael@0 | 10 | #ifndef _UNICODE |
michael@0 | 11 | extern bool g_IsNT; |
michael@0 | 12 | #endif |
michael@0 | 13 | |
michael@0 | 14 | namespace NWindows { |
michael@0 | 15 | namespace NError { |
michael@0 | 16 | |
michael@0 | 17 | bool MyFormatMessage(DWORD messageID, CSysString &message) |
michael@0 | 18 | { |
michael@0 | 19 | LPVOID msgBuf; |
michael@0 | 20 | if(::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
michael@0 | 21 | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, |
michael@0 | 22 | NULL,messageID, 0, (LPTSTR) &msgBuf,0, NULL) == 0) |
michael@0 | 23 | return false; |
michael@0 | 24 | message = (LPCTSTR)msgBuf; |
michael@0 | 25 | ::LocalFree(msgBuf); |
michael@0 | 26 | return true; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | #ifndef _UNICODE |
michael@0 | 30 | bool MyFormatMessage(DWORD messageID, UString &message) |
michael@0 | 31 | { |
michael@0 | 32 | if (g_IsNT) |
michael@0 | 33 | { |
michael@0 | 34 | LPVOID msgBuf; |
michael@0 | 35 | if(::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
michael@0 | 36 | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, |
michael@0 | 37 | NULL, messageID, 0, (LPWSTR) &msgBuf, 0, NULL) == 0) |
michael@0 | 38 | return false; |
michael@0 | 39 | message = (LPCWSTR)msgBuf; |
michael@0 | 40 | ::LocalFree(msgBuf); |
michael@0 | 41 | return true; |
michael@0 | 42 | } |
michael@0 | 43 | CSysString messageSys; |
michael@0 | 44 | bool result = MyFormatMessage(messageID, messageSys); |
michael@0 | 45 | message = GetUnicodeString(messageSys); |
michael@0 | 46 | return result; |
michael@0 | 47 | } |
michael@0 | 48 | #endif |
michael@0 | 49 | |
michael@0 | 50 | }} |