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.

277 lines
9.8 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 _ddbtnDbgEnableOutput (BOOL fEnable);
  139. extern BOOL _ddbtnDbgIsOutputEnable (VOID);
  140. extern VOID _ddbtnDbgSetCallback (LPFNDBGCALLBACKA lpfnCBA, LPFNDBGCALLBACKW lpfnCBW);
  141. extern VOID _ddbtnDbgA (LPSTR lpstrFile, INT lineNo, LPSTR lpstrMsg);
  142. extern VOID _ddbtnDbgW (LPWSTR lpstrFile, INT lineNo, LPWSTR lpstrMsg);
  143. extern VOID _ddbtnDbgMsgBoxA (LPSTR lpstrFile, INT lineNo, LPSTR lpstrMsg);
  144. extern VOID _ddbtnDbgAssert (LPSTR lpstrFile, INT lineNo, BOOL fError, LPSTR lpstrMsg);
  145. extern VOID _ddbtnDbgPrintfA (LPSTR lpstrFmt, ...);
  146. extern VOID _ddbtnDbgPrintfW (LPWSTR lpstrFmt, ...);
  147. extern VOID _ddbtnDbgOutStrA (LPSTR lpstr);
  148. extern VOID _ddbtnDbgOutStrW (LPWSTR lpwstr);
  149. extern LPSTR _ddbtnDbgVaStrA (LPSTR lpstrFmt, ...);
  150. extern LPWSTR _ddbtnDbgVaStrW (LPWSTR lpstrFmt, ...);
  151. extern LPWSTR _ddbtnDbgMulti2Wide (LPSTR lpstr);
  152. extern LPSTR _ddbtnDbgGetWinClass (HWND hwnd);
  153. extern LPSTR _ddbtnDbgGetWinText (HWND hwnd);
  154. extern LPSTR _ddbtnDbgGetErrorString (INT errorCode);
  155. extern LPSTR _ddbtnDbgGetVkStr (INT virtKey);
  156. //----------------------------------------------------------------
  157. // Macro definition
  158. //----------------------------------------------------------------
  159. # define DBGSetCallback(a,b) _ddbtnDbgSetCallback(a, b)
  160. # define DBGEnableOutput(a) _ddbtnDbgEnableOutput(a)
  161. # define DBGIsOutputEnable() _ddbtnDbgIsOutputEnable()
  162. # define Dbg(a) _ddbtnDbgA(__FILE__, __LINE__, _ddbtnDbgVaStrA a)
  163. # define DBGA(a) _ddbtnDbgA(__FILE__, __LINE__, _ddbtnDbgVaStrA a)
  164. # define DBGW(a) _ddbtnDbgW( _ddbtnDbgMulti2Wide(__FILE__), __LINE__, _ddbtnDbgVaStrW a)
  165. # define DBGMsgBox(a) _ddbtnDbgMsgBoxA(__FILE__, __LINE__, _ddbtnDbgVaStrA a)
  166. # define DBGAssert(a) _ddbtnDbgAssert(__FILE__, __LINE__, a, #a)
  167. # define DBGAssertSz(a,b) _ddbtnDbgAssert(__FILE__, __LINE__, a, b)
  168. # define DBGOutStr(a) _ddbtnDbgOutStrA(a)
  169. # define DBGOutStrA(a) _ddbtnDbgOutStrA(a)
  170. # define DBGOutStrW(a) _ddbtnDbgOutStrW(a)
  171. # define DBGP(a) _ddbtnDbgOutStrA(_ddbtnDbgVaStrA a)
  172. # define DBGPA(a) _ddbtnDbgOutStrA(_ddbtnDbgVaStrA a)
  173. # define DBGPW(a) _ddbtnDbgOutStrW(_ddbtnDbgVaStrW a)
  174. # define DBGGetErrorString(a) _ddbtnDbgGetErrorString(a)
  175. # define DBGGetWinClass(a) _ddbtnDbgGetWinClass(a)
  176. # define DBGGetWinText(a) _ddbtnDbgGetWinText(a)
  177. # define DBGGetVirtKeyStr(a) _ddbtnDbgGetVkStr(a)
  178. #else //!_DEBUG //in Release version, these will disapear...
  179. # define DBGSetCallback(a,b)
  180. # define DBGEnableOutput(a)
  181. # define DBGIsOutputEnable()
  182. # define Dbg(a)
  183. # define DBGW(a)
  184. # define DBGA(a)
  185. # define DBGP(a)
  186. # define DBGPA(a)
  187. # define DBGPW(a)
  188. # define DBGAssert(a)
  189. # define DBGAssertSz(a,b)
  190. # define DBGMsgBox(a)
  191. # define DBGOutStr(a)
  192. # define DBGOutStrA(a)
  193. # define DBGOutStrW(a)
  194. # define DBGGetErrorString(a)
  195. # define DBGGetWinClass(a)
  196. # define DBGGetWinText(a)
  197. # define DBGGetVirtKeyStr(a)
  198. #endif //_DEBUG
  199. //----------------------------------------------------------------
  200. //These function use variable argument, so we cannot define
  201. //"Normal" MACRO for them.
  202. //so, Use inline function that do nothing if _DEBUG is NOT set.
  203. //----------------------------------------------------------------
  204. InlineFunc VOID DBGDoNothingA(LPSTR lpstrFmt, ...) {lpstrFmt;}
  205. InlineFunc VOID DBGDoNothingW(LPWSTR lpstrFmt, ...) {lpstrFmt;}
  206. #ifdef _DEBUG
  207. #define DBGPrintf _ddbtnDbgPrintfA
  208. #define DBGPrintfA _ddbtnDbgPrintfA
  209. #define DBGPrintfW _ddbtnDbgPrintfW
  210. #else
  211. #define DBGPrintf DBGDoNothingA
  212. #define DBGPrintfA DBGDoNothingA
  213. #define DBGPrintfW DBGDoNothingW
  214. #endif
  215. //----------------------------------------------------------------
  216. //This is helper inline function for outputs debug string in
  217. //Retail version. if FORCE_DEBUG is defined this function works.
  218. //Some time, we met bugs than occurs only retail version,
  219. //and would like to out debug message.
  220. //----------------------------------------------------------------
  221. #ifdef FORCE_DEBUG
  222. #include <stdarg.h>
  223. //////////////////////////////////////////////////////////////////
  224. // Function : FDbg
  225. // Type : InlineFunc VOID
  226. // Purpose :
  227. // Args :
  228. // :
  229. // : LPSTR lpstrFmt
  230. // : ...
  231. // Return :
  232. // DATE : Tue Jan 06 19:06:19 1998
  233. //////////////////////////////////////////////////////////////////
  234. InlineFunc VOID FDbg(LPSTR lpstrFmt, ...)
  235. {
  236. CHAR szBuf[512];
  237. va_list ap;
  238. va_start(ap, lpstrFmt);
  239. wvsprintfA(szBuf, lpstrFmt, ap);
  240. va_end(ap);
  241. OutputDebugStringA(szBuf);
  242. return;
  243. }
  244. #else //FORCE_DEBUG
  245. InlineFunc VOID FDbg(LPSTR lpstrFmt, ...) {lpstrFmt;}
  246. #endif
  247. #endif //_DBG_H_