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.

274 lines
9.5 KiB

  1. //////////////////////////////////////////////////////////////////
  2. // File : dbg.h
  3. // Purpose : MACRO definition for showing debug message
  4. //
  5. //
  6. // Copyright(c) 1991-1997, Microsoft Corp. All rights reserved
  7. //
  8. //////////////////////////////////////////////////////////////////
  9. #ifndef _DBG_H_
  10. #define _DBG_H_
  11. #ifdef __cplusplus
  12. # define InlineFunc inline
  13. #else
  14. # define InlineFunc __inline
  15. #endif
  16. //----------------------------------------------------------------
  17. // Callback function prototype
  18. //----------------------------------------------------------------
  19. typedef VOID (WINAPI *LPFNDBGCALLBACKA)(LPSTR lpstr);
  20. typedef VOID (WINAPI *LPFNDBGCALLBACKW)(LPWSTR lpwstr);
  21. //-------------------------------------------------------
  22. //MACRO function prototype declare.
  23. //It is valid only if compliled with _DEBUG definition.
  24. //-------------------------------------------------------
  25. //////////////////////////////////////////////////////////////////
  26. // Function : DBGSetCallback
  27. // Type : VOID
  28. // Purpose : Set debug callback function.
  29. // callback function has set, when DBG() has called,
  30. // call this callback function with formatted message string.
  31. // Args :
  32. // : LPFNDBGCALLBACKA lpfnDbgCallbackA
  33. // : LPFNDBGCALLBACKW lpfnDbgCallbackW
  34. // Return : VOID
  35. // DATE : Tue Jan 06 12:21:05 1998
  36. //////////////////////////////////////////////////////////////////
  37. //VOID DBGSetCallback(LPFNDBGCALLBACKA lpfnDbgCallbackA, LPFNDBGCALLBACKW lpfnDbgCallbackW);
  38. //////////////////////////////////////////////////////////////////
  39. // Function : DBGEnableOutput
  40. // Type : VOID
  41. // Purpose : On off OutputDebugString to COM.
  42. // Args :
  43. // : BOOL fOn
  44. // Return :
  45. // DATE : Fri Apr 03 17:33:21 1998
  46. // Author :
  47. //////////////////////////////////////////////////////////////////
  48. //VOID DBGEnableOutput(BOOL fEnable)
  49. //////////////////////////////////////////////////////////////////
  50. // Function : DBGIsOutputEnable
  51. // Type : BOOL
  52. // Purpose :
  53. // Args : None
  54. // Return :
  55. // DATE : Fri Apr 03 17:58:28 1998
  56. // Author :
  57. //////////////////////////////////////////////////////////////////
  58. //BOOL DBGIsOutputEnable(VOID)
  59. ////////////////////////////////////////////////////////
  60. // Function : DBG
  61. // Type : VOID
  62. // Purpose : Printing ANSI debug message with same usage as printf()
  63. // Args :
  64. // : LPSTR lpstrFuncName
  65. // : ...
  66. // Example : DBGW(("Error occured data[%d]", i));
  67. // CAUTION : Must use DOUBLE Blaket to remove in Release version!!!
  68. /////////////////////////////////////////////////////////
  69. //VOID DBG((LPSTR lpstrFuncName, ...));
  70. ////////////////////////////////////////////////////////
  71. // Function: DBGW
  72. // Type : VOID
  73. // Purpose : Printing Unicode debug message with same usage as printf()
  74. // Args :
  75. // : LPWSTR lpstrFuncName
  76. // : ...
  77. // CAUTION : Shold use DOUBLE Blaket!!!
  78. // Example : DBGW(("Error occured data[%d]", i));
  79. /////////////////////////////////////////////////////////
  80. //VOID DBGW((LPWSTR lpstrFuncName, ...));
  81. //////////////////////////////////////////////////////////////////
  82. // Function : DBGMsgBox
  83. // Type : VOID
  84. // Purpose :
  85. // Args :
  86. // : LPSTR lpstrFmt
  87. // : ...
  88. // CAUTION : Shold use DOUBLE Blaket!!!
  89. // Example : DBGMsgBox(("Error occured data[%d]", i));
  90. //////////////////////////////////////////////////////////////////
  91. //VOID DBGMsgBox((LPSTR lpstrFmt, ...))
  92. //////////////////////////////////////////////////////////////////
  93. // Function : DBGAssert
  94. // Type : VOID
  95. // Purpose :
  96. // Args :
  97. // : BOOL fError
  98. // Return :
  99. // DATE : Fri Jan 09 17:17:31 1998
  100. //////////////////////////////////////////////////////////////////
  101. //VOID DBGAssert(BOOL fError)
  102. //////////////////////////////////////////////////////////////////
  103. // Function : DBGSTR
  104. // Type : VOID
  105. // Purpose :
  106. // Args :
  107. // : LPSTR lpstr
  108. //////////////////////////////////////////////////////////////////
  109. //VOID DBGSTR(LPSTR lpstr);
  110. //////////////////////////////////////////////////////////////////
  111. // Function : DBGGetErrorString
  112. // Type : VOID
  113. // Purpose : Get error message from WIN32 Error code.
  114. // Args :
  115. // : INT errorCode
  116. //////////////////////////////////////////////////////////////////
  117. //LPSTR DBGGetErrorString(INT errorCode)
  118. //////////////////////////////////////////////////////////////////
  119. // Function : DBGGetWinClass
  120. // Type : LPSTR
  121. // Purpose : Get class name string from specified window.
  122. // Args :
  123. // : HWND hwnd
  124. //////////////////////////////////////////////////////////////////
  125. //LPSTR DBGGetWinClass(HWND hwnd)
  126. //////////////////////////////////////////////////////////////////
  127. // Function : DBGGetWinText
  128. // Type : LPSTR
  129. // Purpose : Get title text string from specified window.
  130. // Args :
  131. // : HWND hwnd
  132. //////////////////////////////////////////////////////////////////
  133. //LPSTR DBGGetWinText(HWND hwnd)
  134. #ifdef _DEBUG
  135. //----------------------------------------------------------------
  136. //Function prototype declare
  137. //----------------------------------------------------------------
  138. extern VOID _debugEnableOutput (BOOL fEnable);
  139. extern BOOL _debugIsOutputEnable (VOID);
  140. extern VOID _debugSetCallback (LPFNDBGCALLBACKA lpfnCBA, LPFNDBGCALLBACKW lpfnCBW);
  141. extern VOID _debugA (LPSTR lpstrFile, INT lineNo, LPSTR lpstrMsg);
  142. extern VOID _debugW (LPWSTR lpstrFile, INT lineNo, LPWSTR lpstrMsg);
  143. extern VOID _debugMsgBoxA (LPSTR lpstrFile, INT lineNo, LPSTR lpstrMsg);
  144. extern VOID _debugAssert (LPSTR lpstrFile, INT lineNo, BOOL fError, LPSTR lpstrMsg);
  145. extern VOID _debugPrintfA (LPSTR lpstrFmt, ...);
  146. extern VOID _debugPrintfW (LPWSTR lpstrFmt, ...);
  147. extern VOID _debugOutStrA (LPSTR lpstr);
  148. extern VOID _debugOutStrW (LPWSTR lpwstr);
  149. extern LPSTR _debugVaStrA (LPSTR lpstrFmt, ...);
  150. extern LPWSTR _debugVaStrW (LPWSTR lpstrFmt, ...);
  151. extern LPWSTR _debugMulti2Wide (LPSTR lpstr);
  152. extern LPSTR _debugGetWinClass (HWND hwnd);
  153. extern LPSTR _debugGetWinText (HWND hwnd);
  154. extern LPSTR _debugGetErrorString (INT errorCode);
  155. //----------------------------------------------------------------
  156. // Macro definition
  157. //----------------------------------------------------------------
  158. # define DBGSetCallback(a,b) _debugSetCallback(a, b)
  159. # define DBGEnableOutput(a) _debugEnableOutput(a)
  160. # define DBGIsOutputEnable() _debugIsOutputEnable()
  161. # define Dbg(a) _debugA(__FILE__, __LINE__, _debugVaStrA a)
  162. # define DBGA(a) _debugA(__FILE__, __LINE__, _debugVaStrA a)
  163. # define DBGW(a) _debugW( _debugMulti2Wide(__FILE__), __LINE__, _debugVaStrW a)
  164. # define DBGMsgBox(a) _debugMsgBoxA(__FILE__, __LINE__, _debugVaStrA a)
  165. # define DBGAssert(a) _debugAssert(__FILE__, __LINE__, a, #a)
  166. # define DBGAssertSz(a,b) _debugAssert(__FILE__, __LINE__, a, b)
  167. # define DBGOutStr(a) _debugOutStrA(a)
  168. # define DBGOutStrA(a) _debugOutStrA(a)
  169. # define DBGOutStrW(a) _debugOutStrW(a)
  170. # define DBGP(a) _debugOutStrA(_debugVaStrA a)
  171. # define DBGPA(a) _debugOutStrA(_debugVaStrA a)
  172. # define DBGPW(a) _debugOutStrW(_debugVaStrW a)
  173. # define DBGGetErrorString(a) _debugGetErrorString(a)
  174. # define DBGGetWinClass(a) _debugGetWinClass(a)
  175. # define DBGGetWinText(a) _debugGetWinText(a)
  176. #else //!_DEBUG //in Release version, these will disapear...
  177. # define DBGSetCallback(a,b)
  178. # define DBGEnableOutput(a)
  179. # define DBGIsOutputEnable()
  180. # define Dbg(a)
  181. # define DBGW(a)
  182. # define DBGA(a)
  183. # define DBGP(a)
  184. # define DBGPA(a)
  185. # define DBGPW(a)
  186. # define DBGAssert(a)
  187. # define DBGAssertSz(a,b)
  188. # define DBGMsgBox(a)
  189. # define DBGOutStr(a)
  190. # define DBGOutStrA(a)
  191. # define DBGOutStrW(a)
  192. # define DBGGetErrorString(a)
  193. # define DBGGetWinClass(a)
  194. # define DBGGetWinText(a)
  195. #endif //_DEBUG
  196. //----------------------------------------------------------------
  197. //These function use variable argument, so we cannot define
  198. //"Normal" MACRO for them.
  199. //so, Use inline function that do nothing if _DEBUG is NOT set.
  200. //----------------------------------------------------------------
  201. InlineFunc VOID DBGDoNothingA(LPSTR lpstrFmt, ...) {lpstrFmt;}
  202. InlineFunc VOID DBGDoNothingW(LPWSTR lpstrFmt, ...) {lpstrFmt;}
  203. #ifdef _DEBUG
  204. #define DBGPrintf _debugPrintfA
  205. #define DBGPrintfA _debugPrintfA
  206. #define DBGPrintfW _debugPrintfW
  207. #else
  208. #define DBGPrintf DBGDoNothingA
  209. #define DBGPrintfA DBGDoNothingA
  210. #define DBGPrintfW DBGDoNothingW
  211. #endif
  212. //----------------------------------------------------------------
  213. //This is helper inline function for outputs debug string in
  214. //Retail version. if FORCE_DEBUG is defined this function works.
  215. //Some time, we met bugs than occurs only retail version,
  216. //and would like to out debug message.
  217. //----------------------------------------------------------------
  218. #ifdef FORCE_DEBUG
  219. #include <stdarg.h>
  220. //////////////////////////////////////////////////////////////////
  221. // Function : FDbg
  222. // Type : InlineFunc VOID
  223. // Purpose :
  224. // Args :
  225. // :
  226. // : LPSTR lpstrFmt
  227. // : ...
  228. // Return :
  229. // DATE : Tue Jan 06 19:06:19 1998
  230. //////////////////////////////////////////////////////////////////
  231. InlineFunc VOID FDbg(LPSTR lpstrFmt, ...)
  232. {
  233. CHAR szBuf[512];
  234. va_list ap;
  235. va_start(ap, lpstrFmt);
  236. wvsprintfA(szBuf, lpstrFmt, ap);
  237. va_end(ap);
  238. OutputDebugStringA(szBuf);
  239. return;
  240. }
  241. #else //FORCE_DEBUG
  242. InlineFunc VOID FDbg(LPSTR lpstrFmt, ...) {lpstrFmt;}
  243. #endif
  244. #endif //_DBG_H_