Error.cpp 1.1 KB

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