Source code of Windows XP (NT5)
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.

736 lines
27 KiB

  1. // --------------------------------------------------------------------------------
  2. // Msoedbg.h
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // --------------------------------------------------------------------------------
  5. #ifndef __MSOEDBG_H
  6. #define __MSOEDBG_H
  7. // --------------------------------------------------------------------------------
  8. // Forwards
  9. // --------------------------------------------------------------------------------
  10. #ifdef __cplusplus
  11. interface ILogFile;
  12. #endif
  13. // --------------------------------------------------------------------------------
  14. // IF_DEBUG
  15. // --------------------------------------------------------------------------------
  16. #ifdef DEBUG
  17. #define IF_DEBUG(_block_) _block_
  18. #else
  19. #define IF_DEBUG(_block_)
  20. #endif
  21. // --------------------------------------------------------------------------------
  22. // CRLF Definitions
  23. // --------------------------------------------------------------------------------
  24. #ifdef MAC
  25. #define szCRLF "\n\r"
  26. #else // !MAC
  27. #define szCRLF "\r\n"
  28. #endif // MAC
  29. // --------------------------------------------------------------------------------
  30. //
  31. // "Normal" assertion checking. Provided for compatibility with imported code.
  32. //
  33. // Assert(a) Displays a message indicating the file and line number
  34. // of this Assert() if a == 0.
  35. //
  36. // AssertSz(a,b) As Assert(); also displays the message b (which should
  37. // be a string literal.)
  38. //
  39. // SideAssert(a) As Assert(); the expression a is evaluated even if
  40. // asserts are disabled.
  41. //
  42. // --------------------------------------------------------------------------------
  43. #undef AssertSz
  44. #undef Assert
  45. #undef SideAssert
  46. // --------------------------------------------------------------------------------
  47. // We used to define the ASSERTDATA macro as storing the _szFile
  48. // string. However, that won't work when we have Assert()'s in
  49. // pre-compiled header files. We've changed this so that we
  50. // define the _szFile for each assert. However, other functions
  51. // still use _szAssertFile such as the DEBUG PvAlloc(), HvAlloc(), etc.
  52. // --------------------------------------------------------------------------------
  53. #ifdef DEBUG
  54. #define ASSERTDATA static char _szAssertFile[]= __FILE__;
  55. #define SideAssert(_exp) Assert(_exp)
  56. #define Assert(_exp) AssertSz(_exp, "Assert(" #_exp ")")
  57. #else // DEBUG
  58. #define ASSERTDATA
  59. #define SideAssert(a) (void)(a)
  60. #define Assert(a)
  61. #endif // DEBUG
  62. // --------------------------------------------------------------------------------
  63. // IxpAssert - Used in internet transport code so as not to affect the message pump
  64. // --------------------------------------------------------------------------------
  65. #ifdef DEBUG
  66. #ifndef _X86_
  67. #define IxpAssert(a) \
  68. if (!(a)) { \
  69. DebugBreak(); \
  70. } else
  71. #else // _X86_
  72. #define IxpAssert(a) \
  73. if (!(a)) { \
  74. __asm { int 3 }; \
  75. } else
  76. #endif // _X86_
  77. #else
  78. #define IxpAssert(a)
  79. #endif // DEBUG
  80. // --------------------------------------------------------------------------------
  81. // AssertSz - Assert with a message
  82. // --------------------------------------------------------------------------------
  83. #ifdef DEBUG
  84. #define AssertSz(_exp, _msg) \
  85. if (!(_exp)) { \
  86. static char _szFile[] = __FILE__; \
  87. AssertSzFn(_msg, _szFile, __LINE__); \
  88. } else
  89. #else // DEBUG
  90. #define AssertSz(a,b)
  91. #endif // DEBUG
  92. // --------------------------------------------------------------------------------
  93. // AssertFalseSz - Assert with a message
  94. // --------------------------------------------------------------------------------
  95. #ifdef DEBUG
  96. #define AssertFalseSz(_msg) \
  97. { \
  98. static char _szFile[] = __FILE__; \
  99. AssertSzFn(_msg, _szFile, __LINE__); \
  100. }
  101. #else // DEBUG
  102. #define AssertFalseSz(a)
  103. #endif // DEBUG
  104. // --------------------------------------------------------------------------------
  105. // NFAssertSz - Non-Fatal Assert
  106. // --------------------------------------------------------------------------------
  107. #ifdef DEBUG
  108. #ifndef NFAssertSz
  109. #define NFAssertSz(_exp, _msg) \
  110. if (!(_exp)) { \
  111. static char _szFile[] = __FILE__; \
  112. static char _szAssertMsg[] = _msg; \
  113. NFAssertSzFn(_szAssertMsg, _szFile, __LINE__); \
  114. } else
  115. #endif
  116. #else // DEBUG
  117. #ifndef NFAssertSz
  118. #define NFAssertSz(a,b)
  119. #endif
  120. #endif // DEBUG
  121. // --------------------------------------------------------------------------------
  122. // NYI - Net Yet Implemented
  123. // --------------------------------------------------------------------------------
  124. #ifdef DEBUG
  125. #define NYI(_msg) \
  126. if (1) { \
  127. static char _szFnNYI[]= _msg; \
  128. static char _szNYI[]= "Not Implemented"; \
  129. AssertSzFn(_szFnNYI, _szNYI, __LINE__); \
  130. } else
  131. #else // DEBUG
  132. #define NYI(a)
  133. #endif // DEBUG
  134. // --------------------------------------------------------------------------------
  135. // AssertReadWritePtr - Assert can read and write cb from ptr
  136. // --------------------------------------------------------------------------------
  137. #ifdef DEBUG
  138. #define AssertReadWritePtr(ptr, cb) \
  139. if (IsBadReadPtr(ptr, cb) && IsBadWritePtr(ptr, cb)) { \
  140. AssertSz(FALSE, "AssertReadWritePtr: Bad Pointer"); \
  141. } else
  142. #else // DEBUG
  143. #define AssertReadWritePtr(ptr, cb)
  144. #endif // DEBUG
  145. // --------------------------------------------------------------------------------
  146. // AssertReadPtr - Assert can read cb from ptr
  147. // --------------------------------------------------------------------------------
  148. #ifdef DEBUG
  149. #define AssertReadPtr(ptr, cb) \
  150. if (IsBadReadPtr(ptr, cb)) { \
  151. AssertSz(FALSE, "AssertReadPtr: Bad Pointer"); \
  152. } else
  153. #else // DEBUG
  154. #define AssertReadPtr(ptr, cb)
  155. #endif // DEBUG
  156. // --------------------------------------------------------------------------------
  157. // AssertWritePtr - Assert can write cb to ptr
  158. // --------------------------------------------------------------------------------
  159. #ifdef DEBUG
  160. #define AssertWritePtr(ptr, cb) \
  161. if (IsBadWritePtr(ptr, cb)) { \
  162. AssertSz(FALSE, "AssertWritePtr: Bad Pointer"); \
  163. } else
  164. #else // DEBUG
  165. #define AssertWritePtr(ptr, cb)
  166. #endif // DEBUG
  167. #ifdef DEBUG
  168. #define AssertZeroMemory(ptr, cb) \
  169. if (1) { \
  170. for (DWORD _ib = 0; _ib < (cb); _ib++) { \
  171. Assert(((LPBYTE)(ptr))[_ib] == 0); } \
  172. } else
  173. #else // DEBUG
  174. #define AssertZeroMemory(ptr, cb)
  175. #endif // DEBUG
  176. // --------------------------------------------------------------------------------
  177. // Debug Output Levels
  178. // --------------------------------------------------------------------------------
  179. #define DOUT_LEVEL1 1
  180. #define DOUT_LEVEL2 2
  181. #define DOUT_LEVEL3 4
  182. #define DOUT_LEVEL4 8
  183. #define DOUT_LEVEL5 16
  184. #define DOUT_LEVEL6 32
  185. #define DOUT_LEVEL7 64
  186. // --------------------------------------------------------------------------------
  187. // Defines for DOUTLL modules
  188. // --------------------------------------------------------------------------------
  189. #define DOUTL_DRAGDROP 1
  190. #define DOUTL_ADDRBOOK 128
  191. #define DOUTL_ATTMAN 256
  192. #define DOUTL_CRYPT 1024
  193. // --------------------------------------------------------------------------------
  194. // CHECKHR - If hrExp FAILED, then Trap the Error (dbgout) and jump to exit label
  195. // Caller must have a local variable named hr and a label named exit:.
  196. // --------------------------------------------------------------------------------
  197. #define CHECKHR(hrExp) \
  198. if (FAILED (hrExp)) { \
  199. TRAPHR(hr); \
  200. goto exit; \
  201. } else
  202. #define IF_FAILEXIT(hrExp) \
  203. if (FAILED(hrExp)) { \
  204. TraceResult(hr); \
  205. goto exit; \
  206. } else
  207. #define IF_FAILEXIT_LOG(_pLog, hrExp) \
  208. if (FAILED(hrExp)) { \
  209. TraceResultLog((_pLog), hr); \
  210. goto exit; \
  211. } else
  212. // --------------------------------------------------------------------------------
  213. // CHECKALLOC - If _palloc FAILED, then Trap E_OUTOFMEMORY (dbgout) and jump to
  214. // exit label. Caller must have a local variable named hr and a label named exit:.
  215. // --------------------------------------------------------------------------------
  216. #define CHECKALLOC(_palloc) \
  217. if (NULL == (_palloc)) { \
  218. hr = TRAPHR(E_OUTOFMEMORY); \
  219. goto exit; \
  220. } else
  221. #define IF_NULLEXIT(_palloc) \
  222. if (NULL == (_palloc)) { \
  223. hr = TraceResult(E_OUTOFMEMORY); \
  224. goto exit; \
  225. } else
  226. #define IF_NULLEXIT_LOG(_pLog, _palloc) \
  227. if (NULL == (_palloc)) { \
  228. hr = TraceResultLog((_pLog), E_OUTOFMEMORY); \
  229. goto exit; \
  230. } else
  231. // --------------------------------------------------------------------------------
  232. // CHECKEXP - If _expression is TRUE, then Trap _hresult (dbgout) and jump to
  233. // exit label. Caller must have a local variable named hr and a label named exit:.
  234. // --------------------------------------------------------------------------------
  235. #define CHECKEXP(_expression, _hresult) \
  236. if (_expression) { \
  237. hr = TrapError(_hresult); \
  238. goto exit; \
  239. } else
  240. #define IF_TRUEEXIT(_expression, _hresult) \
  241. if (_expression) { \
  242. hr = TraceResult(_hresult); \
  243. goto exit; \
  244. } else
  245. #define IF_FALSEEXIT(_expression, _hresult) \
  246. if (FALSE == _expression) { \
  247. hr = TraceResult(_hresult); \
  248. goto exit; \
  249. } else
  250. // --------------------------------------------------------------------------------
  251. // TRACEMACROTYPE
  252. // --------------------------------------------------------------------------------
  253. typedef enum tagTRACEMACROTYPE {
  254. TRACE_INFO,
  255. TRACE_CALL,
  256. TRACE_RESULT
  257. } TRACEMACROTYPE;
  258. // --------------------------------------------------------------------------------
  259. // These Traces are for c++ only
  260. // --------------------------------------------------------------------------------
  261. typedef DWORD SHOWTRACEMASK;
  262. #define SHOW_TRACE_NONE 0x00000000
  263. #define SHOW_TRACE_INFO 0x00000001
  264. #define SHOW_TRACE_CALL 0x00000002
  265. #define SHOW_TRACE_ALL 0xffffffff
  266. // --------------------------------------------------------------------------------
  267. // These Traces are for c++ only
  268. // --------------------------------------------------------------------------------
  269. #if defined(__cplusplus)
  270. // --------------------------------------------------------------------------------
  271. // TRACELOGINFOINFO
  272. // --------------------------------------------------------------------------------
  273. typedef struct tagTRACELOGINFO {
  274. SHOWTRACEMASK dwMask;
  275. ILogFile *pLog;
  276. } TRACELOGINFO, *LPTRACELOGINFO;
  277. // --------------------------------------------------------------------------------
  278. // DebugTraceEx
  279. // --------------------------------------------------------------------------------
  280. #ifdef DEBUG
  281. EXTERN_C HRESULT DebugTraceEx(SHOWTRACEMASK dwMask, TRACEMACROTYPE tracetype, LPTRACELOGINFO pLog,
  282. HRESULT hr, LPSTR pszFile, INT nLine, LPCSTR pszMsg, LPCSTR pszFunc);
  283. EXTERN_C DWORD GetDebugTraceTagMask(LPCSTR pszTag, SHOWTRACEMASK dwDefaultMask);
  284. #endif
  285. // --------------------------------------------------------------------------------
  286. // TraceCall(_pszFunc)
  287. // -------------------------------------------------------------------------------
  288. #if defined(DEBUG)
  289. #if defined(MSOEDBG_TRACECALLS)
  290. #define TraceCall(_pszFunc) LPCSTR _pszfn = _pszFunc; DebugTraceEx(SHOW_TRACE_ALL, TRACE_CALL, NULL, S_OK, __FILE__, __LINE__, NULL, _pszfn)
  291. #else
  292. #define TraceCall(_pszFunc) DebugTraceEx(SHOW_TRACE_ALL, TRACE_CALL, NULL, S_OK, __FILE__, __LINE__, NULL, NULL)
  293. #endif
  294. #else
  295. #define TraceCall(_pszFunc)
  296. #endif
  297. // --------------------------------------------------------------------------------
  298. // TraceCallLog(_pszFunc)
  299. // -------------------------------------------------------------------------------
  300. #if defined(DEBUG)
  301. #if defined(MSOEDBG_TRACECALLS)
  302. #define TraceCallLog(_pLog, _pszFunc) LPCSTR _pszfn = _pszFunc; DebugTraceEx(SHOW_TRACE_ALL, TRACE_CALL, _pLog, S_OK, __FILE__, __LINE__, NULL, _pszfn)
  303. #else
  304. #define TraceCallLog(_pLog, _pszFunc) LPCSTR _pszfn = _pszFunc; DebugTraceEx(SHOW_TRACE_ALL, TRACE_CALL, _pLog, S_OK, __FILE__, __LINE__, NULL, NULL)
  305. #endif
  306. #else
  307. #define TraceCallLog(_pLog, _pszFunc)
  308. #endif
  309. // --------------------------------------------------------------------------------
  310. // TraceCallTag(_pszFunc)
  311. // -------------------------------------------------------------------------------
  312. #if defined(DEBUG)
  313. #if defined(MSOEDBG_TRACECALLS)
  314. #define TraceCallTag(_dwMask, _pszFunc) LPCSTR _pszfn = _pszFunc; DebugTraceEx(_dwMask, TRACE_CALL, NULL, S_OK, __FILE__, __LINE__, NULL, _pszfn)
  315. #else
  316. #define TraceCallTag(_dwMask, _pszFunc) LPCSTR _pszfn = _pszFunc; DebugTraceEx(_dwMask, TRACE_CALL, NULL, S_OK, __FILE__, __LINE__, NULL, NULL)
  317. #endif
  318. #else
  319. #define TraceCallTag(_dwMask, _pszFunc)
  320. #endif
  321. // --------------------------------------------------------------------------------
  322. // TraceCallSz(_pszFunc, _pszMsg)
  323. // -------------------------------------------------------------------------------
  324. #if defined(DEBUG)
  325. #if defined(MSOEDBG_TRACECALLS)
  326. #define TraceCallSz(_pszFunc, _pszMsg) LPCSTR _pszfn = _pszFunc; DebugTraceEx(SHOW_TRACE_ALL, TRACE_CALL, NULL, S_OK, __FILE__, __LINE__, _pszMsg, _pszfn)
  327. #else
  328. #define TraceCallSz(_pszFunc, _pszMsg) LPCSTR _pszfn = _pszFunc; DebugTraceEx(SHOW_TRACE_ALL, TRACE_CALL, NULL, S_OK, __FILE__, __LINE__, _pszMsg, NULL)
  329. #endif
  330. #else
  331. #define TraceCallSz(_pszFunc, _pszMsg)
  332. #endif
  333. // --------------------------------------------------------------------------------
  334. // TraceCallLogSz(_pLog, _pszFunc, _pszMsg)
  335. // -------------------------------------------------------------------------------
  336. #if defined(DEBUG)
  337. #if defined(MSOEDBG_TRACECALLS)
  338. #define TraceCallLogSz(_pLog, _pszFunc, _pszMsg) LPCSTR _pszfn = _pszFunc; DebugTraceEx(SHOW_TRACE_ALL, TRACE_CALL, _pLog, S_OK, __FILE__, __LINE__, _pszMsg, _pszfn)
  339. #else
  340. #define TraceCallLogSz(_pLog, _pszFunc, _pszMsg) LPCSTR _pszfn = _pszFunc; DebugTraceEx(SHOW_TRACE_ALL, TRACE_CALL, _pLog, S_OK, __FILE__, __LINE__, _pszMsg, NULL)
  341. #endif
  342. #else
  343. #define TraceCallLogSz(_pLog, _pszFunc, _pszMsg)
  344. #endif
  345. // --------------------------------------------------------------------------------
  346. // TraceCallTagSz(_dwMask, _pszFunc, _pszMsg)
  347. // -------------------------------------------------------------------------------
  348. #if defined(DEBUG)
  349. #if defined(MSOEDBG_TRACECALLS)
  350. #define TraceCallTagSz(_dwMask, _pszFunc, _pszMsg) LPCSTR _pszfn = _pszFunc; DebugTraceEx(_dwMask, TRACE_CALL, NULL, S_OK, __FILE__, __LINE__, _pszMsg, _pszfn)
  351. #else
  352. #define TraceCallTagSz(_dwMask, _pszFunc, _pszMsg) LPCSTR _pszfn = _pszFunc; DebugTraceEx(_dwMask, TRACE_CALL, NULL, S_OK, __FILE__, __LINE__, _pszMsg, NULL)
  353. #endif
  354. #else
  355. #define TraceCallTagSz(_dwMask, _pszFunc, _pszMsg)
  356. #endif
  357. // --------------------------------------------------------------------------------
  358. // TraceInfo(_pszMsg)
  359. // --------------------------------------------------------------------------------
  360. #if defined(DEBUG)
  361. #if defined(MSOEDBG_TRACECALLS)
  362. #define TraceInfo(_pszMsg) DebugTraceEx(SHOW_TRACE_ALL, TRACE_INFO, NULL, S_OK, __FILE__, __LINE__, _pszMsg, _pszfn)
  363. #else
  364. #define TraceInfo(_pszMsg) DebugTraceEx(SHOW_TRACE_ALL, TRACE_INFO, NULL, S_OK, __FILE__, __LINE__, _pszMsg, NULL)
  365. #endif
  366. #else
  367. #define TraceInfo(_pszMsg)
  368. #endif
  369. // --------------------------------------------------------------------------------
  370. // TraceInfoAssert(_exp, _pszMsg)
  371. // --------------------------------------------------------------------------------
  372. #if defined(DEBUG)
  373. #if defined(MSOEDBG_TRACECALLS)
  374. #define TraceInfoAssert(_exp, _pszMsg) \
  375. if (!(_exp)) { \
  376. DebugTraceEx(SHOW_TRACE_ALL, TRACE_INFO, NULL, S_OK, __FILE__, __LINE__, _pszMsg, _pszfn); \
  377. } else
  378. #else
  379. #define TraceInfoAssert(_exp, _pszMsg) \
  380. if (!(_exp)) { \
  381. DebugTraceEx(SHOW_TRACE_ALL, TRACE_INFO, NULL, S_OK, __FILE__, __LINE__, _pszMsg, NULL); \
  382. } else
  383. #endif
  384. #else
  385. #define TraceInfoAssert(_exp, _pszMsg)
  386. #endif
  387. // --------------------------------------------------------------------------------
  388. // TraceInfoSideAssert(_exp, _pszMsg)
  389. // --------------------------------------------------------------------------------
  390. #if defined(DEBUG)
  391. #if defined(MSOEDBG_TRACECALLS)
  392. #define TraceInfoSideAssert(_exp, _pszMsg) \
  393. if (!(_exp)) { \
  394. DebugTraceEx(SHOW_TRACE_ALL, TRACE_INFO, NULL, S_OK, __FILE__, __LINE__, _pszMsg, _pszfn); \
  395. } else
  396. #else
  397. #define TraceInfoSideAssert(_exp, _pszMsg) \
  398. if (!(_exp)) { \
  399. DebugTraceEx(SHOW_TRACE_ALL, TRACE_INFO, NULL, S_OK, __FILE__, __LINE__, _pszMsg, NULL); \
  400. } else
  401. #endif
  402. #else
  403. #define TraceInfoSideAssert(_exp, _pszMsg) (void)(_exp)
  404. #endif
  405. // --------------------------------------------------------------------------------
  406. // TraceInfoLog(_pLog, _pszMsg)
  407. // --------------------------------------------------------------------------------
  408. #if defined(DEBUG)
  409. #if defined(MSOEDBG_TRACECALLS)
  410. #define TraceInfoLog(_pLog, _pszMsg) DebugTraceEx(SHOW_TRACE_ALL, TRACE_INFO, _pLog, S_OK, __FILE__, __LINE__, _pszMsg, _pszfn)
  411. #else
  412. #define TraceInfoLog(_pLog, _pszMsg) DebugTraceEx(SHOW_TRACE_ALL, TRACE_INFO, _pLog, S_OK, __FILE__, __LINE__, _pszMsg, NULL)
  413. #endif
  414. #else
  415. #define TraceInfoLog(_pLog, _pszMsg) ((_pLog && _pLog->pLog) ? _pLog->pLog->TraceLog((_pLog)->dwMask, TRACE_INFO, __LINE__, S_OK, _pszMsg) : (void)0)
  416. #endif
  417. // --------------------------------------------------------------------------------
  418. // TraceInfoTag(_dwMask, _pszMsg)
  419. // --------------------------------------------------------------------------------
  420. #if defined(DEBUG)
  421. #if defined(MSOEDBG_TRACECALLS)
  422. #define TraceInfoTag(_dwMask, _pszMsg) DebugTraceEx(_dwMask, TRACE_INFO, NULL, S_OK, __FILE__, __LINE__, _pszMsg, _pszfn)
  423. #else
  424. #define TraceInfoTag(_dwMask, _pszMsg) DebugTraceEx(_dwMask, TRACE_INFO, NULL, S_OK, __FILE__, __LINE__, _pszMsg, NULL)
  425. #endif
  426. #else
  427. #define TraceInfoTag(_dwMask, _pszMsg)
  428. #endif
  429. // --------------------------------------------------------------------------------
  430. // TraceError(_hrResult)
  431. // --------------------------------------------------------------------------------
  432. #if defined(DEBUG)
  433. #if defined(MSOEDBG_TRACECALLS)
  434. #define TraceError(_hrResult) \
  435. if (FAILED(_hrResult)) { \
  436. DebugTraceEx(SHOW_TRACE_ALL, TRACE_RESULT, NULL, _hrResult, __FILE__, __LINE__, NULL, _pszfn); \
  437. } \
  438. else
  439. #else
  440. #define TraceError(_hrResult) \
  441. if (FAILED(_hrResult)) { \
  442. DebugTraceEx(SHOW_TRACE_ALL, TRACE_RESULT, NULL, _hrResult, __FILE__, __LINE__, NULL, NULL); \
  443. } \
  444. else
  445. #endif // defined(MSOEDBG_TRACECALLS)
  446. #else
  447. #define TraceError(_hrResult) _hrResult
  448. #endif // defined(DEBUG)
  449. // --------------------------------------------------------------------------------
  450. // TraceResult(_hrResult)
  451. // --------------------------------------------------------------------------------
  452. #if defined(DEBUG)
  453. #if defined(MSOEDBG_TRACECALLS)
  454. #define TraceResult(_hrResult) DebugTraceEx(SHOW_TRACE_ALL, TRACE_RESULT, NULL, _hrResult, __FILE__, __LINE__, NULL, _pszfn)
  455. #else
  456. #define TraceResult(_hrResult) DebugTraceEx(SHOW_TRACE_ALL, TRACE_RESULT, NULL, _hrResult, __FILE__, __LINE__, NULL, NULL)
  457. #endif
  458. #else
  459. #define TraceResult(_hrResult) _hrResult
  460. #endif
  461. // --------------------------------------------------------------------------------
  462. // TraceResultLog(_pLog, _hrResult)
  463. // --------------------------------------------------------------------------------
  464. #if defined(DEBUG)
  465. #if defined(MSOEDBG_TRACECALLS)
  466. #define TraceResultLog(_pLog, _hrResult) DebugTraceEx(SHOW_TRACE_ALL, TRACE_RESULT, _pLog, _hrResult, __FILE__, __LINE__, NULL, _pszfn)
  467. #else
  468. #define TraceResultLog(_pLog, _hrResult) DebugTraceEx(SHOW_TRACE_ALL, TRACE_RESULT, _pLog, _hrResult, __FILE__, __LINE__, NULL, NULL)
  469. #endif
  470. #else
  471. #define TraceResultLog(_pLog, _hrResult) ((_pLog && _pLog->pLog) ? _pLog->pLog->TraceLog((_pLog)->dwMask, TRACE_RESULT, __LINE__, _hrResult, NULL) : _hrResult)
  472. #endif
  473. // --------------------------------------------------------------------------------
  474. // TraceResultSz(_hrResult, _pszMsg) - Use to log HRESULTs
  475. // --------------------------------------------------------------------------------
  476. #if defined(DEBUG)
  477. #if defined(MSOEDBG_TRACECALLS)
  478. #define TraceResultSz(_hrResult, _pszMsg) DebugTraceEx(SHOW_TRACE_ALL, TRACE_RESULT, NULL, _hrResult, __FILE__, __LINE__, _pszMsg, _pszfn)
  479. #else
  480. #define TraceResultSz(_hrResult, _pszMsg) DebugTraceEx(SHOW_TRACE_ALL, TRACE_RESULT, NULL, _hrResult, __FILE__, __LINE__, _pszMsg, NULL)
  481. #endif
  482. #else
  483. #define TraceResultSz(_hrResult, _pszMsg) _hrResult
  484. #endif
  485. // --------------------------------------------------------------------------------
  486. // TraceResultLogSz(_pLog, _hrResult, _pszMsg) - Use to log HRESULTs
  487. // --------------------------------------------------------------------------------
  488. #if defined(DEBUG)
  489. #if defined(MSOEDBG_TRACECALLS)
  490. #define TraceResultLogSz(_pLog, _hrResult, _pszMsg) DebugTraceEx(SHOW_TRACE_ALL, TRACE_RESULT, _pLog, _hrResult, __FILE__, __LINE__, _pszMsg, _pszfn)
  491. #else
  492. #define TraceResultLogSz(_pLog, _hrResult, _pszMsg) DebugTraceEx(SHOW_TRACE_ALL, TRACE_RESULT, _pLog, _hrResult, __FILE__, __LINE__, _pszMsg, NULL)
  493. #endif
  494. #else
  495. #define TraceResultLogSz(_pLog, _hrResult, _pszMsg) ((_pLog && _pLog->pLog) ? _pLog->pLog->TraceLog((_pLog)->dwMask, TRACE_RESULT, __LINE__, _hrResult, _pszMsg) : _hrResult)
  496. #endif
  497. // --------------------------------------------------------------------------------
  498. // TraceAssert(_exp, _msg) - Performs an assertSz() and TraceInfo
  499. // --------------------------------------------------------------------------------
  500. #if defined(DEBUG)
  501. #define TraceAssert(_exp, _msg) \
  502. if (!(_exp)) { \
  503. TraceInfo(_msg); \
  504. static char _szFile[] = __FILE__; \
  505. AssertSzFn((char*) _msg, _szFile, __LINE__); \
  506. } else
  507. #else
  508. #define TraceAssert(_exp, _msg)
  509. #endif
  510. #endif // #if defined(__cplusplus)
  511. // --------------------------------------------------------------------------------
  512. // DOUT External Values
  513. // --------------------------------------------------------------------------------
  514. #ifdef DEBUG
  515. extern DWORD dwDOUTLevel;
  516. extern DWORD dwDOUTLMod;
  517. extern DWORD dwDOUTLModLevel;
  518. extern DWORD dwATLTraceLevel;
  519. #endif // DEBUG
  520. #if !defined( WIN16 ) || defined( __cplusplus )
  521. // --------------------------------------------------------------------------------
  522. // DOUTLL
  523. // --------------------------------------------------------------------------------
  524. #ifdef DEBUG
  525. __inline void __cdecl DOUTLL(int iModule, int iLevel, LPSTR szFmt, ...) {
  526. if((iModule & dwDOUTLMod) && (iLevel & dwDOUTLModLevel)) {
  527. CHAR ach[MAX_PATH];
  528. va_list arglist;
  529. va_start(arglist, szFmt);
  530. wvsprintf(ach, szFmt, arglist);
  531. va_end(arglist);
  532. lstrcat(ach, szCRLF);
  533. OutputDebugString(ach);
  534. }
  535. }
  536. #else
  537. #define DOUTLL 1 ? (void)0 : (void)
  538. #endif // DEBUG
  539. // --------------------------------------------------------------------------------
  540. // vDOUTL
  541. // --------------------------------------------------------------------------------
  542. #ifdef DEBUG
  543. __inline void vDOUTL(int iLevel, LPSTR szFmt, va_list arglist) {
  544. if (iLevel & dwDOUTLevel) {
  545. CHAR ach[MAX_PATH];
  546. wvsprintf(ach, szFmt, arglist);
  547. lstrcat(ach, szCRLF);
  548. OutputDebugString(ach);
  549. }
  550. }
  551. #else
  552. #define vDOUTL 1 ? (void)0 : (void)
  553. #endif // DEBUG
  554. // --------------------------------------------------------------------------------
  555. // DOUTL
  556. // --------------------------------------------------------------------------------
  557. #ifdef DEBUG
  558. __inline void __cdecl DOUTL(int iLevel, LPSTR szFmt, ...) {
  559. va_list arglist;
  560. va_start(arglist, szFmt);
  561. vDOUTL(iLevel, szFmt, arglist);
  562. va_end(arglist);
  563. }
  564. #else
  565. #define DOUTL 1 ? (void)0 : (void)
  566. #endif // DEBUG
  567. // --------------------------------------------------------------------------------
  568. // vDOUT
  569. // --------------------------------------------------------------------------------
  570. #ifdef DEBUG
  571. _inline void vDOUT(LPSTR szFmt, va_list arglist) {
  572. if (DOUT_LEVEL1 & dwDOUTLevel) {
  573. CHAR ach[MAX_PATH];
  574. wvsprintf(ach, szFmt, arglist);
  575. lstrcat(ach, szCRLF);
  576. OutputDebugString(ach);
  577. }
  578. }
  579. #else
  580. #define vDOUT 1 ? (void)0 : (void)
  581. #endif // DEBUG
  582. // --------------------------------------------------------------------------------
  583. // OEAtlTrace - This is just like vDOUT except it doesn't add the crlf at the end.
  584. // It also has a different flag for turning off just the ATL output.
  585. // --------------------------------------------------------------------------------
  586. #ifdef DEBUG
  587. _inline void OEAtlTrace(LPSTR szFmt, va_list arglist) {
  588. if (DOUT_LEVEL1 & dwATLTraceLevel) {
  589. CHAR ach[MAX_PATH];
  590. wvsprintf(ach, szFmt, arglist);
  591. OutputDebugString(ach);
  592. }
  593. }
  594. #else
  595. #define OEAtlTrace 1 ? (void)0 : (void)
  596. #endif // DEBUG
  597. // --------------------------------------------------------------------------------
  598. // OEATLTRACE
  599. // --------------------------------------------------------------------------------
  600. #ifdef DEBUG
  601. __inline void __cdecl OEATLTRACE(LPSTR szFmt, ...) {
  602. va_list arglist;
  603. va_start(arglist, szFmt);
  604. OEAtlTrace(szFmt, arglist);
  605. va_end(arglist);
  606. }
  607. #else
  608. #define OEATLTRACE 1 ? (void)0 : (void)
  609. #endif // DEBUG
  610. // --------------------------------------------------------------------------------
  611. // DOUT
  612. // --------------------------------------------------------------------------------
  613. #ifdef DEBUG
  614. __inline void __cdecl DOUT(LPSTR szFmt, ...) {
  615. va_list arglist;
  616. va_start(arglist, szFmt);
  617. vDOUT(szFmt, arglist);
  618. va_end(arglist);
  619. }
  620. #else
  621. #define DOUT 1 ? (void)0 : (void)
  622. #endif // DEBUG
  623. #define TRACE DOUT
  624. #endif //!def(WIN16) || def(__cplusplus)
  625. // --------------------------------------------------------------------------------
  626. // DOUT Functions implemented in msoert2.dll - debug.c
  627. // --------------------------------------------------------------------------------
  628. #ifdef DEBUG
  629. EXTERN_C __cdecl DebugStrf(LPTSTR lpszFormat, ...);
  630. EXTERN_C HRESULT HrTrace(HRESULT hr, LPSTR lpszFile, INT nLine);
  631. #endif
  632. // --------------------------------------------------------------------------------
  633. // DebugTrace
  634. // --------------------------------------------------------------------------------
  635. #ifdef DEBUG
  636. #ifndef DebugTrace
  637. #define DebugTrace DebugStrf
  638. #endif
  639. #else
  640. #ifndef DebugTrace
  641. #define DebugTrace 1 ? (void)0 : (void)
  642. #endif
  643. #endif // DEBUG
  644. // --------------------------------------------------------------------------------
  645. // TrapError
  646. // --------------------------------------------------------------------------------
  647. #ifdef DEBUG
  648. #define TrapError(_hresult) HrTrace(_hresult, __FILE__, __LINE__)
  649. #else
  650. #define TrapError(_hresult) _hresult
  651. #endif // DEBUG
  652. // --------------------------------------------------------------------------------
  653. // TRAPHR
  654. // --------------------------------------------------------------------------------
  655. #ifdef DEBUG
  656. #define TRAPHR(_hresult) HrTrace(_hresult, __FILE__, __LINE__)
  657. #else
  658. #define TRAPHR(_hresult) _hresult
  659. #endif // DEBUG
  660. // --------------------------------------------------------------------------------
  661. // Assert Functions implemented in msoedbg.lib
  662. // --------------------------------------------------------------------------------
  663. #ifdef DEBUG
  664. EXTERN_C void AssertSzFn(LPSTR, LPSTR, int);
  665. EXTERN_C void NFAssertSzFn(LPSTR, LPSTR, int);
  666. #endif // DEBUG
  667. #endif // __MSOEDBG_H