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