misc/libphysfs/lzma/CPP/Windows/Error.cpp
changeset 13886 99b265e0d1d0
parent 13885 5f819b90d479
child 13887 b172a5d40eee
equal deleted inserted replaced
13885:5f819b90d479 13886:99b265e0d1d0
     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
       
    11 extern bool g_IsNT;
       
    12 #endif
       
    13 
       
    14 namespace NWindows {
       
    15 namespace NError {
       
    16 
       
    17 bool 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
       
    30 bool 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 }}