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.

107 lines
1.7 KiB

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