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.

223 lines
5.8 KiB

  1. //----------------------------------------------------------------------------
  2. // File: drmerr.h
  3. //
  4. // Copyright (C) 1997-1999 Microsoft Corporation, All rights reserved.
  5. //
  6. // Description
  7. // Includes some helpful define and macros for error flow control.
  8. //
  9. // Author: dongi
  10. //----------------------------------------------------------------------------
  11. #ifndef __DRMERR_H__
  12. #define __DRMERR_H__
  13. // ----------------- BEGIN HACK ----------------------------------------
  14. // author: Davidme (though I don't want the credit!)
  15. // date: Sept 16, 1998
  16. //
  17. // The problem is that the CORg macros depend on using the Error label
  18. // and ADO defines the symbol Error in adoint.h. So any code that wants
  19. // to use both this file and ADO breaks. The hack is to fool adoint.h
  20. // to not define the Error symbol. This should not affect any C++ code
  21. // that uses adoint.h since the Error symbol is defined in adoint.h only
  22. // if the __cplusplus is not defined.
  23. //
  24. // The easy workaround if you get the error below is to #include this file
  25. // before including adoint.h.
  26. //
  27. // Hopefully this hack is less intrusive than the previous one!
  28. #ifdef _ADOINT_H_
  29. #error Name collision with ADO's Error symbol and this file's use of the Error label. To fix this problem,\
  30. define __Error_FWD_DEFINED__ before including adoint.h or include this header file before including adoint.h.
  31. #else
  32. #define __Error_FWD_DEFINED__
  33. #endif // _ADOINT_H_
  34. // ----------------- END HACK ------------------------------------------
  35. #include <wtypes.h>
  36. /*----------------------------------------------------------------------------
  37. Some hungarian style definitions
  38. ----------------------------------------------------------------------------*/
  39. #define fFalse 0
  40. #define fTrue 1
  41. #define hrOK HRESULT(S_OK)
  42. #define hrTrue HRESULT(S_OK)
  43. #define hrFalse ResultFromScode(S_FALSE)
  44. #define hrFail ResultFromScode(E_FAIL)
  45. #define hrNotImpl ResultFromScode(E_NOTIMPL)
  46. #define hrNoInterface ResultFromScode(E_NOINTERFACE)
  47. #define hrNoMem ResultFromScode(E_OUTOFMEMORY)
  48. #define hrAbort ResultFromScode(E_ABORT)
  49. #define hrInvalidArg ResultFromScode(E_INVALIDARG)
  50. #define MSCSAssert(f) ((void)0)
  51. #define HRESULT_FROM_ADO_ERROR(hr) ((hr == S_OK) ? S_OK : ((HRESULT) (hr | 0x80000000)) )
  52. /*----------------------------------------------------------------------------
  53. CORg style error handling
  54. (Historicaly stands for Check OLE Result and Goto)
  55. ----------------------------------------------------------------------------*/
  56. #define DebugMessage(a,b,c) //TODO: Define it in terms of _CrtDbgRetport or _RPTF
  57. #define _UNITEXT(quote) L##quote
  58. #define UNITEXT(quote) _UNITEXT(quote)
  59. #define CPRg(p)\
  60. do\
  61. {\
  62. if (!(p))\
  63. {\
  64. hr = hrNoMem;\
  65. DebugMessage(__FILE__, __LINE__, hr);\
  66. goto Error;\
  67. }\
  68. }\
  69. while (fFalse)
  70. #define CHRg(hResult) CORg(hResult)
  71. #define CORg(hResult)\
  72. do\
  73. {\
  74. hr = (hResult);\
  75. if (FAILED(hr))\
  76. {\
  77. DebugMessage(__FILE__, __LINE__, hr);\
  78. goto Error;\
  79. }\
  80. }\
  81. while (fFalse)
  82. #define CADORg(hResult)\
  83. do\
  84. {\
  85. hr = (hResult);\
  86. if (hr!=S_OK && hr!=S_FALSE)\
  87. {\
  88. hr = HRESULT_FROM_ADO_ERROR(hr);\
  89. DebugMessage(__FILE__, __LINE__, hr);\
  90. goto Error;\
  91. }\
  92. }\
  93. while (fFalse)
  94. #define CORgl(label, hResult)\
  95. do\
  96. {\
  97. hr = (hResult);\
  98. if (FAILED(hr))\
  99. {\
  100. DebugMessage(__FILE__, __LINE__, hr);\
  101. goto label;\
  102. }\
  103. }\
  104. while (fFalse)
  105. #define CWRg(fResult)\
  106. {\
  107. if (!(fResult))\
  108. {\
  109. hr = GetLastError();\
  110. if (!(hr & 0xFFFF0000)) hr = HRESULT_FROM_WIN32(hr);\
  111. DebugMessage(__FILE__, __LINE__, hr);\
  112. goto Error;\
  113. }\
  114. }
  115. #define CWRgl(label, fResult)\
  116. {\
  117. if (!(fResult))\
  118. {\
  119. hr = GetLastError();\
  120. if (!(hr & 0xFFFF0000)) hr = HRESULT_FROM_WIN32(hr);\
  121. DebugMessage(__FILE__, __LINE__, hr);\
  122. goto label;\
  123. }\
  124. }
  125. #define CFRg(fResult)\
  126. {\
  127. if (!(fResult))\
  128. {\
  129. hr = hrFail;\
  130. DebugMessage(__FILE__, __LINE__, hr);\
  131. goto Error;\
  132. }\
  133. }
  134. #define CFRgl(label, fResult)\
  135. {\
  136. if (!(fResult))\
  137. {\
  138. hr = hrFail;\
  139. DebugMessage(__FILE__, __LINE__, hr);\
  140. goto label;\
  141. }\
  142. }
  143. #define CARg(p)\
  144. do\
  145. {\
  146. if (!(p))\
  147. {\
  148. hr = hrInvalidArg;\
  149. DebugMessage(__FILE__, __LINE__, hr);\
  150. goto Error;\
  151. }\
  152. }\
  153. while (fFalse)
  154. //+---------------------------------------------------------------------------
  155. //
  156. // The custom _Assert we formerly used has been replaced with one that calls
  157. // the C run-time _CrtDbgReport method (same as _ASSERTE). If your project
  158. // doesn't link with the C run-time for some reason, you must provide your own
  159. // definition for _Assert before including this header file.
  160. //
  161. // I recommend using the _Assert macro and not _ASSERTE because you can replace
  162. // the implementation later by defining your own before including this header.
  163. //
  164. // IMPORTANT: If your code runs as a service or is an object that runs in a
  165. // service, you should use the INSTALL_ASSERT_EVENTLOG_HOOK macro to
  166. // install a handler that turns off the default functionality of popping
  167. // up a message box when an assertion occurs in favor of logging it to
  168. // the EventLog and debug console and then kicking you into the debugger.
  169. // This way your service won't hang trying to pop up a window.
  170. //
  171. // History: 09/17/98 davidme switched to using this CRT implementation
  172. //
  173. //----------------------------------------------------------------------------
  174. #ifndef _Assert
  175. #ifdef _DEBUG
  176. #include <crtdbg.h>
  177. #define _Assert(f) _ASSERTE(f) // use crtdbg's ASSERT
  178. int AssertEventlogHook( int, char *, int * );
  179. #define INSTALL_ASSERT_EVENTLOG_HOOK _CrtSetReportHook(AssertEventlogHook);
  180. #else // _DEBUG
  181. #define _Assert(f) ((void)0)
  182. #define INSTALL_ASSERT_EVENTLOG_HOOK
  183. #endif // _DEBUG
  184. #endif // _Assert
  185. #endif // __MSCSERR_H__