Leaked source code of windows server 2003
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.

157 lines
2.7 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1998 - 1999
  3. All rights reserved.
  4. Module Name:
  5. result.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 <lmerr.h>
  15. #include "result.hxx"
  16. TResult::
  17. TResult(
  18. IN DWORD dwLastError
  19. ) : _dwLastError( dwLastError )
  20. {
  21. }
  22. TResult::
  23. ~TResult(
  24. VOID
  25. )
  26. {
  27. }
  28. BOOL
  29. TResult::
  30. bValid(
  31. VOID
  32. )
  33. {
  34. return TRUE;
  35. }
  36. TResult::
  37. TResult(
  38. const TResult &rhs
  39. )
  40. {
  41. _dwLastError = rhs._dwLastError;
  42. }
  43. const TResult &
  44. TResult::
  45. operator =(
  46. const TResult &rhs
  47. )
  48. {
  49. if( this != &rhs )
  50. {
  51. _dwLastError = rhs._dwLastError;
  52. }
  53. return *this;
  54. }
  55. TResult::
  56. operator DWORD(
  57. VOID
  58. )
  59. {
  60. return _dwLastError;
  61. }
  62. BOOL
  63. TResult::
  64. bGetErrorString(
  65. IN TString &strLastError
  66. ) const
  67. {
  68. DWORD cchReturn = 0;
  69. LPTSTR pszFormatMessage = NULL;
  70. HMODULE hModule = NULL;
  71. DWORD dwFlags = 0;
  72. TLibrary *pLib = NULL;
  73. TStatusB bStatus;
  74. bStatus DBGNOCHK = FALSE;
  75. //
  76. // If the last error is from a lanman call.
  77. //
  78. if( _dwLastError >= NERR_BASE && _dwLastError <= MAX_NERR )
  79. {
  80. pLib = new TLibrary( gszNetMsgDll );
  81. if( VALID_PTR( pLib ) )
  82. {
  83. hModule = pLib->hInst();
  84. }
  85. dwFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
  86. FORMAT_MESSAGE_IGNORE_INSERTS |
  87. FORMAT_MESSAGE_FROM_HMODULE |
  88. FORMAT_MESSAGE_MAX_WIDTH_MASK;
  89. }
  90. else
  91. {
  92. dwFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
  93. FORMAT_MESSAGE_IGNORE_INSERTS |
  94. FORMAT_MESSAGE_FROM_SYSTEM |
  95. FORMAT_MESSAGE_MAX_WIDTH_MASK;
  96. }
  97. //
  98. // Format the message with the passed in last error.
  99. //
  100. cchReturn = FormatMessage( dwFlags,
  101. hModule,
  102. _dwLastError,
  103. 0,
  104. (LPTSTR)&pszFormatMessage,
  105. 0,
  106. NULL );
  107. //
  108. // If a format string was returned then copy it back to
  109. // the callers specified string.
  110. //
  111. if( cchReturn )
  112. {
  113. bStatus DBGCHK = strLastError.bUpdate( pszFormatMessage );
  114. }
  115. //
  116. // Release the format string.
  117. //
  118. if( pszFormatMessage )
  119. {
  120. LocalFree( pszFormatMessage );
  121. }
  122. //
  123. // Release the net library dll.
  124. //
  125. delete pLib;
  126. return bStatus;
  127. }