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.

113 lines
1.8 KiB

  1. //+--------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: CHResult.hxx
  7. //
  8. //---------------------------------------------------------------
  9. #ifndef _CHRESULT_HXX_
  10. #define _CHRESULT_HXX_
  11. #include "../../h/props.h"
  12. #include <string.h>
  13. class CHResult
  14. {
  15. public:
  16. ~CHResult()
  17. {
  18. Initialize();
  19. }
  20. CHResult()
  21. {
  22. _hr = E_FAIL;
  23. _bstrMessage = NULL;
  24. _pszFile = NULL;
  25. _ulLine = (ULONG) 0;
  26. }
  27. CHResult( HRESULT hr, const LPOLESTR pwszMessage,
  28. const LPSTR pszFile=NULL, ULONG ulLine=0 )
  29. {
  30. _hr = hr;
  31. _bstrMessage = SysAllocString( pwszMessage );
  32. _pszFile = new CHAR[strlen(pszFile) + sizeof(CHAR)];
  33. if( NULL != _pszFile )
  34. memcpy( _pszFile, pszFile, strlen(pszFile) + sizeof(CHAR) );
  35. _ulLine = ulLine;
  36. }
  37. public:
  38. operator HRESULT()
  39. {
  40. return( _hr );
  41. }
  42. operator LPOLESTR()
  43. {
  44. return( _bstrMessage );
  45. }
  46. operator =(HRESULT hr)
  47. {
  48. _hr = hr;
  49. SysFreeString( _bstrMessage );
  50. _bstrMessage = NULL;
  51. return(_hr);
  52. }
  53. public:
  54. ULONG GetLastResult()
  55. {
  56. Initialize();
  57. _hr = HRESULT_FROM_WIN32(GetLastResult());
  58. return( _hr );
  59. }
  60. LPSTR GetFile()
  61. {
  62. return( _pszFile );
  63. }
  64. ULONG GetLine()
  65. {
  66. return( _ulLine );
  67. }
  68. private:
  69. void Initialize()
  70. {
  71. _hr = E_FAIL;
  72. _ulLine = 0;
  73. SysFreeString( _bstrMessage );
  74. _bstrMessage = NULL;
  75. CoTaskMemFree( _pszFile );
  76. _pszFile = NULL;
  77. }
  78. private:
  79. HRESULT _hr;
  80. BSTR _bstrMessage;
  81. LPSTR _pszFile;
  82. ULONG _ulLine;
  83. };
  84. #define CHRESULT(hr,pwszMessage) CHResult( hr, pwszMessage, __FILE__, __LINE__ )
  85. #endif