Skip to content

Latest commit

 

History

History
50 lines (43 loc) · 1.08 KB

Error.cpp

File metadata and controls

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