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.

138 lines
4.1 KiB

  1. /*
  2. * Error checking support methods
  3. */
  4. #ifndef DUI_BASE_ERROR_H_INCLUDED
  5. #define DUI_BASE_ERROR_H_INCLUDED
  6. #pragma once
  7. namespace DirectUI
  8. {
  9. ////////////////////////////////////////////////////////
  10. // DirectUser debugging services
  11. #define QUOTE(s) #s
  12. #define STRINGIZE(s) QUOTE(s)
  13. #define _countof(x) (sizeof(x) / sizeof(x[0]))
  14. DECLARE_INTERFACE(IDebug)
  15. {
  16. STDMETHOD_(BOOL, AssertFailedLine)(THIS_ LPCSTR pszExpression, LPCSTR pszFileName, UINT idxLineNum) PURE;
  17. STDMETHOD_(BOOL, IsValidAddress)(THIS_ const void * lp, UINT nBytes, BOOL bReadWrite) PURE;
  18. STDMETHOD_(void, BuildStack)(THIS_ HGLOBAL * phStackData, UINT * pcCSEntries) PURE;
  19. STDMETHOD_(BOOL, Prompt)(THIS_ LPCSTR pszExpression, LPCSTR pszFileName, UINT idxLineNum, LPCSTR pszTitle) PURE;
  20. };
  21. EXTERN_C DUSER_API IDebug* WINAPI GetDebug();
  22. EXTERN_C DUSER_API void _cdecl AutoTrace(const char* pszFormat, ...);
  23. #define IDebug_AssertFailedLine(p, a, b, c) (p ? (p)->AssertFailedLine(a, b, c) : false)
  24. #define IDebug_IsValidAddress(p, a, b, c) (p ? (p)->IsValidAddress(a, b, c) : false)
  25. #define IDebug_BuildStack(p, a, b) (p ? (p)->BuildStack(a, b) : false)
  26. #define IDebug_Prompt(p, a, b, c, d) (p ? (p)->Prompt(a, b, c, d) : false)
  27. // Define AutoDebugBreak
  28. #ifndef AutoDebugBreak
  29. #define AutoDebugBreak() ForceDebugBreak()
  30. #endif
  31. ////////////////////////////////////////////////////////
  32. // DirectUI debugging macros
  33. #if DBG
  34. #define DUIAssert(f, comment) \
  35. { \
  36. if (!((f)) && IDebug_AssertFailedLine(GetDebug(), STRINGIZE((f)) "\r\n" comment, __FILE__, __LINE__)) \
  37. AutoDebugBreak(); \
  38. }
  39. #define DUIAssertNoMsg(f) \
  40. { \
  41. if (!((f)) && IDebug_AssertFailedLine(GetDebug(), STRINGIZE((f)), __FILE__, __LINE__)) \
  42. AutoDebugBreak(); \
  43. }
  44. #define DUIAssertForce(comment) \
  45. { \
  46. if (IDebug_AssertFailedLine(GetDebug(), STRINGIZE((f)) "\r\n" comment, __FILE__, __LINE__)) \
  47. AutoDebugBreak(); \
  48. }
  49. #define DUIPrompt(comment, prompt) \
  50. { \
  51. if (IDebug_Prompt(GetDebug(), comment, __FILE__, __LINE__, prompt)) \
  52. AutoDebugBreak(); \
  53. }
  54. #define DUIVerifyNoMsg(f) DUIAssertNoMsg((f))
  55. #define DUIVerify(f, comment) DUIAssert((f), comment)
  56. #define DUITrace AutoTrace
  57. #else
  58. #define DUIAssertNoMsg(f) ((void)0)
  59. #define DUIAssert(f, comment) ((void)0)
  60. #define DUIAssertForce(comment) ((void)0)
  61. #define DUIPrompt(comment, prompt) ((void)0)
  62. #define DUIVerifyNoMsg(f) ((void)(f))
  63. #define DUIVerify(f, comment) ((void)(f, comment))
  64. #define DUITrace 1 ? (void) 0 : AutoTrace
  65. #endif
  66. ////////////////////////////////////////////////////////
  67. // Error codes
  68. // If any DUI API can fail to an abnormal program event, the API's return value
  69. // is always HRESULT. Any API that isn't part of this category either returns
  70. // void or any other data type
  71. //
  72. // All erroneous program events (internal invalid state or invalid parameters)
  73. // are handled by asserts
  74. #define DUI_E_USERFAILURE MAKE_DUERROR(1001)
  75. #define DUI_E_NODEFERTABLE MAKE_DUERROR(1002)
  76. #define DUI_E_PARTIAL MAKE_DUERROR(1003)
  77. ////////////////////////////////////////////////////////
  78. // Profiling support
  79. #ifdef PROFILING
  80. void ICProfileOn();
  81. void ICProfileOff();
  82. #define ProfileOn() ICProfileOn()
  83. #define ProfileOff() ICProfileOff()
  84. #else
  85. #define ProfileOn()
  86. #define ProfileOff()
  87. #endif
  88. ////////////////////////////////////////////////////////
  89. // Quick profiling
  90. #define StartBlockTimer() __int64 _dFreq, _dStart, _dStop; \
  91. QueryPerformanceFrequency((LARGE_INTEGER*)&_dFreq); \
  92. QueryPerformanceCounter((LARGE_INTEGER*)&_dStart)
  93. #define StopBlockTimer() QueryPerformanceCounter((LARGE_INTEGER*)&_dStop)
  94. #define BlockTime() (((_dStop - _dStart) * 1000) / _dFreq)
  95. void ForceDebugBreak();
  96. } // namespace DirectUI
  97. #endif // DUI_BASE_ERROR_H_INCLUDED