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.

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