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.

114 lines
1.9 KiB

  1. //
  2. // auto_chk.h
  3. //
  4. #pragma once
  5. #ifdef _DEBUG_AUTOHR
  6. #include "dbg.h" // CDebug
  7. #endif
  8. class auto_hr
  9. {
  10. public:
  11. auto_hr() : hr(0) {}
  12. auto_hr& operator= (HRESULT rhs)
  13. {
  14. hr = rhs;
  15. #ifdef _DEBUG_AUTOHR
  16. if (debug().CheckHrFail())
  17. throw HRESULT (debug().m_pInfo->m_hr);
  18. #endif
  19. if (FAILED(rhs))
  20. {
  21. #ifdef _DEBUG_AUTOHR
  22. if (debug().m_pInfo->m_bDebugBreakOnError)
  23. #ifdef _M_IX86
  24. __asm int 3;
  25. #else
  26. DebugBreak();
  27. #endif
  28. #endif
  29. throw HRESULT(rhs);
  30. }
  31. return *this;
  32. };
  33. operator HRESULT ()
  34. { return hr; }
  35. HRESULT operator <<(HRESULT h)
  36. {
  37. hr = h;
  38. return hr;
  39. }
  40. protected:
  41. auto_hr& operator= (bool rhs) { return *this; }
  42. auto_hr& operator= (int rhs) { return *this; }
  43. auto_hr& operator= (ULONG rhs) { return *this; }
  44. HRESULT hr;
  45. };
  46. class auto_os
  47. {
  48. public:
  49. auto_os() : dw(0) {}
  50. auto_os& operator= (LONG rhs)
  51. {
  52. dw = rhs;
  53. #ifdef _DEBUG_AUTOHR
  54. if (debug().CheckOsFail())
  55. throw int (debug().m_pInfo->m_os);
  56. #endif
  57. if (rhs)
  58. {
  59. #ifdef _DEBUG_AUTOHR
  60. if (debug().m_pInfo->m_bDebugBreakOnError)
  61. #ifdef _M_IX86
  62. __asm int 3;
  63. #else
  64. DebugBreak();
  65. #endif
  66. #endif
  67. throw int (rhs);
  68. }
  69. return *this;
  70. };
  71. auto_os& operator= (BOOL rhs)
  72. {
  73. dw = rhs;
  74. #ifdef _DEBUG_AUTOHR
  75. if (debug().CheckOsFail())
  76. throw int (debug().m_pInfo->m_os);
  77. #endif
  78. if (!rhs)
  79. {
  80. #ifdef _DEBUG_AUTOHR
  81. if (debug().m_pInfo->m_bDebugBreakOnError)
  82. #ifdef _M_IX86
  83. __asm int 3;
  84. #else
  85. DebugBreak();
  86. #endif
  87. #endif
  88. throw int (GetLastError());
  89. }
  90. return *this;
  91. };
  92. operator LONG ()
  93. { return dw; }
  94. protected:
  95. DWORD dw;
  96. };