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.

2745 lines
91 KiB

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