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.

113 lines
1.8 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. dbgreslt.cxx
  6. Abstract:
  7. Error result help class
  8. Author:
  9. Steve Kiraly (SteveKi) 03-20-1998
  10. Revision History:
  11. --*/
  12. #include "precomp.hxx"
  13. #pragma hdrstop
  14. #include "dbgreslt.hxx"
  15. TDebugResult::
  16. TDebugResult(
  17. IN DWORD dwError
  18. ) : m_dwError( dwError ),
  19. m_pszError( NULL )
  20. {
  21. }
  22. TDebugResult::
  23. ~TDebugResult(
  24. VOID
  25. )
  26. {
  27. //
  28. // Release any allocated error string.
  29. //
  30. if( m_pszError && m_pszError != kstrNull )
  31. {
  32. LocalFree( const_cast<LPTSTR>( m_pszError ) );
  33. }
  34. }
  35. BOOL
  36. TDebugResult::
  37. bValid(
  38. VOID
  39. ) const
  40. {
  41. return TRUE;
  42. }
  43. TDebugResult::
  44. operator DWORD(
  45. VOID
  46. )
  47. {
  48. return m_dwError;
  49. }
  50. LPCTSTR
  51. TDebugResult::
  52. GetErrorString(
  53. VOID
  54. )
  55. {
  56. DWORD cchReturn = 0;
  57. DWORD dwFlags = 0;
  58. //
  59. // Release any allocated error string.
  60. //
  61. if( m_pszError && m_pszError != kstrNull )
  62. {
  63. LocalFree( const_cast<LPTSTR>( m_pszError ) );
  64. }
  65. //
  66. // Set the format message flags.
  67. //
  68. dwFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
  69. FORMAT_MESSAGE_IGNORE_INSERTS |
  70. FORMAT_MESSAGE_FROM_SYSTEM |
  71. FORMAT_MESSAGE_MAX_WIDTH_MASK;
  72. //
  73. // Format the message with the passed in last error.
  74. //
  75. cchReturn = FormatMessage( dwFlags,
  76. NULL,
  77. m_dwError,
  78. 0,
  79. reinterpret_cast<LPTSTR>( &m_pszError ),
  80. 0,
  81. NULL );
  82. //
  83. // If a format string was not returned set the string to null.
  84. //
  85. if( !cchReturn )
  86. {
  87. m_pszError = kstrNull;
  88. }
  89. return m_pszError;
  90. }