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.

235 lines
6.3 KiB

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