Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 2000
  6. //
  7. // File: cscpin.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "pch.h"
  11. #pragma hdrstop
  12. #include "error.h"
  13. CWinError::CWinError(
  14. DWORD dwError
  15. )
  16. {
  17. _Initialize(dwError, false);
  18. }
  19. CWinError::CWinError(
  20. HRESULT hr
  21. )
  22. {
  23. _Initialize(DWORD(hr), true);
  24. }
  25. void
  26. CWinError::_Initialize(
  27. DWORD dwError,
  28. bool bHResult
  29. )
  30. {
  31. if (0 == FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
  32. NULL,
  33. dwError,
  34. 0,
  35. (LPWSTR)m_szText,
  36. ARRAYSIZE(m_szText),
  37. NULL))
  38. {
  39. LPCTSTR pszFmt = L"Error code %d";
  40. if (bHResult)
  41. {
  42. pszFmt = L"Error code 0x%08X";
  43. }
  44. wnsprintf(m_szText, ARRAYSIZE(m_szText), pszFmt, dwError);
  45. }
  46. }