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
10 KiB

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