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.

2597 lines
80 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // Debug.h
  7. //
  8. // Description:
  9. // Debugging utilities header.
  10. //
  11. // Maintained By:
  12. // Galen Barbee (GalenB) 22-NOV-1999
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #pragma once
  16. //
  17. // KB: USES_SYSALLOCSTRING gpease 8-NOV-1999
  18. // Turn this on if you are going to use the OLE automation
  19. // functions: SysAllocString, SysFreeString, etc..
  20. //
  21. // #define USES_SYSALLOCSTRING
  22. //
  23. // Trace Flags
  24. //
  25. typedef enum _TRACEFLAGS
  26. {
  27. mtfALWAYS = 0xFFFFFFFF,
  28. mtfNEVER = 0x00000000,
  29. // function entry/exits, call, scoping
  30. mtfASSERT_HR = 0x00000001, // Halt if HRESULT is an error
  31. mtfQUERYINTERFACE = 0x00000002, // Query Interface details and halt on error
  32. // Asserts
  33. mtfSHOWASSERTS = 0x00000004, // Show assert message box
  34. // = 0x00000008,
  35. // other
  36. mtfCALLS = 0x00000010, // Function calls that use the TraceMsgDo macro
  37. mtfFUNC = 0x00000020, // Functions entrances w/parameters
  38. mtfSTACKSCOPE = 0x00000040, // if set, debug spew will generate bar/space for level each of the call stack
  39. mtfPERTHREADTRACE = 0x00000080, // Enables per thread tracing, excludes memory tracking.
  40. // specific
  41. mtfDLL = 0x00000100, // DLL specific
  42. mtfWM = 0x00000200, // Window Messages
  43. mtfFLOW = 0x00000400, // Control flow
  44. // = 0x00000800
  45. // citracker spew
  46. mtfCITRACKERS = 0x00001000, // CITrackers will spew entrances and exits
  47. // = 0x00002000,
  48. // = 0x00004000,
  49. // = 0x00008000,
  50. // = 0x00010000,
  51. // = 0x00020000,
  52. // = 0x00040000,
  53. // = 0x00080000,
  54. // = 0x00100000,
  55. // = 0x00200000,
  56. // = 0x00400000,
  57. // = 0x00800000,
  58. // memory
  59. mtfMEMORYLEAKS = 0x01000000, // Halts when a memory leak is detected on thread exit
  60. mtfMEMORYINIT = 0x02000000, // Initializes new memory allocations to non-zero value
  61. mtfMEMORYALLOCS = 0x04000000, // Turns on spew to display each de/allocation.
  62. // = 0x08000000,
  63. // output prefixes
  64. mtfADDTIMEDATE = 0x10000000, // Replaces Filepath(Line) with Date/Time
  65. mtfBYMODULENAME = 0x20000000, // Puts the module name at the beginning of the line
  66. // = 0x40000000,
  67. mtfOUTPUTTODISK = 0x80000000, // Writes output to disk
  68. } TRACEFLAGS;
  69. typedef DWORD TRACEFLAG;
  70. #define ASZ_NEWLINE "\r\n"
  71. #define SZ_NEWLINE TEXT( ASZ_NEWLINE )
  72. #define SIZEOF_ASZ_NEWLINE ( sizeof( ASZ_NEWLINE ) - sizeof( CHAR ) )
  73. #define SIZEOF_SZ_NEWLINE ( sizeof( SZ_NEWLINE ) - sizeof( TCHAR ) )
  74. #define FREE_ADDRESS 0xFA
  75. #define FREE_BLOCK 0xFB
  76. #define AVAILABLE_ADDRESS 0xAA
  77. #ifdef DEBUG
  78. #pragma message( "BUILD: DEBUG macros being built" )
  79. //
  80. // Globals
  81. //
  82. extern DWORD g_TraceMemoryIndex; // TLS index for the memory tracking link list
  83. extern DWORD g_dwCounter; // Stack depth counter
  84. extern TRACEFLAG g_tfModule; // Global tracing flags
  85. extern const LPCTSTR g_pszModuleIn; // Local module name - use DEFINE_MODULE
  86. extern const TCHAR g_szTrue[]; // Array "TRUE"
  87. extern const TCHAR g_szFalse[]; // Array "FALSE"
  88. //
  89. // Definition Macros
  90. //
  91. #define DEFINE_MODULE( _module ) const LPCTSTR g_pszModuleIn = TEXT(_module);
  92. #define __MODULE__ g_pszModuleIn
  93. #define DEFINE_THISCLASS( _class ) static const TCHAR g_szClass[] = TEXT(_class);
  94. #define __THISCLASS__ g_szClass
  95. //
  96. // ImageHlp Stuff - not ready for prime time yet.
  97. //
  98. #if defined( IMAGEHLP_ENABLED )
  99. #include <imagehlp.h>
  100. typedef BOOL ( * PFNSYMGETSYMFROMADDR )( HANDLE, DWORD, PDWORD, PIMAGEHLP_SYMBOL );
  101. typedef BOOL ( * PFNSYMGETLINEFROMADDR )( HANDLE, DWORD, PDWORD, PIMAGEHLP_LINE );
  102. typedef BOOL ( * PFNSYMGETMODULEINFO )( HANDLE, DWORD, PIMAGEHLP_MODULE );
  103. extern HINSTANCE g_hImageHlp; // IMAGEHLP.DLL instance handle
  104. extern PFNSYMGETSYMFROMADDR g_pfnSymGetSymFromAddr;
  105. extern PFNSYMGETLINEFROMADDR g_pfnSymGetLineFromAddr;
  106. extern PFNSYMGETMODULEINFO g_pfnSymGetModuleInfo;
  107. #endif // IMAGEHLP_ENABLED
  108. void
  109. DebugIncrementStackDepthCounter( void );
  110. void
  111. DebugDecrementStackDepthCounter( void );
  112. //////////////////////////////////////////////////////////////////////////////
  113. //++
  114. //
  115. // MACRO
  116. // TraceInitializeProcess(
  117. // _rgControl
  118. // _sizeofControl
  119. // _fGlobalMemoryTackingIn
  120. // )
  121. //
  122. // Description:
  123. // Should be called in the DLL main on process attach or in the entry
  124. // routine of an EXE. Initializes debugging globals and TLS. Registers
  125. // the WMI tracing facilities (if WMI support is enabled).
  126. //
  127. // Arguments:
  128. // _rgControl WMI control block (see DEBUG_WMI_CONTROL_GUIDS)
  129. // _sizeofControl The sizeof( _rgControl )
  130. //
  131. // Return Values:
  132. // None.
  133. //
  134. //--
  135. //////////////////////////////////////////////////////////////////////////////
  136. #if defined( DEBUG_SW_TRACING_ENABLED )
  137. #define TraceInitializeProcess( _rgControl, _sizeofControl, _fGlobalMemoryTackingIn ) \
  138. do \
  139. { \
  140. DebugInitializeTraceFlags( _fGlobalMemoryTackingIn ); \
  141. WMIInitializeTracing( _rgControl, _sizeofControl ); \
  142. } while ( 0 )
  143. #else // ! DEBUG_SW_TRACING_ENABLED
  144. #define TraceInitializeProcess( _fGlobalMemoryTackingIn ) \
  145. do \
  146. { \
  147. DebugInitializeTraceFlags( _fGlobalMemoryTackingIn ); \
  148. } while ( 0 )
  149. #endif // DEBUG_SW_TRACING_ENABLED
  150. //////////////////////////////////////////////////////////////////////////////
  151. //++
  152. //
  153. // MACRO
  154. // TraceInitializeThread(
  155. // _name
  156. // )
  157. //
  158. // Description:
  159. // Should be called in the DLL thread attach or when a new thread is
  160. // created. Sets up the memory tracing for that thread as well as
  161. // establishing the tfThread for each thread (if mtfPERTHREADTRACE
  162. // is set in g_tfModule).
  163. //
  164. // Arguments:
  165. // _name NULL or the name of the thread.
  166. //
  167. // Return Values:
  168. // None.
  169. //
  170. //--
  171. //////////////////////////////////////////////////////////////////////////////
  172. #define TraceInitializeThread( _name ) \
  173. do \
  174. { \
  175. TlsSetValue( g_TraceMemoryIndex, NULL ); \
  176. DebugInitializeThreadTraceFlags( _name ); \
  177. } while ( 0 )
  178. //////////////////////////////////////////////////////////////////////////////
  179. //++
  180. //
  181. // MACRO
  182. // TraceThreadRundown( void )
  183. //
  184. // Description:
  185. // Should be called before a thread terminates. It will check to make
  186. // sure all memory allocated by the thread was released properly. It
  187. // will also cleanup any per thread structures.
  188. //
  189. // Arguments:
  190. // None.
  191. //
  192. // Return Values:
  193. // None.
  194. //
  195. //--
  196. //////////////////////////////////////////////////////////////////////////////
  197. #define TraceThreadRundown() \
  198. do \
  199. { \
  200. DebugMemoryCheck( NULL, NULL ); \
  201. DebugThreadRundownTraceFlags(); \
  202. } while ( 0 )
  203. //////////////////////////////////////////////////////////////////////////////
  204. //++
  205. //
  206. // MACRO
  207. // TraceCreateMemoryList(
  208. // _pmbIn
  209. // )
  210. //
  211. // Description:
  212. // Creates a thread-independent list to track objects.
  213. //
  214. // _pmbIn should be an LPVOID.
  215. //
  216. // Arguments:
  217. // _pmbIn - Pointer to store the head of the list.
  218. //
  219. // Return Values:
  220. // None.
  221. //
  222. //--
  223. //////////////////////////////////////////////////////////////////////////////
  224. #define TraceCreateMemoryList( _pmbIn ) \
  225. DebugCreateMemoryList( TEXT(__FILE__), __LINE__, __MODULE__, &_pmbIn, TEXT(#_pmbIn) );
  226. //////////////////////////////////////////////////////////////////////////////
  227. //++
  228. //
  229. // MACRO
  230. // TraceTerminateMemoryList(
  231. // _pmbIn
  232. // )
  233. //
  234. // Description:
  235. // Checks to make sure the list is empty before destroying the list.
  236. //
  237. // _pmbIn should be an LPVOID.
  238. //
  239. // Arguments:
  240. // _pmbIn - Pointer to store the head of the list.
  241. //
  242. // Return Values:
  243. // None.
  244. //
  245. //--
  246. //////////////////////////////////////////////////////////////////////////////
  247. // BUGBUG: DavidP 09-DEC-1999
  248. // _pmbIn is evaluated multiple times but the name of the
  249. // macro is mixed case.
  250. #define TraceTerminateMemoryList( _pmbIn ) \
  251. do \
  252. { \
  253. DebugMemoryCheck( _pmbIn, TEXT(#_pmbIn) ); \
  254. HeapFree( GetProcessHeap(), 0, _pmbIn ); \
  255. } while ( 0 )
  256. //////////////////////////////////////////////////////////////////////////////
  257. //++
  258. //
  259. // MACRO
  260. // TraceMoveToMemoryList(
  261. // _addr
  262. // _pmbIn
  263. // )
  264. //
  265. // Description:
  266. // Moves an object from the thread tracking list to a thread independent
  267. // memory list (_pmbIn).
  268. //
  269. // _pmbIn should be castable to an LPVOID.
  270. //
  271. // Arguments:
  272. // _addr - Address of object to move.
  273. // _pmbIn - Pointer to store the head of the list.
  274. //
  275. // Return Values:
  276. // None.
  277. //
  278. //--
  279. //////////////////////////////////////////////////////////////////////////////
  280. //#define TraceMoveToMemoryList( _addr, _pmbIn ) \
  281. // DebugMoveToMemoryList( TEXT(__FILE__), __LINE__, __MODULE__, _addr, _pmbIn, TEXT(#_pmbIn) );
  282. #define TraceMoveToMemoryList( _addr, _pmbIn )
  283. //////////////////////////////////////////////////////////////////////////////
  284. //++
  285. //
  286. // MACRO
  287. // TraceMoveFromMemoryList(
  288. // _addr
  289. // _pmbIn
  290. // )
  291. //
  292. // Description:
  293. // Moves an object from a thread independent memory list (_pmbIn) to the
  294. // per thread tracking list.
  295. //
  296. // _pmbIn should be castable to an LPVOID.
  297. //
  298. // Arguments:
  299. // _addr - Address of object to move.
  300. // _pmbIn - Pointer to store the head of the list.
  301. //
  302. // Return Values:
  303. // None.
  304. //
  305. //--
  306. //////////////////////////////////////////////////////////////////////////////
  307. //#define TraceMoveFromMemoryList( _addr, _pmbIn ) \
  308. // DebugMoveFromMemoryList( TEXT(__FILE__), __LINE__, __MODULE__, _addr, _pmbIn, TEXT(#_pmbIn) );
  309. #define TraceMoveFromMemoryList( _addr, _pmbIn )
  310. //////////////////////////////////////////////////////////////////////////////
  311. //++
  312. //
  313. // MACRO
  314. // TraceMemoryListDelete(
  315. // _addr
  316. // _pmbIn
  317. // )
  318. //
  319. // Description:
  320. // Moves and object from the thread tracking list to a thread independent
  321. // memory list (_pmbIn).
  322. //
  323. // _pmbIn should be an LPVOID.
  324. //
  325. // Arguments:
  326. // _addr - Address of object to delete.
  327. // _pmbIn - Pointer to store the head of the list.
  328. //
  329. // Return Values:
  330. // None.
  331. //
  332. //--
  333. //////////////////////////////////////////////////////////////////////////////
  334. //#define TraceMemoryListDelete( _addr, _pmbIn, _fClobberIn ) \
  335. // DebugMemoryListDelete( TEXT(__FILE__), __LINE__, __MODULE__, _addr, _pmbIn, TEXT(#_pmbIn), _fClobberIn );
  336. //////////////////////////////////////////////////////////////////////////////
  337. //++
  338. //
  339. // MACRO
  340. // TraceTerminateProcess
  341. //
  342. // Description:
  343. // Should be called before a process terminates. It cleans up anything
  344. // that the Debug APIs created. It will check to make sure all memory
  345. // allocated by the main thread was released properly. It will also
  346. // terminate WMI tracing (if WMI support is enabled). It also closes
  347. // the logging handle.
  348. //
  349. // Arguments:
  350. // _rgControl - WMI control block (see DEBUG_WMI_CONTROL_GUIDS)
  351. // _sizeofControl - the sizeof( _rgControl )
  352. //
  353. // Return Values:
  354. // None.
  355. //
  356. //--
  357. //////////////////////////////////////////////////////////////////////////////
  358. #if defined( DEBUG_SW_TRACING_ENABLED )
  359. #define TraceTerminateProcess( _rgControl, _sizeofControl ) \
  360. do \
  361. { \
  362. LogTerminateProcess(); \
  363. WMITerminateTracing( _rgControl, _sizeofControl ); \
  364. DebugMemoryCheck( NULL, NULL ); \
  365. DebugTerminateProcess(); \
  366. } while ( 0 )
  367. #else // ! DEBUG_SW_TRACING_ENABLED
  368. //
  369. // TODO: 11 DEC 2000 GalenB
  370. //
  371. // LogTerminateProcess() needs to be available for retail builds.
  372. // Since it doesn't yet do anything this isn't a problem, but that
  373. // of course can change...
  374. //
  375. #define TraceTerminateProcess() \
  376. do \
  377. { \
  378. LogTerminateProcess(); \
  379. DebugMemoryCheck( NULL, NULL ); \
  380. DebugTerminateProcess(); \
  381. } while ( 0 )
  382. #endif // DEBUG_SW_TRACING_ENABLED
  383. //****************************************************************************
  384. //
  385. // Debug initialization routines
  386. //
  387. // Uses should use the TraceInitializeXXX and TraceTerminateXXX macros, not
  388. // these routines.
  389. //
  390. //****************************************************************************
  391. void
  392. DebugInitializeTraceFlags( BOOL fGlobalMemoryTackingIn = TRUE );
  393. void
  394. DebugInitializeThreadTraceFlags(
  395. LPCTSTR pszThreadNameIn
  396. );
  397. void
  398. DebugTerminateProcess( void );
  399. void
  400. DebugThreadRundownTraceFlags( void );
  401. void
  402. DebugCreateMemoryList(
  403. LPCTSTR pszFileIn,
  404. const int nLineIn,
  405. LPCTSTR pszModuleIn,
  406. LPVOID * ppvListOut,
  407. LPCTSTR pszListNameIn
  408. );
  409. void
  410. DebugMemoryListDelete(
  411. LPCTSTR pszFileIn,
  412. const int nLineIn,
  413. LPCTSTR pszModuleIn,
  414. void * pvMemIn,
  415. LPVOID pvListIn,
  416. LPCTSTR pszListNameIn,
  417. BOOL fClobberIn
  418. );
  419. void
  420. DebugMoveToMemoryList(
  421. LPCTSTR pszFileIn,
  422. const int nLineIn,
  423. LPCTSTR pszModuleIn,
  424. void * pvMemIn,
  425. LPVOID pmbListIn,
  426. LPCTSTR pszListNameIn
  427. );
  428. void
  429. DebugMoveFromMemoryList(
  430. LPCTSTR pszFileIn,
  431. const int nLineIn,
  432. LPCTSTR pszModuleIn,
  433. HGLOBAL hGlobal,
  434. LPVOID pmbListIn,
  435. LPCTSTR pszListNameIn
  436. );
  437. //****************************************************************************
  438. //
  439. // Memmory Allocation Subsitution Macros
  440. //
  441. // Replaces LocalAlloc/LocalFree, GlobalAlloc/GlobalFree, and malloc/free
  442. //
  443. //****************************************************************************
  444. #define TraceAlloc( _flags, _size ) DebugAlloc( TEXT(__FILE__), __LINE__, __MODULE__, _flags, _size, TEXT(#_size) )
  445. #define TraceReAlloc( _pvmem, _size, _flags ) DebugReAlloc( TEXT(__FILE__), __LINE__, __MODULE__, _pvmem, _flags, _size, TEXT(#_size) )
  446. #define TraceFree( _hmem ) DebugFree( _hmem, TEXT(__FILE__), __LINE__, __MODULE__ )
  447. //////////////////////////////////////////////////////////////////////////////
  448. //++
  449. //
  450. // MACRO
  451. // TraceAllocString(
  452. // _flags,
  453. // _size
  454. // )
  455. //
  456. // Description:
  457. // Quick way to allocation a string that is the proper size and that will
  458. // be tracked by memory tracking.
  459. //
  460. // Arguments:
  461. // _flags - Allocation attributes.
  462. // _size - Number of characters in the string to be allocated.
  463. //
  464. // Return Values:
  465. // Handle/pointer to memory to be used as a string.
  466. //
  467. //////////////////////////////////////////////////////////////////////////////
  468. #define TraceAllocString( _flags, _size ) \
  469. (LPTSTR) DebugAlloc( TEXT(__FILE__), \
  470. __LINE__, \
  471. __MODULE__, \
  472. _flags, \
  473. (_size) * sizeof( TCHAR ), \
  474. TEXT(#_size) \
  475. )
  476. //****************************************************************************
  477. //
  478. // Code Tracing Macros
  479. //
  480. //****************************************************************************
  481. //////////////////////////////////////////////////////////////////////////////
  482. //++
  483. //
  484. // MACRO
  485. // TraceFunc(
  486. // _szArgs
  487. // )
  488. //
  489. // Description:
  490. // Displays file, line number, module and "_szArgs" only if the mtfFUNC is
  491. // set in g_tfModule. "_szArgs" is the name of the function just
  492. // entered. It also increments the stack counter.
  493. //
  494. // Arguments:
  495. // _szArgs - Arguments for the function just entered.
  496. //
  497. // Return Values:
  498. // None.
  499. //
  500. //--
  501. //////////////////////////////////////////////////////////////////////////////
  502. #define TraceFunc( _szArgs ) \
  503. HRESULT __MissingTraceFunc; \
  504. if ( g_tfModule != 0 ) \
  505. { \
  506. DebugIncrementStackDepthCounter(); \
  507. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ ") TEXT(__FUNCTION__) TEXT("( ") TEXT(_szArgs) TEXT(" )") ); \
  508. }
  509. //
  510. // These next macros are just like TraceFunc except they take additional
  511. // arguments to display the values passed into the function call. "_szArgs"
  512. // should contain a printf string on how to display the arguments.
  513. //
  514. #define TraceFunc1( _szArgs, _arg1 ) \
  515. HRESULT __MissingTraceFunc; \
  516. if ( g_tfModule != 0 ) \
  517. { \
  518. DebugIncrementStackDepthCounter(); \
  519. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ ") TEXT(__FUNCTION__) TEXT("( ") TEXT(_szArgs) TEXT(" )"), _arg1 ); \
  520. }
  521. #define TraceFunc2( _szArgs, _arg1, _arg2 ) \
  522. HRESULT __MissingTraceFunc; \
  523. if ( g_tfModule != 0 ) \
  524. { \
  525. DebugIncrementStackDepthCounter(); \
  526. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ ") TEXT(__FUNCTION__) TEXT("( ") TEXT(_szArgs) TEXT(" )"), _arg1, _arg2 ); \
  527. }
  528. #define TraceFunc3( _szArgs, _arg1, _arg2, _arg3 ) \
  529. HRESULT __MissingTraceFunc; \
  530. if ( g_tfModule != 0 ) \
  531. { \
  532. DebugIncrementStackDepthCounter(); \
  533. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ ") TEXT(__FUNCTION__) TEXT("( ") TEXT(_szArgs) TEXT(" )"), _arg1, _arg2, _arg3 ); \
  534. }
  535. #define TraceFunc4( _szArgs, _arg1, _arg2, _arg3, _arg4 ) \
  536. HRESULT __MissingTraceFunc; \
  537. if ( g_tfModule != 0 ) \
  538. { \
  539. DebugIncrementStackDepthCounter(); \
  540. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ ") TEXT(__FUNCTION__) TEXT("( ") TEXT(_szArgs) TEXT(" )"), _arg1, _arg2, _arg3, _arg4 ); \
  541. }
  542. #define TraceFunc5( _szArgs, _arg1, _arg2, _arg3, _arg4, _arg5 ) \
  543. HRESULT __MissingTraceFunc; \
  544. if ( g_tfModule != 0 ) \
  545. { \
  546. DebugIncrementStackDepthCounter(); \
  547. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ ") TEXT(__FUNCTION__) TEXT("( ") TEXT(_szArgs) TEXT(" )"), _arg1, _arg2, _arg3, _arg4, arg5 ); \
  548. }
  549. #define TraceFunc6( _szArgs, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6 ) \
  550. HRESULT __MissingTraceFunc; \
  551. if ( g_tfModule != 0 ) \
  552. { \
  553. DebugIncrementStackDepthCounter(); \
  554. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ ") TEXT(__FUNCTION__) TEXT("( ") TEXT(_szArgs) TEXT(" )"), _arg1, _arg2, _arg3, _arg4, arg5, arg6 ); \
  555. }
  556. //////////////////////////////////////////////////////////////////////////////
  557. //++
  558. //
  559. // MACRO
  560. // TraceQIFunc(
  561. // _szArgs,
  562. // riid,
  563. // ppv
  564. // )
  565. //
  566. // Description:
  567. // Just like TraceFunc but customized for QueryInterface. Specifically,
  568. // displays the name of the interface and the value of the return pointer.
  569. //
  570. // Arguments:
  571. // _riid - Interface ID.
  572. // _ppv - Return pointer.
  573. //
  574. // Return Values:
  575. // None.
  576. //
  577. //--
  578. //////////////////////////////////////////////////////////////////////////////
  579. #define TraceQIFunc( _riid, _ppv ) \
  580. HRESULT __MissingTraceFunc; \
  581. if ( g_tfModule != 0 ) \
  582. { \
  583. TCHAR szGuid[ cchGUID_STRING_SIZE ]; \
  584. DebugIncrementStackDepthCounter(); \
  585. TraceMessage( TEXT(__FILE__), \
  586. __LINE__, \
  587. __MODULE__, \
  588. mtfFUNC, \
  589. TEXT("+ ") TEXT(__FUNCTION__) TEXT("( [IUnknown] %s, ppv = %#x )"), \
  590. PszTraceFindInterface( _riid, szGuid ), \
  591. _ppv \
  592. ); \
  593. }
  594. //////////////////////////////////////////////////////////////////////////////
  595. //++
  596. //
  597. // MACRO
  598. // TraceFlow(
  599. // _pszFormat
  600. // )
  601. //
  602. // Description:
  603. // This macro outputs a string that is indented to the current depth.
  604. //
  605. //--
  606. //////////////////////////////////////////////////////////////////////////////
  607. #define TraceFlow( _pszFormat ) \
  608. do \
  609. { \
  610. if ( g_tfModule != 0 ) \
  611. { \
  612. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFLOW, TEXT("| ") TEXT(_pszFormat) ); \
  613. } \
  614. } while ( 0 )
  615. //
  616. // These next macros are just like TraceFunc except they take additional
  617. // arguments to display the values passed into the function call. "_pszFormat"
  618. // should contain a printf string on how to display the arguments.
  619. //
  620. #define TraceFlow1( _pszFormat, _arg1 ) \
  621. do \
  622. { \
  623. if ( g_tfModule != 0 ) \
  624. { \
  625. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFLOW, TEXT("| ") TEXT(_pszFormat), _arg1 ); \
  626. } \
  627. } while ( 0 )
  628. #define TraceFlow2( _pszFormat, _arg1, _arg2 ) \
  629. do \
  630. { \
  631. if ( g_tfModule != 0 ) \
  632. { \
  633. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFLOW, TEXT("| ") TEXT(_pszFormat), _arg1, _arg2 ); \
  634. } \
  635. } while ( 0 )
  636. #define TraceFlow3( _pszFormat, _arg1, _arg2, _arg3 ) \
  637. do \
  638. { \
  639. if ( g_tfModule != 0 ) \
  640. { \
  641. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFLOW, TEXT("| ") TEXT(_pszFormat), _arg1, _arg2, _arg3 ); \
  642. } \
  643. } while ( 0 )
  644. #define TraceFlow4( _pszFormat, _arg1, _arg2, _arg3, _arg4 ) \
  645. do \
  646. { \
  647. if ( g_tfModule != 0 ) \
  648. { \
  649. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFLOW, TEXT("| ") TEXT(_pszFormat), _arg1, _arg2, _arg3, _arg4 ); \
  650. } \
  651. } while ( 0 )
  652. #define TraceFlow5( _pszFormat, _arg1, _arg2, _arg3, _arg4, _arg5 ) \
  653. do \
  654. { \
  655. if ( g_tfModule != 0 ) \
  656. { \
  657. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFLOW, TEXT("| ") TEXT(_pszFormat), _arg1, _arg2, _arg3, _arg4, _arg5 ); \
  658. } \
  659. } while ( 0 )
  660. #define TraceFlow6( _pszFormat, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6 ) \
  661. do \
  662. { \
  663. if ( g_tfModule != 0 ) \
  664. { \
  665. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFLOW, TEXT("| ") TEXT(_pszFormat), _arg1, _arg2, _arg3, _arg4, _arg5, _arg6 ); \
  666. } \
  667. } while ( 0 )
  668. //////////////////////////////////////////////////////////////////////////////
  669. //++
  670. //
  671. // MACRO
  672. // TraceFuncExit( void )
  673. //
  674. // Description:
  675. // Return macro for TraceFunc() if the return type is void. It also
  676. // decrements the stack counter.
  677. //
  678. // Arguments:
  679. // None.
  680. //
  681. // Return Values:
  682. // None.
  683. //
  684. //--
  685. //////////////////////////////////////////////////////////////////////////////
  686. #define TraceFuncExit() \
  687. do \
  688. { \
  689. if ( g_tfModule != 0 ) \
  690. { \
  691. __MissingTraceFunc = 0; \
  692. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("V") ); \
  693. DebugDecrementStackDepthCounter(); \
  694. } \
  695. return; \
  696. } while ( 0 )
  697. //////////////////////////////////////////////////////////////////////////////
  698. //++
  699. //
  700. // MACRO
  701. // RETURN(
  702. // _rval
  703. // )
  704. //
  705. // Description:
  706. // Return macro for TraceFunc(). The _rval will be returned as the
  707. // result of the function. It also decrements the stack counter.
  708. //
  709. // Arguments:
  710. // _rval - Result of the function.
  711. //
  712. // Return Values:
  713. // None.
  714. //
  715. //--
  716. //////////////////////////////////////////////////////////////////////////////
  717. #define RETURN( _rval ) \
  718. do \
  719. { \
  720. if ( g_tfModule != 0 ) \
  721. { \
  722. __MissingTraceFunc = 0; \
  723. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("V") ); \
  724. DebugDecrementStackDepthCounter(); \
  725. } \
  726. return _rval; \
  727. } while ( 0 )
  728. /*
  729. return ( ( g_tfModule != 0 ) \
  730. ? ( TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("V") ) \
  731. , DebugDecrementStackDepthCounter() \
  732. , _rval ) \
  733. : _rval )
  734. */
  735. //////////////////////////////////////////////////////////////////////////////
  736. //++
  737. //
  738. // MACRO
  739. // FRETURN(
  740. // _rval
  741. // )
  742. //
  743. // Description:
  744. // This is a fake version of the return macro for TraceFunc().
  745. // *** This doesn't return. *** It also decrements the stack counter.
  746. //
  747. // Arguments:
  748. // _rval - Result of the function.
  749. //
  750. // Return Values:
  751. // None.
  752. //
  753. //--
  754. //////////////////////////////////////////////////////////////////////////////
  755. #define FRETURN( _rval ) \
  756. do \
  757. { \
  758. if ( g_tfModule != 0 ) \
  759. { \
  760. __MissingTraceFunc = 0; \
  761. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("V") ); \
  762. DebugDecrementStackDepthCounter(); \
  763. } \
  764. } while ( 0 )
  765. //////////////////////////////////////////////////////////////////////////////
  766. //++
  767. //
  768. // MACRO
  769. // HRETURN(
  770. // _hr
  771. // )
  772. //
  773. // Description:
  774. // Return macro for TraceFunc(). The _hr will be returned as the result
  775. // of the function. If the value is not S_OK, it will be displayed in
  776. // the debugger. It also decrements the stack counter.
  777. //
  778. // Arguments:
  779. // _hr - Result of the function.
  780. //
  781. // Return Values:
  782. // None.
  783. //
  784. //--
  785. //////////////////////////////////////////////////////////////////////////////
  786. #define HRETURN( _hr ) \
  787. do \
  788. { \
  789. if ( g_tfModule != 0 ) \
  790. { \
  791. __MissingTraceFunc = 0; \
  792. if ( _hr != S_OK ) \
  793. { \
  794. DebugReturnMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT( "V hr = 0x%08x (%s)"), _hr ); \
  795. } \
  796. else \
  797. { \
  798. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("V") ); \
  799. } \
  800. DebugDecrementStackDepthCounter(); \
  801. } \
  802. return _hr; \
  803. } while ( 0 )
  804. //
  805. // These next macros are just like HRETURN except they allow other
  806. // exceptable values to be passed.back without causing extra spew.
  807. //
  808. #define HRETURN1( _hr, _arg1 ) \
  809. do \
  810. { \
  811. if ( g_tfModule != 0 ) \
  812. { \
  813. __MissingTraceFunc = 0; \
  814. if ( ( _hr != S_OK ) && ( _hr != _arg1 ) ) \
  815. { \
  816. DebugReturnMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT( "V hr = 0x%08x (%s)"), _hr ); \
  817. } \
  818. else \
  819. { \
  820. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("V") ); \
  821. } \
  822. DebugDecrementStackDepthCounter(); \
  823. } \
  824. return _hr; \
  825. } while ( 0 )
  826. #define HRETURN2( _hr, _arg1, _arg2 ) \
  827. do \
  828. { \
  829. if ( g_tfModule != 0 ) \
  830. { \
  831. __MissingTraceFunc = 0; \
  832. if ( ( _hr != S_OK ) && ( _hr != _arg1 ) && ( _hr != _arg2 ) ) \
  833. { \
  834. DebugReturnMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT( "V hr = 0x%08x (%s)"), _hr ); \
  835. } \
  836. else \
  837. { \
  838. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("V") ); \
  839. } \
  840. DebugDecrementStackDepthCounter(); \
  841. } \
  842. return _hr; \
  843. } while ( 0 )
  844. #define HRETURN3( _hr, _arg1, _arg2, _arg3 ) \
  845. do \
  846. { \
  847. if ( g_tfModule != 0 ) \
  848. { \
  849. __MissingTraceFunc = 0; \
  850. if ( ( _hr != S_OK ) && ( _hr != _arg1 ) && ( _hr != _arg2 ) && ( _hr != _arg3 ) ) \
  851. { \
  852. DebugReturnMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT( "V hr = 0x%08x (%s)"), _hr ); \
  853. } \
  854. else \
  855. { \
  856. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("V") ); \
  857. } \
  858. DebugDecrementStackDepthCounter(); \
  859. } \
  860. return _hr; \
  861. } while ( 0 )
  862. //////////////////////////////////////////////////////////////////////////////
  863. //++
  864. //
  865. // MACRO
  866. // TraceDo(
  867. // _szExp
  868. // )
  869. //
  870. // Description:
  871. // Displays the file, line number, module and function call and return
  872. // from the function call (no return value displayed) for "_szExp" only
  873. // if the mtfCALLS is set in g_tfModule. Note return value is not
  874. // displayed. _szExp will be in RETAIL version of the product.
  875. //
  876. // Arguments:
  877. // _szExp
  878. // The expression to be traced including assigment to the return
  879. // variable.
  880. //
  881. // Return Values:
  882. // None. The return value should be defined within _szExp.
  883. //
  884. //--
  885. //////////////////////////////////////////////////////////////////////////////
  886. #define TraceDo( _szExp ) \
  887. do \
  888. { \
  889. if ( g_tfModule != 0 ) \
  890. { \
  891. DebugIncrementStackDepthCounter(); \
  892. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("+ ") TEXT(#_szExp ) ); \
  893. _szExp; \
  894. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("V") ); \
  895. DebugDecrementStackDepthCounter(); \
  896. } \
  897. else \
  898. { \
  899. _szExp; \
  900. } \
  901. } while ( 0 )
  902. //////////////////////////////////////////////////////////////////////////////
  903. //++
  904. //
  905. // MACRO
  906. // TraceMsgDo(
  907. // _pszExp,
  908. // _pszReturnMsg
  909. // )
  910. //
  911. // Description:
  912. // Displays the file, line number, module and function call and return
  913. // value which is formatted in "_pszReturnMsg" for "_pszExp" only if the
  914. // mtfCALLS is set in g_tfModule. _pszExp will be in the RETAIL version
  915. // of the product.
  916. //
  917. // Arguments:
  918. // _pszExp
  919. // The expression to be traced including assigment to the return
  920. // variable.
  921. // _pszReturnMsg
  922. // A format string for displaying the return value.
  923. //
  924. // Return Values:
  925. // None. The return value should be defined within _szExp.
  926. //
  927. // Example:
  928. // TraceMsgDo( hr = HrDoSomething(), "0x%08.8x" );
  929. //
  930. //--
  931. //////////////////////////////////////////////////////////////////////////////
  932. #define TraceMsgDo( _pszExp, _pszReturnMsg ) \
  933. do \
  934. { \
  935. if ( g_tfModule != 0 ) \
  936. { \
  937. DebugIncrementStackDepthCounter(); \
  938. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("+ ") TEXT(#_pszExp) ); \
  939. TraceMessageDo( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT(_pszReturnMsg), TEXT(#_pszExp), _pszExp ); \
  940. DebugDecrementStackDepthCounter(); \
  941. } \
  942. else \
  943. { \
  944. _pszExp; \
  945. } \
  946. } while ( 0 )
  947. //
  948. // These next macros are just like TraceMsgDo except they take additional
  949. // arguments to display the values passed into the function call. "_pszReturnMsg"
  950. // should contain a printf format string describing how to display the
  951. // arguments.
  952. //
  953. #define TraceMsgDo1( _pszExp, _pszReturnMsg, _arg1 ) \
  954. do \
  955. { \
  956. if ( g_tfModule != 0 ) \
  957. { \
  958. DebugIncrementStackDepthCounter(); \
  959. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("+ ") TEXT(#_pszExp) ); \
  960. TraceMessageDo( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT(_pszReturnMsg), TEXT(#_pszExp), _pszExp, _arg1 ); \
  961. DebugDecrementStackDepthCounter(); \
  962. } \
  963. else \
  964. { \
  965. _pszExp; \
  966. } \
  967. } while ( 0 )
  968. #define TraceMsgDo2( _pszExp, _pszReturnMsg, _arg1, _arg2 ) \
  969. do \
  970. { \
  971. if ( g_tfModule != 0 ) \
  972. { \
  973. DebugIncrementStackDepthCounter(); \
  974. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("+ ") TEXT(#_pszExp) ); \
  975. TraceMessageDo( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT(_pszReturnMsg), TEXT(#_pszExp), _pszExp, _arg1, _arg2 ); \
  976. DebugDecrementStackDepthCounter(); \
  977. } \
  978. else \
  979. { \
  980. _pszExp; \
  981. } \
  982. } while ( 0 )
  983. #define TraceMsgDo3( _pszExp, _pszReturnMsg, _arg1, _arg2, _arg3 ) \
  984. do \
  985. { \
  986. if ( g_tfModule != 0 ) \
  987. { \
  988. DebugIncrementStackDepthCounter(); \
  989. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("+ ") TEXT(#_pszExp) ); \
  990. TraceMessageDo( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT(_pszReturnMsg), TEXT(#_pszExp), _pszExp, _arg1, _arg2, _arg3 ); \
  991. DebugDecrementStackDepthCounter(); \
  992. } \
  993. else \
  994. { \
  995. _pszExp; \
  996. } \
  997. } while ( 0 )
  998. #define TraceMsgDo4( _pszExp, _pszReturnMsg, _arg1, _arg2, _arg3, _arg4 ) \
  999. do \
  1000. { \
  1001. if ( g_tfModule != 0 ) \
  1002. { \
  1003. DebugIncrementStackDepthCounter(); \
  1004. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("+ ") TEXT(#_pszExp) ); \
  1005. TraceMessageDo( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT(_pszReturnMsg), TEXT(#_pszExp), _pszExp, _arg1, _arg2, _arg3, _arg4 ); \
  1006. DebugDecrementStackDepthCounter(); \
  1007. } \
  1008. else \
  1009. { \
  1010. _pszExp; \
  1011. } \
  1012. } while ( 0 )
  1013. #define TraceMsgDo5( _pszExp, _pszReturnMsg, _arg1, _arg2, _arg3, _arg4, _arg5 ) \
  1014. do \
  1015. { \
  1016. if ( g_tfModule != 0 ) \
  1017. { \
  1018. DebugIncrementStackDepthCounter(); \
  1019. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("+ ") TEXT(#_pszExp) ); \
  1020. TraceMessageDo( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT(_pszReturnMsg), TEXT(#_pszExp), _pszExp, _arg1, _arg2, _arg3, _arg4, _arg5 ); \
  1021. DebugDecrementStackDepthCounter(); \
  1022. } \
  1023. else \
  1024. { \
  1025. _pszExp; \
  1026. } \
  1027. } while ( 0 )
  1028. #define TraceMsgDo6( _pszExp, _pszReturnMsg, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6 ) \
  1029. do \
  1030. { \
  1031. if ( g_tfModule != 0 ) \
  1032. { \
  1033. DebugIncrementStackDepthCounter(); \
  1034. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("+ ") TEXT(#_pszExp) ); \
  1035. TraceMessageDo( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT(_pszReturnMsg), TEXT(#_pszExp), _pszExp, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6 ); \
  1036. DebugDecrementStackDepthCounter(); \
  1037. } \
  1038. else \
  1039. { \
  1040. _pszExp; \
  1041. } \
  1042. } while ( 0 )
  1043. //////////////////////////////////////////////////////////////////////////////
  1044. //++
  1045. //
  1046. // MACRO
  1047. // TraceMsgPreDo(
  1048. // _pszExp,
  1049. // _pszPreMsg
  1050. // _pszReturnMsg,
  1051. // )
  1052. //
  1053. // Description:
  1054. // Displays the file, line number, module and function call and return
  1055. // value which is formatted in "_pszReturnMsg" for "_pszExp" only if the
  1056. // mtfCALLS is set in g_tfModule. _pszExp will be in the RETAIL version
  1057. // of the product.
  1058. //
  1059. // Same as TraceMsgDo except it displays the formatted message before
  1060. // executing the expression. Arguments for TraceMsgPreDo1, etc. are
  1061. // applied to both _pszPreMsg and _pszReturnMsg. The first substitution
  1062. // string in _pszReturnMsg is for the return value from the function.
  1063. //
  1064. // Arguments:
  1065. // _pszExp
  1066. // The expression to be traced including assigment to the return
  1067. // variable.
  1068. // _pszPreMsg
  1069. // A format string for displaying a message before the expression
  1070. // is evaluated.
  1071. // _pszReturnMsg
  1072. // A format string for displaying the return value.
  1073. //
  1074. // Return Values:
  1075. // None. The return value should be defined within _szExp.
  1076. //
  1077. // Example:
  1078. // TraceMsgPreDo1( hr = HrDoSomething( bstrName ),
  1079. // "Name = '%ls'",
  1080. // "0x%08.8x, Name = '%ls'",
  1081. // bstrName
  1082. // );
  1083. //
  1084. //--
  1085. //////////////////////////////////////////////////////////////////////////////
  1086. #define TraceMsgPreDo( _pszExp, _pszPreMsg, _pszReturnMsg ) \
  1087. do \
  1088. { \
  1089. if ( g_tfModule != 0 ) \
  1090. { \
  1091. DebugIncrementStackDepthCounter(); \
  1092. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("+ ") TEXT(#_pszExp) ); \
  1093. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("| ") TEXT(_pszPreMsg) ); \
  1094. TraceMessageDo( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT(_pszReturnMsg), TEXT(#_pszExp), _pszExp ); \
  1095. DebugDecrementStackDepthCounter(); \
  1096. } \
  1097. else \
  1098. { \
  1099. _pszExp; \
  1100. } \
  1101. } while ( 0 )
  1102. //
  1103. // These next macros are just like TraceMsgPreDo except they take additional
  1104. // arguments to display the values passed into the function call. "_pszPreMsg"
  1105. // should contain a printf format string describing how to display the
  1106. // arguments.
  1107. //
  1108. #define TraceMsgPreDo1( _pszExp, _pszPreMsg, _pszReturnMsg, _arg1 ) \
  1109. do \
  1110. { \
  1111. if ( g_tfModule != 0 ) \
  1112. { \
  1113. DebugIncrementStackDepthCounter(); \
  1114. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("+ ") TEXT(#_pszExp) ); \
  1115. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("| ") TEXT(_pszPreMsg), _arg1 ); \
  1116. TraceMessageDo( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT(_pszReturnMsg), TEXT(#_pszExp), _pszExp, _arg1 ); \
  1117. DebugDecrementStackDepthCounter(); \
  1118. } \
  1119. else \
  1120. { \
  1121. _pszExp; \
  1122. } \
  1123. } while ( 0 )
  1124. #define TraceMsgPreDo2( _pszExp, _pszPreMsg, _pszReturnMsg, _arg1, _arg2 ) \
  1125. do \
  1126. { \
  1127. if ( g_tfModule != 0 ) \
  1128. { \
  1129. DebugIncrementStackDepthCounter(); \
  1130. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("+ ") TEXT(#_pszExp) ); \
  1131. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("| ") TEXT(_pszPreMsg), _arg1, _arg2 ); \
  1132. TraceMessageDo( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT(_pszReturnMsg), TEXT(#_pszExp), _pszExp, _arg1, _arg2 ); \
  1133. DebugDecrementStackDepthCounter(); \
  1134. } \
  1135. else \
  1136. { \
  1137. _pszExp; \
  1138. } \
  1139. } while ( 0 )
  1140. #define TraceMsgPreDo3( _pszExp, _pszPreMsg, _pszReturnMsg, _arg1, _arg2, _arg3 ) \
  1141. do \
  1142. { \
  1143. if ( g_tfModule != 0 ) \
  1144. { \
  1145. DebugIncrementStackDepthCounter(); \
  1146. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("+ ") TEXT(#_pszExp) ); \
  1147. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("| ") TEXT(_pszPreMsg), _arg1, _arg2, _arg3 ); \
  1148. TraceMessageDo( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT(_pszReturnMsg), TEXT(#_pszExp), _pszExp, _arg1, _arg2, _arg3 ); \
  1149. DebugDecrementStackDepthCounter(); \
  1150. } \
  1151. else \
  1152. { \
  1153. _pszExp; \
  1154. } \
  1155. } while ( 0 )
  1156. #define TraceMsgPreDo4( _pszExp, _pszPreMsg, _pszReturnMsg, _arg1, _arg2, _arg3, _arg4 ) \
  1157. do \
  1158. { \
  1159. if ( g_tfModule != 0 ) \
  1160. { \
  1161. DebugIncrementStackDepthCounter(); \
  1162. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("+ ") TEXT(#_pszExp) ); \
  1163. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("| ") TEXT(_pszPreMsg), _arg1, _arg2, _arg3, _arg4 ); \
  1164. TraceMessageDo( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT(_pszReturnMsg), TEXT(#_pszExp), _pszExp, _arg1, _arg2, _arg3, _arg4 ); \
  1165. DebugDecrementStackDepthCounter(); \
  1166. } \
  1167. else \
  1168. { \
  1169. _pszExp; \
  1170. } \
  1171. } while ( 0 )
  1172. #define TraceMsgPreDo5( _pszExp, _pszPreMsg, _pszReturnMsg, _arg1, _arg2, _arg3, _arg4, _arg5 ) \
  1173. do \
  1174. { \
  1175. if ( g_tfModule != 0 ) \
  1176. { \
  1177. DebugIncrementStackDepthCounter(); \
  1178. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("+ ") TEXT(#_pszExp) ); \
  1179. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("| ") TEXT(_pszPreMsg), _arg1, _arg2, _arg3, _arg4, _arg5 ); \
  1180. TraceMessageDo( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT(_pszReturnMsg), TEXT(#_pszExp), _pszExp, _arg1, _arg2, _arg3, _arg4, _arg5 ); \
  1181. DebugDecrementStackDepthCounter(); \
  1182. } \
  1183. else \
  1184. { \
  1185. _pszExp; \
  1186. } \
  1187. } while ( 0 )
  1188. #define TraceMsgPreDo6( _pszExp, _pszPreMsg, _pszReturnMsg, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6 ) \
  1189. do \
  1190. { \
  1191. if ( g_tfModule != 0 ) \
  1192. { \
  1193. DebugIncrementStackDepthCounter(); \
  1194. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("+ ") TEXT(#_pszExp) ); \
  1195. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT("| ") TEXT(_pszPreMsg), _arg1, _arg2, _arg3, _arg4, _arg5, _arg6 ); \
  1196. TraceMessageDo( TEXT(__FILE__), __LINE__, __MODULE__, mtfCALLS, TEXT(_pszReturnMsg), TEXT(#_pszExp), _pszExp, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6 ); \
  1197. DebugDecrementStackDepthCounter(); \
  1198. } \
  1199. else \
  1200. { \
  1201. _pszExp; \
  1202. } \
  1203. } while ( 0 )
  1204. //////////////////////////////////////////////////////////////////////////////
  1205. //++
  1206. //
  1207. // MACRO
  1208. // TraceMsgGUID(
  1209. // _flags,
  1210. // _msg
  1211. // _guid
  1212. // )
  1213. //
  1214. // Description:
  1215. // Dumps a GUID to the debugger only if one of the flags in _flags is
  1216. // set in g_tfModule.
  1217. //
  1218. // Arguments:
  1219. // _flags - Flags to check
  1220. // _msg - msg to print before GUID
  1221. // _guid - GUID to dump
  1222. //
  1223. // Return Values:
  1224. // None.
  1225. //
  1226. //--
  1227. //////////////////////////////////////////////////////////////////////////////
  1228. // BUGBUG: DavidP 09-DEC-1999
  1229. // _guid is evaluated multiple times but the name of the
  1230. // macro is mixed case.
  1231. #define TraceMsgGUID( _flags, _msg, _guid ) \
  1232. do \
  1233. { \
  1234. if ( g_tfModule != 0 ) \
  1235. { \
  1236. TraceMessage( TEXT(__FILE__), \
  1237. __LINE__, \
  1238. __MODULE__, \
  1239. _flags, \
  1240. TEXT("%s {%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}"), \
  1241. TEXT(_msg), \
  1242. _guid.Data1, _guid.Data2, _guid.Data3, \
  1243. _guid.Data4[ 0 ], _guid.Data4[ 1 ], _guid.Data4[ 2 ], _guid.Data4[ 3 ], \
  1244. _guid.Data4[ 4 ], _guid.Data4[ 5 ], _guid.Data4[ 6 ], _guid.Data4[ 7 ] ); \
  1245. } \
  1246. } while ( 0 )
  1247. //////////////////////////////////////////////////////////////////////////////
  1248. //++
  1249. //
  1250. // MACRO
  1251. // ErrorMsg(
  1252. // _szMsg,
  1253. // _err
  1254. // )
  1255. //
  1256. // Description:
  1257. // Print an error out. Can be used to write errors to a file. Note that
  1258. // it will also print the source filename, line number and module name.
  1259. //
  1260. // Arguments:
  1261. // _szMsg - Format string to be displayed.
  1262. // _err - Error code of the error.
  1263. //
  1264. // Return Values:
  1265. // None.
  1266. //
  1267. //--
  1268. //////////////////////////////////////////////////////////////////////////////
  1269. #define ErrorMsg( _szMsg, _err ) \
  1270. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfALWAYS, TEXT(__FUNCTION__) TEXT(": ") TEXT(_szMsg), _err );
  1271. //////////////////////////////////////////////////////////////////////////////
  1272. //++
  1273. //
  1274. // MACRO
  1275. // WndMsg(
  1276. // _hwnd,
  1277. // _umsg,
  1278. // _wparam,
  1279. // _lparam
  1280. // )
  1281. //
  1282. // Description:
  1283. // Prints out a message to trace windows messages.
  1284. //
  1285. // Arguments:
  1286. // _hwnd - The HWND
  1287. // _umsg - The uMsg
  1288. // _wparam - The WPARAM
  1289. // _lparam _ The LPARAM
  1290. //
  1291. // Return Values:
  1292. // None.
  1293. //
  1294. //--
  1295. //////////////////////////////////////////////////////////////////////////////
  1296. // BUGBUG: DavidP 09-DEC-1999
  1297. // _wparam and _lparam are evaluated multiple times but the name
  1298. // of the macro is mixed case.
  1299. #define WndMsg( _hwnd, _umsg, _wparam, _lparam ) \
  1300. do \
  1301. { \
  1302. if ( g_tfModule & mtfWM ) \
  1303. { \
  1304. DebugMsg( TEXT("%s: WM : hWnd = 0x%08x, uMsg = %u, wParam = 0x%08x (%u), lParam = 0x%08x (%u)"), __MODULE__, _hwnd, _umsg, _wparam, _wparam, _lparam, _lparam ); \
  1305. } \
  1306. } while ( 0 )
  1307. //****************************************************************************
  1308. //
  1309. // Debug Macros
  1310. //
  1311. // These calls are only compiled in DEBUG. They are a NOP in RETAIL
  1312. // (not even compiled in).
  1313. //
  1314. //****************************************************************************
  1315. //
  1316. // Same as TraceDo() but only compiled in DEBUG.
  1317. //
  1318. #define DebugDo( _fn ) \
  1319. do \
  1320. { \
  1321. DebugIncrementStackDepthCounter(); \
  1322. DebugMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT("+ ") TEXT(#_fn ) ); \
  1323. _fn; \
  1324. DebugMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT("V") ); \
  1325. DebugDecrementStackDepthCounter(); \
  1326. } while ( 0 )
  1327. //
  1328. // Same as TraceMsgDo() but only compiled in DEBUG.
  1329. //
  1330. #define DebugMsgDo( _fn, _msg ) \
  1331. do \
  1332. { \
  1333. DebugIncrementStackDepthCounter(); \
  1334. DebugMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT("+ ") TEXT(#_fn) ); \
  1335. DebugMessageDo( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(_msg), TEXT(#_fn), _fn ); \
  1336. DebugDecrementStackDepthCounter(); \
  1337. } while ( 0 )
  1338. //****************************************************************************
  1339. //
  1340. // HRESULT testing macros
  1341. //
  1342. // These functions check HRESULT return values and display UI if conditions
  1343. // warrant only in DEBUG.
  1344. //
  1345. //****************************************************************************
  1346. //////////////////////////////////////////////////////////////////////////////
  1347. //++
  1348. //
  1349. // MACRO
  1350. // IsTraceFlagSet(
  1351. // _flag
  1352. // )
  1353. //
  1354. // Description:
  1355. // Checks to see of the flag is set in the global flags or in the per
  1356. // thread flags. If you specify more than one flag and if any of them are
  1357. // set, it will return TRUE.
  1358. //
  1359. // In RETAIL this always return FALSE thereby effectively deleting the
  1360. // block of the if statement. Example:
  1361. //
  1362. // if ( IsTraceFlagSet( mtfPERTHREADTRACE ) )
  1363. // {
  1364. // //
  1365. // // This code only exists in DEBUG.
  1366. // .
  1367. // .
  1368. // .
  1369. // }
  1370. //
  1371. // Arguments:
  1372. // _flags - Flag to check for.
  1373. //
  1374. // Return Values:
  1375. // TRUE - If DEBUG and flag set.
  1376. // FLASE - If RETAIL or flag not set.
  1377. //
  1378. //--
  1379. //////////////////////////////////////////////////////////////////////////////
  1380. #define IsTraceFlagSet( _flag ) ( g_tfModule && IsDebugFlagSet( _flag ) )
  1381. //////////////////////////////////////////////////////////////////////////////
  1382. //++
  1383. //
  1384. // MACRO
  1385. // THR(
  1386. // _hr
  1387. // )
  1388. //
  1389. // Description:
  1390. // Warning is display if HRESULT is anything but S_OK (0). This can be
  1391. // use in an expression. Example:
  1392. //
  1393. // hr = THR( pSomething->DoSomething( arg ) );
  1394. //
  1395. // Arguments:
  1396. // _hr - Function expression to check.
  1397. //
  1398. // Return Values:
  1399. // Result of the "_hr" expression.
  1400. //
  1401. //--
  1402. //////////////////////////////////////////////////////////////////////////////
  1403. #define THR( _hr ) \
  1404. TraceHR( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(#_hr), _hr, FALSE, S_OK )
  1405. #define THRMSG( _hr, _msg ) \
  1406. TraceHR( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(_msg), _hr, FALSE, S_OK )
  1407. #define THRMSG1( _hr, _msg, _arg1 ) \
  1408. TraceHR( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(_msg), _hr, FALSE, S_OK, _arg1 )
  1409. #define THRE( _hr, _hrIgnore ) \
  1410. TraceHR( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(#_hr), _hr, FALSE, _hrIgnore )
  1411. #define THREMSG( _hr, _hrIgnore, _msg ) \
  1412. TraceHR( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(_msg), _hr, FALSE, _hrIgnore )
  1413. #define THREMSG1( _hr, _hrIgnore, _msg, _arg1 ) \
  1414. TraceHR( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(_msg), _hr, FALSE, _hrIgnore, _arg1 )
  1415. //////////////////////////////////////////////////////////////////////////////
  1416. //++
  1417. //
  1418. // MACRO
  1419. // STHR(
  1420. // _hr
  1421. // )
  1422. //
  1423. // Description:
  1424. // Warning is display if FAILED( _hr ) is TRUE. This can be use in an
  1425. // expression. Example:
  1426. //
  1427. // hr = STHR( pSomething->DoSomething( arg ) );
  1428. //
  1429. // Arguments:
  1430. // _hr - Function expression to check.
  1431. //
  1432. // Return Values:
  1433. // Result of the "_hr" expression.
  1434. //
  1435. //--
  1436. //////////////////////////////////////////////////////////////////////////////
  1437. #define STHR( _hr ) \
  1438. TraceHR( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(#_hr), _hr, TRUE, S_OK )
  1439. #define STHRMSG( _hr, _msg ) \
  1440. TraceHR( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(_msg), _hr, TRUE, S_OK )
  1441. #define STHRMSG1( _hr, _msg, _arg1 ) \
  1442. TraceHR( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(_msg), _hr, TRUE, S_OK, _arg1 )
  1443. #define STHRE( _hr, _hrIgnore ) \
  1444. TraceHR( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(#_hr), _hr, TRUE, _hrIgnore )
  1445. #define STHREMSG( _hr, _hrIgnore, _msg ) \
  1446. TraceHR( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(_msg), _hr, TRUE, _hrIgnore )
  1447. #define STHREMSG1( _hr, _hrIgnore, _msg, _arg1 ) \
  1448. TraceHR( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(_msg), _hr, TRUE, _hrIgnore, _arg1 )
  1449. //////////////////////////////////////////////////////////////////////////////
  1450. //++
  1451. //
  1452. // MACRO
  1453. // TW32(
  1454. // _fn
  1455. // )
  1456. //
  1457. // Description:
  1458. // Warning is display if result is anything but ERROR_SUCCESS (0). This
  1459. // can be use in an expression. Example:
  1460. //
  1461. // dwErr = TW32( RegOpenKey( HKLM, "foobar", &hkey ) );
  1462. //
  1463. // Arguments:
  1464. // _fn - Function expression to check.
  1465. //
  1466. // Return Values:
  1467. // Result of the "_fn" expression.
  1468. //
  1469. //--
  1470. //////////////////////////////////////////////////////////////////////////////
  1471. #define TW32( _fn ) \
  1472. TraceWin32( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(#_fn), _fn, ERROR_SUCCESS )
  1473. #define TW32MSG( _fn, _msg ) \
  1474. TraceWin32( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(_msg), _fn, ERROR_SUCCESS )
  1475. #define TW32MSG1( _fn, _msg, _arg1 ) \
  1476. TraceWin32( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(_msg), _fn, ERROR_SUCCESS, _arg1 )
  1477. #define TW32E( _fn, _errIgnore ) \
  1478. TraceWin32( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(#_fn), _fn, _errIgnore )
  1479. #define TW32EMSG( _fn, _errIgnore, _msg ) \
  1480. TraceWin32( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(_msg), _fn, _errIgnore )
  1481. #define TW32EMSG1( _fn, _errIgnore, _msg, _arg1 ) \
  1482. TraceWin32( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(_msg), _fn, _errIgnore, _arg1 )
  1483. //////////////////////////////////////////////////////////////////////////////
  1484. //++
  1485. //
  1486. // MACRO
  1487. // RRETURN(
  1488. // _fn
  1489. // )
  1490. //
  1491. // Description:
  1492. // Warning is display if return value is anything but ERROR_SUCCESS (0).
  1493. //
  1494. // Argument:
  1495. // _fn - Value to return.
  1496. //
  1497. // Return Values:
  1498. // _fn always.
  1499. //
  1500. //--
  1501. //////////////////////////////////////////////////////////////////////////////
  1502. #define RRETURN( _fn ) \
  1503. do \
  1504. { \
  1505. if ( g_tfModule != 0 ) \
  1506. { \
  1507. __MissingTraceFunc = 0; \
  1508. if ( _fn != ERROR_SUCCESS ) \
  1509. { \
  1510. DebugReturnMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT( "V ") TEXT(#_fn) TEXT(" = 0x%08x (%s)"), _fn ); \
  1511. } \
  1512. else \
  1513. { \
  1514. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("V") ); \
  1515. } \
  1516. DebugDecrementStackDepthCounter(); \
  1517. } \
  1518. return _fn; \
  1519. } while ( 0 )
  1520. //////////////////////////////////////////////////////////////////////////////
  1521. //++
  1522. //
  1523. // MACRO
  1524. // QIRETURN(
  1525. // _hr,
  1526. // _riid
  1527. // )
  1528. //
  1529. // Description:
  1530. // Warning is display if HRESULT is anything but S_OK (0) only if
  1531. // mtfQUERYINTERFACE is set in g_tfModule, otherwise only a debug
  1532. // message will be printed. Note that TraceFunc() must have been called
  1533. // on the call stack counter must be incremented prior to using.
  1534. //
  1535. // QIRETURNx will ignore E_NOINTERFACE errors for the interfaces
  1536. // specified.
  1537. //
  1538. // Arguments:
  1539. // _hr - Result of the query interface call.
  1540. // _riid - The reference ID of the interfaced queried for.
  1541. //
  1542. // Return Values:
  1543. // None - calls RETURN macro.
  1544. //
  1545. //--
  1546. //////////////////////////////////////////////////////////////////////////////
  1547. #define QIRETURN( _hr, _riid ) \
  1548. do \
  1549. { \
  1550. if ( _hr ) \
  1551. { \
  1552. TCHAR szGuid[ 40 ]; \
  1553. TCHAR szSymbolicName[ 64 ]; \
  1554. DWORD cchSymbolicName = 64; \
  1555. DebugFindWinerrorSymbolicName( _hr, szSymbolicName, &cchSymbolicName ); \
  1556. Assert( cchSymbolicName != 64 ); \
  1557. DebugMessage( TEXT(__FILE__), \
  1558. __LINE__, \
  1559. __MODULE__, \
  1560. TEXT("*HRESULT* QueryInterface( %s, ppv ) failed(), hr = 0x%08x (%s)"), \
  1561. PszDebugFindInterface( _riid, szGuid ), \
  1562. _hr, \
  1563. szSymbolicName \
  1564. ); \
  1565. } \
  1566. if ( g_tfModule & mtfQUERYINTERFACE ) \
  1567. { \
  1568. __MissingTraceFunc = 0; \
  1569. TraceHR( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(#_hr), _hr, FALSE, S_OK ); \
  1570. } \
  1571. HRETURN( _hr ); \
  1572. } while ( 0 )
  1573. #define QIRETURN1( _hr, _riid, _riidIgnored1 ) \
  1574. do \
  1575. { \
  1576. if ( _hr == E_NOINTERFACE \
  1577. && IsEqualIID( _riid, _riidIgnored1 ) \
  1578. ) \
  1579. { \
  1580. FRETURN( S_OK ); \
  1581. return( _hr ); \
  1582. } \
  1583. QIRETURN( _hr, _riid ); \
  1584. } while ( 0 )
  1585. #define QIRETURN2( _hr, _riid, _riidIgnored1, _riidIgnored2 ) \
  1586. do \
  1587. { \
  1588. if ( _hr == E_NOINTERFACE \
  1589. && ( IsEqualIID( _riid, _riidIgnored1 ) \
  1590. || IsEqualIID( _riid, _riidIgnored2 ) \
  1591. ) \
  1592. ) \
  1593. { \
  1594. FRETURN( S_OK ); \
  1595. return( _hr ); \
  1596. } \
  1597. QIRETURN( _hr, _riid ); \
  1598. } while ( 0 )
  1599. #define QIRETURN3( _hr, _riid, _riidIgnored1, _riidIgnored2, _riidIgnored3 ) \
  1600. do \
  1601. { \
  1602. if ( _hr == E_NOINTERFACE \
  1603. && ( IsEqualIID( _riid, _riidIgnored1 ) \
  1604. || IsEqualIID( _riid, _riidIgnored2 ) \
  1605. || IsEqualIID( _riid, _riidIgnored3 ) \
  1606. ) \
  1607. ) \
  1608. { \
  1609. FRETURN( S_OK ); \
  1610. return( _hr ); \
  1611. } \
  1612. QIRETURN( _hr, _riid ); \
  1613. } while ( 0 )
  1614. #define QIRETURN4( _hr, _riid, _riidIgnored1, _riidIgnored2, _riidIgnored3, _riidIgnored4 ) \
  1615. do \
  1616. { \
  1617. if ( _hr == E_NOINTERFACE \
  1618. && ( IsEqualIID( _riid, _riidIgnored1 ) \
  1619. || IsEqualIID( _riid, _riidIgnored2 ) \
  1620. || IsEqualIID( _riid, _riidIgnored3 ) \
  1621. || IsEqualIID( _riid, _riidIgnored4 ) \
  1622. ) \
  1623. ) \
  1624. { \
  1625. FRETURN( S_OK ); \
  1626. return( _hr ); \
  1627. } \
  1628. QIRETURN( _hr, _riid ); \
  1629. } while ( 0 )
  1630. #define QIRETURN5( _hr, _riid, _riidIgnored1, _riidIgnored2, _riidIgnored3, _riidIgnored4, _riidIgnored5 ) \
  1631. do \
  1632. { \
  1633. if ( _hr == E_NOINTERFACE \
  1634. && ( IsEqualIID( _riid, _riidIgnored1 ) \
  1635. || IsEqualIID( _riid, _riidIgnored2 ) \
  1636. || IsEqualIID( _riid, _riidIgnored3 ) \
  1637. || IsEqualIID( _riid, _riidIgnored4 ) \
  1638. || IsEqualIID( _riid, _riidIgnored5 ) \
  1639. ) \
  1640. ) \
  1641. { \
  1642. FRETURN( S_OK ); \
  1643. return( _hr ); \
  1644. } \
  1645. QIRETURN( _hr, _riid ); \
  1646. } while ( 0 )
  1647. #define QIRETURN6( _hr, _riid, _riidIgnored1, _riidIgnored2, _riidIgnored3, _riidIgnored4, _riidIgnored5, _riidIgnored6 ) \
  1648. do \
  1649. { \
  1650. if ( _hr == E_NOINTERFACE \
  1651. && ( IsEqualIID( _riid, _riidIgnored1 ) \
  1652. || IsEqualIID( _riid, _riidIgnored2 ) \
  1653. || IsEqualIID( _riid, _riidIgnored3 ) \
  1654. || IsEqualIID( _riid, _riidIgnored4 ) \
  1655. || IsEqualIID( _riid, _riidIgnored5 ) \
  1656. || IsEqualIID( _riid, _riidIgnored6 ) \
  1657. ) \
  1658. ) \
  1659. { \
  1660. FRETURN( S_OK ); \
  1661. return( _hr ); \
  1662. } \
  1663. QIRETURN( _hr, _riid ); \
  1664. } while ( 0 )
  1665. #define QIRETURN7( _hr, _riid, _riidIgnored1, _riidIgnored2, _riidIgnored3, _riidIgnored4, _riidIgnored5, _riidIgnored6, _riidIgnored7 ) \
  1666. do \
  1667. { \
  1668. if ( _hr == E_NOINTERFACE \
  1669. && ( IsEqualIID( _riid, _riidIgnored1 ) \
  1670. || IsEqualIID( _riid, _riidIgnored2 ) \
  1671. || IsEqualIID( _riid, _riidIgnored3 ) \
  1672. || IsEqualIID( _riid, _riidIgnored4 ) \
  1673. || IsEqualIID( _riid, _riidIgnored5 ) \
  1674. || IsEqualIID( _riid, _riidIgnored6 ) \
  1675. || IsEqualIID( _riid, _riidIgnored7 ) \
  1676. ) \
  1677. ) \
  1678. { \
  1679. FRETURN( S_OK ); \
  1680. return( _hr ); \
  1681. } \
  1682. QIRETURN( _hr, _riid ); \
  1683. } while ( 0 )
  1684. //////////////////////////////////////////////////////////////////////////////
  1685. //++
  1686. //
  1687. // MACRO
  1688. // QIRETURN_IGNORESTDMARSHALLING(
  1689. // _hr,
  1690. // _riid
  1691. // )
  1692. //
  1693. // Description:
  1694. // Works like QIRETURN (see QIRETURN above), but ignores E_NOINTERFACE for
  1695. // the standard marshalling interfaces.
  1696. //
  1697. // Arguments:
  1698. // _hr - Result of the query interface call.
  1699. // _riid - The reference ID of the interfaced queried for.
  1700. //
  1701. // Return Values:
  1702. // None - calls QIRETURN5 macro.
  1703. //
  1704. //--
  1705. //////////////////////////////////////////////////////////////////////////////
  1706. #define QIRETURN_IGNORESTDMARSHALLING( _hr, _riid ) \
  1707. do \
  1708. { \
  1709. const GUID _COCLASS_IdentityUnmarshall = { 0x0000001b, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 }; \
  1710. const GUID _IID_IMarshalOptions_ = { 0x4c1e39e1, 0xe3e3, 0x4296, 0xaa, 0x86, 0xec, 0x93, 0x8d, 0x89, 0x6e, 0x92 }; \
  1711. QIRETURN6( _hr, _riid, IID_IMarshal, _COCLASS_IdentityUnmarshall, IID_IStdMarshalInfo, IID_IExternalConnection, IID_ICallFactory, _IID_IMarshalOptions_ ); \
  1712. } while ( 0 )
  1713. #define QIRETURN_IGNORESTDMARSHALLING1( _hr, _riid, _riid1 ) \
  1714. do \
  1715. { \
  1716. const GUID _COCLASS_IdentityUnmarshall = { 0x0000001b, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 }; \
  1717. const GUID _IID_IMarshalOptions_ = { 0x4c1e39e1, 0xe3e3, 0x4296, 0xaa, 0x86, 0xec, 0x93, 0x8d, 0x89, 0x6e, 0x92 }; \
  1718. QIRETURN7( _hr, _riid, IID_IMarshal, _COCLASS_IdentityUnmarshall, IID_IStdMarshalInfo, IID_IExternalConnection, IID_ICallFactory, _riid1, _IID_IMarshalOptions_ ); \
  1719. } while ( 0 )
  1720. //////////////////////////////////////////////////////////////////////////////
  1721. //++
  1722. //
  1723. // MACRO
  1724. // BOOLTOSTRING(
  1725. // _fBool
  1726. // )
  1727. //
  1728. // Desfription:
  1729. // If _fBool is true, returns address of "TRUE" else returns address of
  1730. // "FALSE".
  1731. //
  1732. // Argument:
  1733. // _fBool - Expression to evaluate.
  1734. //
  1735. // Return Values:
  1736. // address of "TRUE" if _fBool is true.
  1737. // address of "FALSE" if _fBool is false.
  1738. //
  1739. //--
  1740. //////////////////////////////////////////////////////////////////////////////
  1741. #define BOOLTOSTRING( _fBool ) ( (_fBool) ? g_szTrue : g_szFalse )
  1742. //****************************************************************************
  1743. //
  1744. // Trace/Debug Functions - these do not exist in RETAIL.
  1745. //
  1746. //****************************************************************************
  1747. BOOL
  1748. IsDebugFlagSet(
  1749. TRACEFLAG tfIn
  1750. );
  1751. void
  1752. __cdecl
  1753. TraceMsg(
  1754. TRACEFLAG tfIn,
  1755. LPCSTR pszFormatIn,
  1756. ...
  1757. );
  1758. void
  1759. __cdecl
  1760. TraceMsg(
  1761. TRACEFLAG tfIn,
  1762. LPCWSTR pszFormatIn,
  1763. ...
  1764. );
  1765. void
  1766. __cdecl
  1767. DebugMsg(
  1768. LPCSTR pszFormatIn,
  1769. ...
  1770. );
  1771. void
  1772. __cdecl
  1773. DebugMsg(
  1774. LPCWSTR pszFormatIn,
  1775. ...
  1776. );
  1777. void
  1778. __cdecl
  1779. DebugMsgNoNewline(
  1780. LPCSTR pszFormatIn,
  1781. ...
  1782. );
  1783. void
  1784. __cdecl
  1785. DebugMsgNoNewline(
  1786. LPCWSTR pszFormatIn,
  1787. ...
  1788. );
  1789. void
  1790. __cdecl
  1791. TraceMessage(
  1792. LPCTSTR pszFileIn,
  1793. const int nLineIn,
  1794. LPCTSTR pszModuleIn,
  1795. TRACEFLAG tfIn,
  1796. LPCTSTR pszFormatIn,
  1797. ...
  1798. );
  1799. void
  1800. __cdecl
  1801. TraceMessageDo(
  1802. LPCTSTR pszFileIn,
  1803. const int nLineIn,
  1804. LPCTSTR pszModuleIn,
  1805. TRACEFLAG tfIn,
  1806. LPCTSTR pszFormatIn,
  1807. LPCTSTR pszFuncIn,
  1808. ...
  1809. );
  1810. void
  1811. __cdecl
  1812. DebugMessage(
  1813. LPCTSTR pszFileIn,
  1814. const int nLineIn,
  1815. LPCTSTR pszModuleIn,
  1816. LPCTSTR pszFormatIn,
  1817. ...
  1818. );
  1819. void
  1820. __cdecl
  1821. DebugMessageDo(
  1822. LPCTSTR pszFileIn,
  1823. const int nLineIn,
  1824. LPCTSTR pszModuleIn,
  1825. LPCTSTR pszFormatIn,
  1826. LPCTSTR pszFuncIn,
  1827. ...
  1828. );
  1829. BOOL
  1830. AssertMessage(
  1831. LPCTSTR pszFileIn,
  1832. const int nLineIn,
  1833. LPCTSTR pszModuleIn,
  1834. LPCTSTR pszfnIn,
  1835. BOOL fTrueIn,
  1836. ...
  1837. );
  1838. HRESULT
  1839. TraceHR(
  1840. LPCTSTR pszFileIn,
  1841. const int nLineIn,
  1842. LPCTSTR pszModuleIn,
  1843. LPCTSTR pszfnIn,
  1844. HRESULT hrIn,
  1845. BOOL fSuccessIn,
  1846. HRESULT hrIgnoreIn,
  1847. ...
  1848. );
  1849. ULONG
  1850. TraceWin32(
  1851. LPCTSTR pszFileIn,
  1852. const int nLineIn,
  1853. LPCTSTR pszModuleIn,
  1854. LPCTSTR pszfnIn,
  1855. ULONG ulErrIn,
  1856. ULONG ulErrIgnoreIn,
  1857. ...
  1858. );
  1859. void
  1860. __cdecl
  1861. TraceLogMsgNoNewline(
  1862. LPCSTR pszFormatIn,
  1863. ...
  1864. );
  1865. void
  1866. __cdecl
  1867. TraceLogMsgNoNewline(
  1868. LPCWSTR pszFormatIn,
  1869. ...
  1870. );
  1871. #if 0
  1872. //
  1873. // Trying to get the NTSTATUS stuff to play in "user world"
  1874. // is just about impossible. This is here in case it is needed
  1875. // and one could find the right combination of headers to
  1876. // make it work. Inflicting such pain on others is the reason
  1877. // why this function is #ifdef'fed.
  1878. //
  1879. void
  1880. DebugFindNTStatusSymbolicName(
  1881. NTSTATUS dwStatusIn,
  1882. LPTSTR pszNameOut,
  1883. LPDWORD pcchNameInout
  1884. );
  1885. #endif
  1886. void
  1887. DebugFindWinerrorSymbolicName(
  1888. DWORD dwErrIn,
  1889. LPTSTR pszNameOut,
  1890. LPDWORD pcchNameInout
  1891. );
  1892. void
  1893. DebugReturnMessage(
  1894. LPCTSTR pszFileIn,
  1895. const int nLineIn,
  1896. LPCTSTR pszModuleIn,
  1897. LPCTSTR pszMessageIn,
  1898. DWORD dwErrIn
  1899. );
  1900. //****************************************************************************
  1901. //
  1902. // Use the TraceMemoryXXX wrappers, not the DebugMemoryXXX functions.
  1903. // The memory tracking functions do not exist in RETAIL (converted to NOP).
  1904. //
  1905. //****************************************************************************
  1906. typedef enum EMEMORYBLOCKTYPE
  1907. {
  1908. mmbtUNKNOWN = 0, // Never used
  1909. mmbtMEMORYALLOCATION, // GlobalAlloc/LocalAlloc/malloc
  1910. mmbtOBJECT, // Object pointer
  1911. mmbtHANDLE, // Object handle
  1912. mmbtPUNK, // IUnknown pointer
  1913. mmbtSYSALLOCSTRING // SysAllocString
  1914. } EMEMORYBLOCKTYPE;
  1915. #define TraceMemoryAdd( _mbtType, _hGlobalIn, _pszFileIn, _nLineIn, _pszModuleIn, _dwBytesIn, _pszCommentIn ) \
  1916. DebugMemoryAdd( _mbtType, _hGlobalIn, _pszFileIn, _nLineIn, _pszModuleIn, _dwBytesIn, _pszCommentIn )
  1917. #define TraceMemoryAddAddress( _pv ) \
  1918. DebugMemoryAdd( mmbtMEMORYALLOCATION, _pv, TEXT(__FILE__), __LINE__, __MODULE__, 0, TEXT(#_pv) )
  1919. #define TraceMemoryAddHandle( _handle ) \
  1920. DebugMemoryAdd( mmbtHANDLE, _handle, TEXT(__FILE__), __LINE__, __MODULE__, 0, TEXT(#_handle) )
  1921. #define TraceMemoryAddObject( _pv ) \
  1922. DebugMemoryAdd( mmbtOBJECT, _pv, TEXT(__FILE__), __LINE__, __MODULE__, 0, TEXT(#_pv) )
  1923. #define TraceMemoryAddPunk( _punk ) \
  1924. DebugMemoryAdd( mmbtPUNK, _punk, TEXT(__FILE__), __LINE__, __MODULE__, 0, TEXT(#_punk) )
  1925. #define TraceMemoryAddBSTR( _pv ) \
  1926. DebugMemoryAdd( mmbtSYSALLOCSTRING, _pv, TEXT(__FILE__), __LINE__, __MODULE__, 0, TEXT(#_pv) )
  1927. #define TraceMemoryDelete( _hGlobalIn, _fClobberIn ) \
  1928. DebugMemoryDelete( mmbtUNKNOWN, _hGlobalIn, TEXT(__FILE__), __LINE__, __MODULE__, _fClobberIn )
  1929. #define TraceStrDup( _sz ) \
  1930. (LPTSTR) DebugMemoryAdd( mmbtMEMORYALLOCATION, StrDup( _sz ), TEXT(__FILE__), __LINE__, __MODULE__, 0, TEXT("StrDup( ") TEXT(#_sz) TEXT(" )") )
  1931. #if defined( USES_SYSALLOCSTRING )
  1932. // BUGBUG: DavidP 09-DEC-1999
  1933. // _sz is evaluated multiple times but the name of the
  1934. // macro is mixed case.
  1935. #define TraceSysAllocString( _sz ) \
  1936. (BSTR) DebugMemoryAdd( mmbtSYSALLOCSTRING, SysAllocString( _sz ), TEXT(__FILE__), __LINE__, __MODULE__, ((DWORD)( *(&_sz) == NULL ? 0 : wcslen( _sz ) + 1 )), TEXT("SysAllocString( ") TEXT(#_sz) TEXT(")") )
  1937. // BUGBUG: DavidP 09-DEC-1999
  1938. // _sz and _len are evaluated multiple times but the name of the
  1939. // macro is mixed case.
  1940. #define TraceSysAllocStringByteLen( _sz, _len ) \
  1941. (BSTR) DebugMemoryAdd( mmbtSYSALLOCSTRING, SysAllocStringByteLen( _sz, _len ), TEXT(__FILE__), __LINE__, __MODULE__, _len, TEXT("SysAllocStringByteLen( ") TEXT(#_sz) TEXT(")") )
  1942. // BUGBUG: DavidP 09-DEC-1999
  1943. // _sz and _len are evaluated multiple times but the name of the
  1944. // macro is mixed case.
  1945. #define TraceSysAllocStringLen( _sz, _len ) \
  1946. (BSTR) DebugMemoryAdd( mmbtSYSALLOCSTRING, SysAllocStringLen( _sz, _len ), TEXT(__FILE__), __LINE__, __MODULE__, _len + 1, TEXT("SysAllocStringLen( ") TEXT(#_sz) TEXT(")") )
  1947. #define TraceSysReAllocString( _bstrOrg, _bstrNew ) \
  1948. DebugSysReAllocString( TEXT(__FILE__), __LINE__, __MODULE__, _bstrOrg, _bstrNew, TEXT("TraceSysReAllocString(") TEXT(#_bstrOrg) TEXT(", ") TEXT(#_bstrNew) TEXT(" )") )
  1949. #define TraceSysReAllocStringLen( _bstrOrg, _bstrNew, _cch ) \
  1950. DebugSysReAllocStringLen( TEXT(__FILE__), __LINE__, __MODULE__, _bstrOrg, _bstrNew, _cch, TEXT("TraceSysReAllocString(") TEXT(#_bstrOrg) TEXT(", ") TEXT(#_bstrNew) TEXT(", ") TEXT(#_cch) TEXT(" )") )
  1951. #define TraceSysFreeString( _bstr ) \
  1952. DebugMemoryDelete( mmbtSYSALLOCSTRING, _bstr, TEXT(__FILE__), __LINE__, __MODULE__, TRUE ); \
  1953. SysFreeString( _bstr )
  1954. #endif // USES_SYSALLOCSTRING
  1955. //****************************************************************************
  1956. //
  1957. // Memory tracing functions - these are remapped to the GlobalAlloc/GlobalFree
  1958. // heap functions when in RETAIL. Use the TraceMemoryXXX wrappers, not the
  1959. // DebugMemoryXXX functions.
  1960. //
  1961. //****************************************************************************
  1962. void *
  1963. DebugAlloc(
  1964. LPCTSTR pszFileIn,
  1965. const int nLineIn,
  1966. LPCTSTR pszModuleIn,
  1967. UINT uFlagsIn,
  1968. DWORD dwBytesIn,
  1969. LPCTSTR pszCommentIn
  1970. );
  1971. void *
  1972. DebugReAlloc(
  1973. LPCTSTR pszFileIn,
  1974. const int nLineIn,
  1975. LPCTSTR pszModuleIn,
  1976. void * pvMemIn,
  1977. UINT uFlagsIn,
  1978. DWORD dwBytesIn,
  1979. LPCTSTR pszCommentIn
  1980. );
  1981. BOOL
  1982. DebugFree(
  1983. void * pvMemIn,
  1984. LPCTSTR pszFileIn,
  1985. const int nLineIn,
  1986. LPCTSTR pszModuleIn
  1987. );
  1988. void *
  1989. DebugMemoryAdd(
  1990. EMEMORYBLOCKTYPE mbtType
  1991. , void * pvMemIn
  1992. , LPCTSTR pszFileIn
  1993. , const int nLineIn
  1994. , LPCTSTR pszModuleIn
  1995. , DWORD dwBytesIn
  1996. , LPCTSTR pszCommentIn
  1997. );
  1998. void
  1999. DebugMemoryDelete(
  2000. EMEMORYBLOCKTYPE mbtTypeIn
  2001. , void * pvMemIn
  2002. , LPCTSTR pszFileIn
  2003. , const int nLineIn
  2004. , LPCTSTR pszModuleIn
  2005. , BOOL fClobberIn
  2006. );
  2007. #if defined( USES_SYSALLOCSTRING )
  2008. INT
  2009. DebugSysReAllocString(
  2010. LPCTSTR pszFileIn,
  2011. const int nLineIn,
  2012. LPCTSTR pszModuleIn,
  2013. BSTR * pbstrIn,
  2014. const OLECHAR * pszIn,
  2015. LPCTSTR pszCommentIn
  2016. );
  2017. INT
  2018. DebugSysReAllocStringLen(
  2019. LPCTSTR pszFileIn,
  2020. const int nLineIn,
  2021. LPCTSTR pszModuleIn,
  2022. BSTR * pbstrIn,
  2023. const OLECHAR * pszIn,
  2024. unsigned int ucchIn,
  2025. LPCTSTR pszCommentIn
  2026. );
  2027. #endif // USES_SYSALLOCSTRING
  2028. void
  2029. DebugMemoryCheck(
  2030. LPVOID pvListIn,
  2031. LPCTSTR pszListNameIn
  2032. );
  2033. //****************************************************************************
  2034. //
  2035. // operator new() for C++
  2036. //
  2037. //****************************************************************************
  2038. #ifdef __cplusplus
  2039. extern
  2040. void *
  2041. __cdecl
  2042. operator new(
  2043. size_t nSizeIn,
  2044. LPCTSTR pszFileIn,
  2045. const int nLineIn,
  2046. LPCTSTR pszModuleIn
  2047. );
  2048. /*
  2049. //****************************************************************************
  2050. //
  2051. // operator new []() for C++
  2052. //
  2053. //****************************************************************************
  2054. extern
  2055. void *
  2056. __cdecl
  2057. operator new [](
  2058. size_t nSizeIn,
  2059. LPCTSTR pszFileIn,
  2060. const int nLineIn,
  2061. LPCTSTR pszModuleIn
  2062. );
  2063. */
  2064. //****************************************************************************
  2065. //
  2066. // operator delete() for C++
  2067. //
  2068. //****************************************************************************
  2069. extern
  2070. void
  2071. __cdecl
  2072. operator delete(
  2073. void * pMem,
  2074. LPCTSTR pszFileIn,
  2075. const int nLineIn,
  2076. LPCTSTR pszModuleIn
  2077. );
  2078. /*
  2079. //****************************************************************************
  2080. //
  2081. // operator delete []() for C++
  2082. //
  2083. //****************************************************************************
  2084. extern
  2085. void
  2086. __cdecl
  2087. operator delete [](
  2088. void * pMemIn,
  2089. size_t stSizeIn,
  2090. LPCTSTR pszFileIn,
  2091. const int nLineIn,
  2092. LPCTSTR pszModuleIn
  2093. );
  2094. */
  2095. //
  2096. // Remap "new" to our macro so "we" don't have to type anything extra and
  2097. // so it magically dissappears in RETAIL.
  2098. //
  2099. #define new new( TEXT(__FILE__), __LINE__, __MODULE__ )
  2100. #endif
  2101. //****************************************************************************
  2102. //
  2103. //
  2104. #else // it's RETAIL ******************************************************
  2105. //
  2106. //
  2107. //****************************************************************************
  2108. #pragma message("BUILD: RETAIL macros being built")
  2109. //
  2110. // Debugging -> NOPs
  2111. //
  2112. #define DEFINE_MODULE( _module )
  2113. #define __MODULE__ NULL
  2114. #define DEFINE_THISCLASS( _class )
  2115. #define __THISCLASS__ NULL
  2116. //#define DEFINE_SUPER( _super )
  2117. //#define __SUPERCLASS__ NULL
  2118. #define BOOLTOSTRING( _fBool ) NULL
  2119. #define DebugDo( _fn )
  2120. #define DebugMsgDo( _fn, _msg )
  2121. #define TraceMsgGUID( _f, _m, _g )
  2122. #define AssertMessage TRUE
  2123. //
  2124. // TODO: gpease 08-NOV-1999
  2125. // We probably want to do something special for ErrorMsg()
  2126. //
  2127. #define ErrorMsg 1 ? (void)0 : (void)__noop
  2128. #define TraceMsg 1 ? (void)0 : (void)__noop
  2129. #define WndMsg 1 ? (void)0 : (void)__noop
  2130. #define DebugMsg 1 ? (void)0 : (void)__noop
  2131. #define DebugMsgNoNewline 1 ? (void)0 : (void)__noop
  2132. #define TraceMessage 1 ? (void)0 : (void)__noop
  2133. #define DebugMessage 1 ? (void)0 : (void)__noop
  2134. #define TraceHR 1 ? (void)0 : (void)__noop
  2135. #define TraceFunc 1 ? (void)0 : (void)__noop
  2136. #define TraceFunc1 1 ? (void)0 : (void)__noop
  2137. #define TraceFunc2 1 ? (void)0 : (void)__noop
  2138. #define TraceFunc3 1 ? (void)0 : (void)__noop
  2139. #define TraceFunc4 1 ? (void)0 : (void)__noop
  2140. #define TraceFunc5 1 ? (void)0 : (void)__noop
  2141. #define TraceFunc6 1 ? (void)0 : (void)__noop
  2142. #define TraceQIFunc 1 ? (void)0 : (void)__noop
  2143. #define TraceFlow 1 ? (void)0 : (void)__noop
  2144. #define TraceFlow1 1 ? (void)0 : (void)__noop
  2145. #define TraceFlow2 1 ? (void)0 : (void)__noop
  2146. #define TraceFlow3 1 ? (void)0 : (void)__noop
  2147. #define TraceFlow4 1 ? (void)0 : (void)__noop
  2148. #define TraceFlow5 1 ? (void)0 : (void)__noop
  2149. #define TraceFlow6 1 ? (void)0 : (void)__noop
  2150. #define TraceFuncExit() return
  2151. #if defined( DEBUG_SW_TRACING_ENABLED )
  2152. #define TraceInitializeProcess( _rgControl, _sizeofControl, _fGlobalMemoryTackingIn )
  2153. #define TraceTerminateProcess( _rgControl, _sizeofControl )
  2154. #else // ! DEBUG_SW_TRACING_ENABLED
  2155. #define TraceInitializeProcess( _fGlobalMemoryTackingIn )
  2156. #define TraceTerminateProcess()
  2157. #endif // DEBUG_SW_TRACING_ENABLED
  2158. #define TraceInitializeThread( _name )
  2159. #define TraceThreadRundown()
  2160. #define TraceMemoryAdd( _mbtType, _hGlobalIn, _pszFileIn, _nLineIn, _pszModuleIn, _uFlagsIn, _dwBytesIn, _pszCommentIn ) _hGlobalIn
  2161. #define TraceMemoryAddHandle( _handle ) _handle
  2162. #define TraceMemoryAddBSTR( _bstr ) _bstr
  2163. #define TraceMemoryAddAddress( _pv ) _pv
  2164. #define TraceMemoryAddHandle( _obj ) _obj
  2165. #define TraceMemoryAddPunk( _punk ) _punk
  2166. #define TraceMemoryDelete( _h, _b ) _h
  2167. #define TraceMemoryAddObject( _pv ) _pv
  2168. #define IsTraceFlagSet( _flag ) FALSE
  2169. //
  2170. // Tracing -> just do operation
  2171. //
  2172. #define TraceDo( _fn ) _fn
  2173. #define TraceMsgDo( _fn, _msg ) _fn
  2174. #define TraceMsgDo1( _fn, _msg, _arg1 ) _fn
  2175. #define TraceMsgDo2( _fn, _msg, _arg1, _arg2 ) _fn
  2176. #define TraceMsgDo3( _fn, _msg, _arg1, _arg2, _arg3 ) _fn
  2177. #define TraceMsgDo4( _fn, _msg, _arg1, _arg2, _arg3, _arg4 ) _fn
  2178. #define TraceMsgDo5( _fn, _msg, _arg1, _arg2, _arg3, _arg4, _arg5 ) _fn
  2179. #define TraceMsgDo6( _fn, _msg, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6 ) _fn
  2180. #define TraceMsgPreDo( _fn, _msg1, _msg2 ) _fn
  2181. #define TraceMsgPreDo1( _fn, _msg1, _msg2, _arg1 ) _fn
  2182. #define TraceMsgPreDo2( _fn, _msg1, _msg2, _arg1, _arg2 ) _fn
  2183. #define TraceMsgPreDo3( _fn, _msg1, _msg2, _arg1, _arg2, _arg3 ) _fn
  2184. #define TraceMsgPreDo4( _fn, _msg1, _msg2, _arg1, _arg2, _arg3, _arg4 ) _fn
  2185. #define TraceMsgPreDo5( _fn, _msg1, _msg2, _arg1, _arg2, _arg3, _arg4, _arg5 ) _fn
  2186. #define TraceMsgPreDo6( _fn, _msg1, _msg2, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6 ) _fn
  2187. #define TraceAssertIfZero( _fn ) _fn
  2188. //
  2189. // RETURN testing -> do retail
  2190. //
  2191. #define THR( _hr ) _hr
  2192. #define THRMSG( _hr, _msg ) _hr
  2193. #define THRMSG1( _hr, _msg, _arg1 ) _hr
  2194. #define THRE( _hr, _hrIgnore ) _hr
  2195. #define THREMSG( _hr, _hrIgnore, _msg ) _hr
  2196. #define THREMSG1( _hr, _hrIgnore, _msg, _arg1 ) _hr
  2197. #define STHR( _hr ) _hr
  2198. #define STHRMSG( _hr, _msg ) _hr
  2199. #define STHRMSG1( _hr, _msg, _arg1 ) _hr
  2200. #define STHRE( _hr, _hrIgnore ) _hr
  2201. #define STHREMSG( _hr, _hrIgnore, _msg ) _hr
  2202. #define STHREMSG1( _hr, _hrIgnore, _msg, _arg1 ) _hr
  2203. #define TW32( _fn ) _fn
  2204. #define TW32MSG( _fn, _msg ) _fn
  2205. #define TW32MSG1( _fn, _msg, _arg1 ) _fn
  2206. #define TW32E( _fn, _errIgnore ) _fn
  2207. #define TW32EMSG( _fn, _errIgnore, _msg ) _fn
  2208. #define TW32EMSG1( _fn, _errIgnore, _msg, _arg1 ) _fn
  2209. #define RETURN( _fn ) return _fn
  2210. #define FRETURN( _fn )
  2211. #define RRETURN( _fn ) return _fn
  2212. #define HRETURN( _hr ) return _hr
  2213. #define QIRETURN( _qi, _riid ) return _qi
  2214. #define QIRETURN1( _qi, _riid, _riid1 ) return _qi
  2215. #define QIRETURN2( _qi, _riid, _riid1, _riid2 ) return _qi
  2216. #define QIRETURN3( _qi, _riid, _riid1, _riid2, _riid3 ) return _qi
  2217. #define QIRETURN4( _qi, _riid, _riid1, _riid2, _riid3, _riid4 ) return _qi
  2218. #define QIRETURN5( _qi, _riid, _riid1, _riid2, _riid3, _riid4, _riid5 ) return _qi
  2219. #define QIRETURN6( _qi, _riid, _riid1, _riid2, _riid3, _riid4, _riid5, _riid6 ) return _qi
  2220. #define QIRETURN7( _qi, _riid, _riid1, _riid2, _riid3, _riid4, _riid5, _riid6, _riid7 ) return _qi
  2221. #define QIRETURN_IGNORESTDMARSHALLING( _qi, _riid ) return _qi
  2222. #define QIRETURN_IGNORESTDMARSHALLING1( _qi, _riid, _riid1 ) return _qi
  2223. //
  2224. // Memory Functions -> do retail
  2225. //
  2226. #define TraceAlloc( _flags, _size ) HeapAlloc( GetProcessHeap(), _flags, _size )
  2227. #define TraceAllocString( _flags, _size ) (LPTSTR) HeapAlloc( GetProcessHeap(), flags, (_size) * sizeof( TCHAR ) )
  2228. #define TraceReAlloc( _pvMem, _uBytes, _uFlags ) ( ( _pvMem == NULL ) \
  2229. ? HeapAlloc( GetProcessHeap(), _uFlags, _uBytes ) \
  2230. : HeapReAlloc( GetProcessHeap(), _uFlags, _pvMem, _uBytes ) )
  2231. #define TraceFree( _pv ) HeapFree( GetProcessHeap(), 0, _pv )
  2232. #define TraceStrDup( _sz ) StrDup( _sz )
  2233. #define TraceSysAllocString( _sz ) SysAllocString( _sz )
  2234. #define TraceSysAllocStringByteLen( _sz, _len ) SysAllocStringByteLen( _sz, _len )
  2235. #define TraceSysAllocStringLen( _sz, _len ) SysAllocStringLen( _sz, _len )
  2236. #define TraceSysReAllocString( _bstrOrg, _bstrNew ) SysReAllocString( _bstrOrg, _bstrNew )
  2237. #define TraceSysReAllocStringLen( _bstrOrg, _bstrNew, _cch ) SysReAllocStringLen( _bstrOrg, _bstrNew, _cch )
  2238. #define TraceSysFreeString( _bstr ) SysFreeString( _bstr )
  2239. #define TraceCreateMemoryList( _pvIn )
  2240. #define TraceMoveToMemoryList( _addr, _pvIn )
  2241. //#define TraceMemoryListDelete( _addr, _pvIn, _fClobber )
  2242. #define TraceTerminateMemoryList( _pvIn )
  2243. #define TraceMoveFromMemoryList( _addr, _pmbIn )
  2244. #endif // DEBUG
  2245. #if DBG==1 || defined( _DEBUG )
  2246. //////////////////////////////////////////////////////////////////////////////
  2247. //
  2248. // MACRO
  2249. // DEBUG_BREAK
  2250. //
  2251. // Description:
  2252. // Because the system expection handler can hick-up over INT 3s and
  2253. // DebugBreak()s, This x86 only macro causes the program to break in the
  2254. // right spot.
  2255. //
  2256. //////////////////////////////////////////////////////////////////////////////
  2257. #if defined( _X86_ )
  2258. #define DEBUG_BREAK do { _try { _asm int 3 } _except (EXCEPTION_EXECUTE_HANDLER) {;} } while ( 0 )
  2259. #else
  2260. #define DEBUG_BREAK DebugBreak()
  2261. #endif
  2262. //////////////////////////////////////////////////////////////////////////////
  2263. //++
  2264. //
  2265. // MACRO
  2266. // Assert(
  2267. // _fn
  2268. // )
  2269. //
  2270. // Description:
  2271. // Checks to see if the Expression is TRUE. If not, a message will be
  2272. // displayed to the user on wether the program should break or continue.
  2273. //
  2274. // Arguments:
  2275. // _fn - Expression being asserted.
  2276. //
  2277. // Return Values:
  2278. // None.
  2279. //
  2280. //--
  2281. //////////////////////////////////////////////////////////////////////////////
  2282. #ifdef Assert
  2283. #undef Assert
  2284. #endif
  2285. // BUGBUG: DavidP 09-DEC-1999
  2286. // __fn is evaluated multiple times but the name of the
  2287. // macro is mixed case.
  2288. #define Assert( _fn ) \
  2289. do \
  2290. { \
  2291. if ( ! (_fn) && AssertMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(#_fn), !!(_fn) ) ) \
  2292. { \
  2293. DEBUG_BREAK; \
  2294. } \
  2295. } while ( 0 )
  2296. //////////////////////////////////////////////////////////////////////////////
  2297. //++
  2298. //
  2299. // MACRO
  2300. // AssertMsg(
  2301. // _fn,
  2302. // _msg
  2303. // )
  2304. //
  2305. // Descrption:
  2306. // Just like an Assert but has an (hopefully) informative message
  2307. // associated with it.
  2308. //
  2309. // Arguments:
  2310. // _fn - Expression to be evaluated.
  2311. // _msg - Message to be display if assertion fails.
  2312. //
  2313. // Return Values:
  2314. // None.
  2315. //
  2316. //--
  2317. //////////////////////////////////////////////////////////////////////////////
  2318. #ifdef AssertMsg
  2319. #undef AssertMsg
  2320. #undef AssertMsg1
  2321. #endif
  2322. // BUGBUG: DavidP 09-DEC-1999
  2323. // _fn is evaluated multiple times but the name of the
  2324. // macro is mixed case.
  2325. #define AssertMsg( _fn, _msg ) \
  2326. do \
  2327. { \
  2328. if ( ! (_fn) && AssertMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(_msg), !!(_fn) ) ) \
  2329. { \
  2330. DEBUG_BREAK; \
  2331. } \
  2332. } while ( 0 )
  2333. #define AssertMsg1( _fn, _msg, _arg1 ) \
  2334. do \
  2335. { \
  2336. if ( ! (_fn) && AssertMessage( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(_msg), !!(_fn), _arg1 ) ) \
  2337. { \
  2338. DEBUG_BREAK; \
  2339. } \
  2340. } while ( 0 )
  2341. //////////////////////////////////////////////////////////////////////////////
  2342. //++
  2343. //
  2344. // MACRO
  2345. // AssertString(
  2346. // _fn,
  2347. // _msg
  2348. // )
  2349. //
  2350. // Descrption:
  2351. // Just like an Assert but has a (hopefully) informative string
  2352. // associated with it.
  2353. //
  2354. // Arguments:
  2355. // _fn - Expression to be evaluated.
  2356. // _msg - String to be display if assertion fails.
  2357. //
  2358. // Return Values:
  2359. // None.
  2360. //
  2361. //--
  2362. //////////////////////////////////////////////////////////////////////////////
  2363. #ifdef AssertString
  2364. #undef AssertString
  2365. #endif
  2366. // BUGBUG: DavidP 09-DEC-1999
  2367. // _fn is evaluated multiple times but the name of the
  2368. // macro is mixed case.
  2369. #define AssertString( _fn, _str ) \
  2370. do \
  2371. { \
  2372. if ( ! (_fn) && AssertMessage( TEXT(__FILE__), __LINE__, __MODULE__, _str, !!(_fn) ) ) \
  2373. { \
  2374. DEBUG_BREAK; \
  2375. } \
  2376. } while ( 0 )
  2377. #undef VERIFY
  2378. #undef VERIFYMSG
  2379. #undef VERIFYMSG1
  2380. #undef VERIFYSTRING
  2381. #define VERIFY( _fn ) Assert( _fn )
  2382. #define VERIFYMSG( _fn, _msg ) AssertMsg( _fn, _msg )
  2383. #define VERIFYMSG1( _fn, _msg, _arg1 ) AssertMsg1( _fn, _msg, _arg1 )
  2384. #define VERIFYSTRING( _fn, _str ) AssertString( _fn, _str )
  2385. #else // DBG!=1 && !_DEBUG
  2386. #define DEBUG_BREAK DebugBreak()
  2387. #ifndef Assert
  2388. #define Assert( _fn )
  2389. #endif
  2390. #ifndef AssertMsg
  2391. #define AssertMsg( _fn, _msg )
  2392. #endif
  2393. #ifndef AssertMsg1
  2394. #define AssertMsg1( _fn, _msg, _arg1 )
  2395. #endif
  2396. #ifndef AssertString
  2397. #define AssertString( _fn, _msg )
  2398. #endif
  2399. #ifndef VERIFY
  2400. #define VERIFY( _fn ) _fn
  2401. #endif
  2402. #ifndef VERIFYMSG
  2403. #define VERIFYMSG( _fn, _msg ) _fn
  2404. #endif
  2405. #ifndef VERIFYMSG1
  2406. #define VERIFYMSG1( _fn, _msg, _arg1 ) _fn
  2407. #endif
  2408. #ifndef VERIFYSTRING
  2409. #define VERIFYSTRING( _fn, _str ) _fn
  2410. #endif
  2411. #endif // DBG==1 || _DEBUG