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.

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