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.

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