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.

652 lines
19 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: WIADEBUG.H
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 9/6/1999
  12. *
  13. * DESCRIPTION: Declarations for the debugging functions, macros and classes
  14. *
  15. *******************************************************************************/
  16. #ifndef __WIADEBUG_H_INCLUDED
  17. #define __WIADEBUG_H_INCLUDED
  18. #include <windows.h>
  19. #include "simcrit.h"
  20. #if !defined(__cplusplus)
  21. #error This library can only be used in c++ programs.
  22. #endif
  23. //
  24. // Severity levels
  25. //
  26. enum
  27. {
  28. WiaDebugSeverityNormal = 0,
  29. WiaDebugSeverityWarning = 1,
  30. WiaDebugSeverityError = 2
  31. };
  32. //
  33. // Make sure these haven't already been defined. This shouldn't normally be a problem.
  34. //
  35. #ifdef WIA_DEBUG_CREATE
  36. #undef WIA_DEBUG_CREATE
  37. #endif
  38. #ifdef WIA_DEBUG_DESTROY
  39. #undef WIA_DEBUG_DESTROY
  40. #endif
  41. #ifdef WIA_SET_TRACE_MASK
  42. #undef WIA_SET_TRACE_MASK
  43. #endif
  44. #ifdef WIA_PUSHFUNCTION
  45. #undef WIA_PUSHFUNCTION
  46. #endif
  47. #ifdef WIA_PUSH_FUNCTION
  48. #undef WIA_PUSH_FUNCTION
  49. #endif
  50. #ifdef WIA_PUSHFUNCTION_MASK
  51. #undef WIA_PUSHFUNCTION_MASK
  52. #endif
  53. #ifdef WIA_PUSH_FUNCTION_MASK
  54. #undef WIA_PUSH_FUNCTION_MASK
  55. #endif
  56. #ifdef WIA_TRACE
  57. #undef WIA_TRACE
  58. #endif
  59. #ifdef WIA_WARNING
  60. #undef WIA_WARNING
  61. #endif
  62. #ifdef WIA_ERROR
  63. #undef WIA_ERROR
  64. #endif
  65. #ifdef WIA_PRINTHRESULT
  66. #undef WIA_PRINTHRESULT
  67. #endif
  68. #ifdef WIA_PRINTGUID
  69. #undef WIA_PRINTGUID
  70. #endif
  71. #ifdef WIA_PRINTWINDOWMESSAGE
  72. #undef WIA_PRINTWINDOWMESSAGE
  73. #endif
  74. #ifdef WIA_ASSERT
  75. #undef WIA_ASSERT
  76. #endif
  77. #ifdef WIA_CHECK_HR
  78. #undef WIA_CHECK_HR
  79. #endif
  80. #ifdef WIA_RETURN_HR
  81. #undef WIA_RETURN_HR
  82. #endif
  83. //
  84. // Turn of name mangling for exported/imported functions
  85. //
  86. extern "C"
  87. {
  88. //
  89. // Exported functions
  90. //
  91. int WINAPI IncrementDebugIndentLevel(void);
  92. int WINAPI DecrementDebugIndentLevel(void);
  93. BOOL WINAPI PrintDebugMessageW( DWORD dwSeverity, DWORD dwModuleMask, COLORREF crForegroundColor, COLORREF crBackgroundColor, LPCWSTR pszModuleName, LPCWSTR pszMsg );
  94. BOOL WINAPI PrintDebugMessageA( DWORD dwSeverity, DWORD dwModuleMask, COLORREF crForegroundColor, COLORREF crBackgroundColor, LPCSTR pszModuleName, LPCSTR pszMsg );
  95. DWORD WINAPI GetDebugMask(void);
  96. DWORD WINAPI SetDebugMask( DWORD dwNewMask );
  97. COLORREF WINAPI AllocateDebugColor(void);
  98. BOOL WINAPI GetStringFromGuidA( const IID *pGuid, LPSTR pszString, int nMaxLen );
  99. BOOL WINAPI GetStringFromGuidW( const IID *pGuid, LPWSTR pszString, int nMaxLen );
  100. VOID WINAPI DoRecordAllocation( LPVOID pv, size_t Size );
  101. VOID WINAPI DoRecordFree( LPVOID pv );
  102. BOOL WINAPI GetStringFromMsgA( UINT uMsg, LPSTR pszString, int nMaxLen );
  103. BOOL WINAPI GetStringFromMsgW( UINT uMsg, LPWSTR pszString, int nMaxLen );
  104. //
  105. // Exported function typedefs
  106. //
  107. typedef int (WINAPI *IncrementDebugIndentLevelProc)(void);
  108. typedef int (WINAPI *DecrementDebugIndentLevelProc)(void);
  109. typedef BOOL (WINAPI *PrintDebugMessageWProc)( DWORD, DWORD, COLORREF, COLORREF, LPCWSTR, LPCWSTR );
  110. typedef BOOL (WINAPI *PrintDebugMessageAProc)( DWORD, DWORD, COLORREF, COLORREF, LPCSTR, LPCSTR );
  111. typedef DWORD (WINAPI *GetDebugMaskProc)(void);
  112. typedef DWORD (WINAPI *SetDebugMaskProc)( DWORD );
  113. typedef COLORREF (WINAPI *AllocateDebugColorProc)(void);
  114. typedef BOOL (WINAPI *GetStringFromGuidAProc)( const IID*, LPSTR, int );
  115. typedef BOOL (WINAPI *GetStringFromGuidWProc)( const IID*, LPWSTR, int );
  116. typedef VOID (WINAPI *DoRecordAllocationProc)( LPVOID pv, size_t Size );
  117. typedef VOID (WINAPI *DoRecordFreeProc)( LPVOID pv );
  118. typedef VOID (WINAPI *DoReportLeaksProc)( LPTSTR );
  119. typedef BOOL (WINAPI *GetStringFromMsgAProc)( UINT uMsg, LPSTR pszString, int nMaxLen );
  120. typedef BOOL (WINAPI *GetStringFromMsgWProc)( UINT uMsg, LPWSTR pszString, int nMaxLen );
  121. } // extern "C"
  122. //
  123. // Names of exported functions
  124. //
  125. #define INCREMENT_DEBUG_INDENT_LEVEL_NAME "IncrementDebugIndentLevel"
  126. #define DECREMENT_DEBUG_INDENT_LEVEL_NAME "DecrementDebugIndentLevel"
  127. #define PRINT_DEBUG_MESSAGE_NAMEW "PrintDebugMessageW"
  128. #define PRINT_DEBUG_MESSAGE_NAMEA "PrintDebugMessageA"
  129. #define GET_DEBUG_MASK_NAME "GetDebugMask"
  130. #define SET_DEBUG_MASK_NAME "SetDebugMask"
  131. #define ALLOCATE_DEBUG_COLOR_NAME "AllocateDebugColor"
  132. #define GET_STRING_FROM_GUID_NAMEA "GetStringFromGuidA"
  133. #define GET_STRING_FROM_GUID_NAMEW "GetStringFromGuidW"
  134. #define DO_RECORD_ALLOCATION "DoRecordAllocation"
  135. #define DO_RECORD_FREE "DoRecordFree"
  136. #define DO_REPORT_LEAKS "DoReportLeaks"
  137. #define GET_STRING_FROM_MSGA "GetStringFromMsgA"
  138. #define GET_STRING_FROM_MSGW "GetStringFromMsgW"
  139. //
  140. // Forced error stuff
  141. //
  142. #define REGSTR_FORCEERR_KEY TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\WIA\\ForceError")
  143. #define REGSTR_ERROR_POINT TEXT("ErrorPoint")
  144. #define REGSTR_ERROR_VALUE TEXT("ErrorValue")
  145. #define HKEY_FORCEERROR HKEY_CURRENT_USER
  146. //
  147. // Name of DLL
  148. //
  149. #define DEBUG_DLL_NAMEW L"wiadebug.dll"
  150. #define DEBUG_DLL_NAMEA "wiadebug.dll"
  151. //
  152. // Path to the section of the registry in which all debug data is stored
  153. //
  154. #define DEBUG_REGISTRY_PATHA "Software\\Microsoft\\Wia\\WiaDebugUi"
  155. #define DEBUG_REGISTRY_PATHW L"Software\\Microsoft\\Wia\\WiaDebugUi"
  156. //
  157. // Path to the section of the registry in which the module flags are stored
  158. //
  159. #define DEBUG_REGISTRY_PATH_FLAGSA "Software\\Microsoft\\Wia\\WiaDebugUi\\ModuleFlags"
  160. #define DEBUG_REGISTRY_PATH_FLAGSW L"Software\\Microsoft\\Wia\\WiaDebugUi\\ModuleFlags"
  161. //
  162. // Registry value names
  163. //
  164. #define DEBUG_REGISTRY_ENABLE_DBGA "EnableTracing"
  165. #define DEBUG_REGISTRY_ENABLE_DBGW L"EnableTracing"
  166. //
  167. // Name of default value. This allows us to turn on all debugging.
  168. //
  169. #define DEBUG_REGISTRY_DEFAULT_FLAGSA "DefaultDebugModuleFlag"
  170. #define DEBUG_REGISTRY_DEFAULT_FLAGSW L"DefaultDebugModuleFlag"
  171. //
  172. // Unicode/ANSI versions
  173. //
  174. #if defined(UNICODE)
  175. typedef PrintDebugMessageWProc PrintDebugMessageProc;
  176. typedef GetStringFromGuidWProc GetStringFromGuidProc;
  177. #define PRINT_DEBUG_MESSAGE_NAME PRINT_DEBUG_MESSAGE_NAMEW
  178. #define DEBUG_DLL_NAME DEBUG_DLL_NAMEW
  179. #define GET_STRING_FROM_GUID_NAME GET_STRING_FROM_GUID_NAMEW
  180. #define DEBUG_REGISTRY_PATH DEBUG_REGISTRY_PATHW
  181. #define DEBUG_REGISTRY_PATH_FLAGS DEBUG_REGISTRY_PATH_FLAGSW
  182. #define DEBUG_REGISTRY_ENABLE_DBG DEBUG_REGISTRY_ENABLE_DBGW
  183. #define DEBUG_REGISTRY_DEFAULT_FLAGS DEBUG_REGISTRY_DEFAULT_FLAGSW
  184. #define GET_STRING_FROM_MSG GET_STRING_FROM_MSGW
  185. #else
  186. typedef PrintDebugMessageAProc PrintDebugMessageProc;
  187. typedef GetStringFromGuidAProc GetStringFromGuidProc;
  188. #define PRINT_DEBUG_MESSAGE_NAME PRINT_DEBUG_MESSAGE_NAMEA
  189. #define DEBUG_DLL_NAME DEBUG_DLL_NAMEA
  190. #define GET_STRING_FROM_GUID_NAME GET_STRING_FROM_GUID_NAMEA
  191. #define DEBUG_REGISTRY_PATH DEBUG_REGISTRY_PATHA
  192. #define DEBUG_REGISTRY_PATH_FLAGS DEBUG_REGISTRY_PATH_FLAGSA
  193. #define DEBUG_REGISTRY_ENABLE_DBG DEBUG_REGISTRY_ENABLE_DBGA
  194. #define DEBUG_REGISTRY_DEFAULT_FLAGS DEBUG_REGISTRY_DEFAULT_FLAGSA
  195. #define GET_STRING_FROM_MSG GET_STRING_FROM_MSGA
  196. #endif
  197. //
  198. // Color used to specify use default
  199. //
  200. #define DEFAULT_DEBUG_COLOR static_cast<COLORREF>(0xFFFFFFFF)
  201. //
  202. // Default colors
  203. //
  204. #define ERROR_FOREGROUND_COLOR RGB(0x00,0x00,0x00)
  205. #define ERROR_BACKGROUND_COLOR RGB(0xFF,0x7F,0x7F)
  206. #define WARNING_FOREGROUND_COLOR RGB(0x00,0x00,0x00)
  207. #define WARNING_BACKGROUND_COLOR RGB(0xFF,0xFF,0x7F)
  208. //
  209. // Kernel object names
  210. //
  211. #define WIADEBUG_MEMORYMAPPED_FILENAME TEXT("WiaDebugMemoryMappedFile")
  212. #define WIADEBUG_MEMORYMAPPED_MUTEXNAME TEXT("WiaDebugMemoryMappedMutex")
  213. #define WIADEBUG_DEBUGCLIENT_MUTEXNAME TEXT("WiaDebugDebugClientMutex")
  214. #define NUMBER_OF_DEBUG_COLORS 8
  215. //
  216. // The data stored in the shared memory section
  217. //
  218. //
  219. // Make sure it it is byte aligned
  220. //
  221. #include <pshpack1.h>
  222. struct CSystemGlobalData
  223. {
  224. //
  225. // Global debugging switch
  226. //
  227. DWORD nAllowDebugMessages;
  228. //
  229. // Registered debug window. We will cast it to an HWND (which should be safe under Win64)
  230. //
  231. DWORD hwndDebug;
  232. //
  233. // Color information
  234. //
  235. COLORREF crDebugColors[NUMBER_OF_DEBUG_COLORS];
  236. DWORD nCurrentColor;
  237. };
  238. #include <poppack.h>
  239. //
  240. // Class for safely manipulating the global data
  241. //
  242. class CGlobalDebugState
  243. {
  244. private:
  245. HANDLE m_hSystemDataMutex;
  246. HANDLE m_hMemoryMappedFile;
  247. CSystemGlobalData *m_pSystemGlobalData;
  248. private:
  249. //
  250. // No implementation
  251. //
  252. CGlobalDebugState( const CGlobalDebugState & );
  253. CGlobalDebugState &operator=( const CGlobalDebugState & );
  254. private:
  255. CSystemGlobalData *Lock(void);
  256. void Release(void);
  257. public:
  258. CGlobalDebugState(void);
  259. void Destroy(void);
  260. ~CGlobalDebugState(void);
  261. bool IsValid(void) const;
  262. DWORD AllowDebugMessages(void);
  263. DWORD AllowDebugMessages( DWORD nAllowDebugMessages );
  264. DWORD AllocateNextColorIndex(void);
  265. COLORREF GetColorFromIndex( DWORD nIndex );
  266. bool SendDebugWindowMessage( UINT, WPARAM, LPARAM );
  267. bool DebugWindow( HWND hWnd );
  268. HWND DebugWindow(void);
  269. };
  270. //
  271. // The WM_COPYDATA message will have this ID when it is sent with a debug string
  272. //
  273. #define COPYDATA_DEBUG_MESSAGE_ID 0xDEADBEEF
  274. //
  275. // The data stored in the shared memory section
  276. //
  277. //
  278. // Make sure this data is byte aligned
  279. //
  280. #include <pshpack1.h>
  281. struct CDebugStringMessageData
  282. {
  283. COLORREF crBackground;
  284. COLORREF crForeground;
  285. BOOL bUnicode;
  286. CHAR szString[2048];
  287. };
  288. #include <poppack.h>
  289. ///////////////////////////////////////////////////////////////////////////////
  290. // Main debug class. Mostly used though macros.
  291. ///////////////////////////////////////////////////////////////////////////////
  292. class CWiaDebugClient
  293. {
  294. public:
  295. mutable CSimpleCriticalSection m_CriticalSection;
  296. private:
  297. HINSTANCE m_hDebugModule;
  298. HINSTANCE m_hCurrentModuleInstance;
  299. IncrementDebugIndentLevelProc m_pfnIncrementDebugIndentLevel;
  300. DecrementDebugIndentLevelProc m_pfnDecrementDebugIndentLevel;
  301. PrintDebugMessageWProc m_pfnPrintDebugMessageW;
  302. PrintDebugMessageAProc m_pfnPrintDebugMessageA;
  303. GetDebugMaskProc m_pfnGetDebugMask;
  304. SetDebugMaskProc m_pfnSetDebugMask;
  305. AllocateDebugColorProc m_pfnAllocateDebugColor;
  306. GetStringFromGuidAProc m_pfnGetStringFromGuidA;
  307. GetStringFromGuidWProc m_pfnGetStringFromGuidW;
  308. DoRecordAllocationProc m_pfnDoRecordAllocation;
  309. DoRecordFreeProc m_pfnDoRecordFree;
  310. DoReportLeaksProc m_pfnDoReportLeaks;
  311. GetStringFromMsgAProc m_pfnGetStringFromMsgA;
  312. GetStringFromMsgWProc m_pfnGetStringFromMsgW;
  313. CHAR m_szModuleNameA[MAX_PATH];
  314. WCHAR m_szModuleNameW[MAX_PATH];
  315. COLORREF m_crForegroundColor;
  316. DWORD m_dwModuleDebugMask;
  317. bool m_bHaveModuleInformation;
  318. bool m_bDebugLibLoadAttempted;
  319. public:
  320. //
  321. // Actual constructor and destructor
  322. //
  323. CWiaDebugClient(void);
  324. ~CWiaDebugClient(void);
  325. private:
  326. //
  327. // No implementation
  328. //
  329. CWiaDebugClient( const CWiaDebugClient & );
  330. CWiaDebugClient &operator=( const CWiaDebugClient & );
  331. private:
  332. bool LoadWiaDebugExports();
  333. bool InitializeModuleInfo();
  334. LPTSTR GetJustTheFileName( LPCTSTR pszPath, LPTSTR pszFileName, int nMaxLen );
  335. public:
  336. void SetInstance( HINSTANCE hInstance );
  337. bool Initialize();
  338. void Destroy();
  339. bool IsInitialized();
  340. DWORD SetDebugMask( DWORD dwNewMask );
  341. DWORD GetDebugMask(void);
  342. int IncrementIndentLevel();
  343. int DecrementIndentLevel();
  344. void RecordAllocation( LPVOID pv, size_t Size );
  345. void RecordFree( LPVOID pv );
  346. void ReportLeaks( void );
  347. inline void * __cdecl operator new(size_t size, UINT uNothing )
  348. {
  349. if (0 == size)
  350. {
  351. return NULL;
  352. }
  353. PBYTE pBuf = size ? (PBYTE)LocalAlloc(LPTR, size) : NULL;
  354. return (void *)pBuf;
  355. }
  356. inline void __cdecl operator delete(void *ptr)
  357. {
  358. if (ptr)
  359. {
  360. LocalFree(ptr);
  361. }
  362. }
  363. //
  364. // Unicode versions
  365. //
  366. void PrintWarningMessage( LPCWSTR pszFmt, ... );
  367. void PrintErrorMessage( LPCWSTR pszFmt, ... );
  368. void PrintTraceMessage( LPCWSTR pszFmt, ... );
  369. void PrintHResult( HRESULT hr, LPCWSTR pszFmt, ... );
  370. void PrintGuid( const IID &guid, LPCWSTR pszFmt, ... );
  371. void PrintMessage( DWORD dwSeverity, COLORREF crForegroundColor, COLORREF crBackgroundColor, LPCWSTR pszFmt, ... );
  372. void PrintWindowMessage( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LPCWSTR pszMessage=NULL );
  373. //
  374. // Ansi versions
  375. //
  376. void PrintWarningMessage( LPCSTR pszFmt, ... );
  377. void PrintErrorMessage( LPCSTR pszFmt, ... );
  378. void PrintTraceMessage( LPCSTR pszFmt, ... );
  379. void PrintHResult( HRESULT hr, LPCSTR pszFmt, ... );
  380. void PrintGuid( const IID &guid, LPCSTR pszFmt, ... );
  381. void PrintMessage( DWORD dwSeverity, COLORREF crForegroundColor, COLORREF crBackgroundColor, LPCSTR pszFmt, ... );
  382. void PrintWindowMessage( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LPCSTR pszMessage=NULL );
  383. static DWORD GetForceFailurePoint( LPCTSTR pszProgramName );
  384. static HRESULT GetForceFailureValue( LPCTSTR pszProgramName, bool bPrintWarning=false );
  385. static void SetForceFailurePoint( LPCTSTR pszProgramName, DWORD dwErrorPoint );
  386. static void SetForceFailureValue( LPCTSTR pszProgramName, HRESULT hr );
  387. };
  388. ///////////////////////////////////////////////////////////////////////////////
  389. // A bunch of useful "auto" classes. Mostly used though macros.
  390. ///////////////////////////////////////////////////////////////////////////////
  391. class CPushTraceMask
  392. {
  393. private:
  394. DWORD m_dwOldMask;
  395. private:
  396. // Not implemented
  397. CPushTraceMask(void);
  398. CPushTraceMask( const CPushTraceMask & );
  399. CPushTraceMask &operator=( const CPushTraceMask & );
  400. public:
  401. CPushTraceMask( DWORD dwTraceMask );
  402. ~CPushTraceMask(void);
  403. };
  404. class CPushIndentLevel
  405. {
  406. private:
  407. int m_nIndentLevel;
  408. private:
  409. //
  410. // Not implemented
  411. //
  412. CPushIndentLevel(void);
  413. CPushIndentLevel( const CPushIndentLevel & );
  414. CPushIndentLevel &operator=( const CPushIndentLevel & );
  415. public:
  416. CPushIndentLevel( LPCTSTR pszFmt, ... );
  417. ~CPushIndentLevel(void);
  418. };
  419. class CPushTraceMaskAndIndentLevel
  420. {
  421. private:
  422. int m_nIndentLevel;
  423. DWORD m_dwOldMask;
  424. private:
  425. //
  426. // Not implemented
  427. //
  428. CPushTraceMaskAndIndentLevel( const CPushTraceMaskAndIndentLevel & );
  429. CPushTraceMaskAndIndentLevel &operator=( const CPushTraceMaskAndIndentLevel & );
  430. public:
  431. CPushTraceMaskAndIndentLevel( DWORD dwTraceMask, LPCTSTR pszFmt, ... );
  432. ~CPushTraceMaskAndIndentLevel(void);
  433. };
  434. ///////////////////////////////////////////////////////////////////////////////
  435. // This is debug-only stuff
  436. ///////////////////////////////////////////////////////////////////////////////
  437. #if defined(DBG) || defined(_DEBUG)
  438. extern CWiaDebugClient g_TheDebugClient;
  439. #define WIA_DEBUG_CREATE(hInstance) g_TheDebugClient.SetInstance(hInstance)
  440. #define WIA_DEBUG_DESTROY()
  441. #define WIA_PUSH_TRACE_MASK(__x) CPushTraceMask __pushTraceMask( __x )
  442. //
  443. // This version does support varargs
  444. //
  445. #define WIA_PUSH_FUNCTION(__x) CPushIndentLevel __pushIndentLevel __x
  446. //
  447. // This version doesn't support varargs
  448. //
  449. #define WIA_PUSHFUNCTION(__x) CPushIndentLevel __pushIndentLevel(TEXT("%s"),__x)
  450. #define WIA_PUSH_FUNCTION_MASK(__x) CPushTraceMaskAndIndentLevel __PushTraceMaskAndIndentLevel __x
  451. #define WIA_TRACE(args)\
  452. do\
  453. {\
  454. g_TheDebugClient.PrintTraceMessage args;\
  455. } while(false)
  456. #define WIA_ERROR(args)\
  457. do\
  458. {\
  459. g_TheDebugClient.PrintErrorMessage args;\
  460. } while (false)
  461. #define WIA_WARNING(args)\
  462. do\
  463. {\
  464. g_TheDebugClient.PrintWarningMessage args;\
  465. } while (false)
  466. #define WIA_PRINTHRESULT(args)\
  467. do\
  468. {\
  469. g_TheDebugClient.PrintHResult args;\
  470. } while (false)
  471. #define WIA_PRINTGUID(args)\
  472. do\
  473. {\
  474. g_TheDebugClient.PrintGuid args;\
  475. } while (false)
  476. #define WIA_PRINTWINDOWMESSAGE(args)\
  477. do\
  478. {\
  479. g_TheDebugClient.PrintWindowMessage args;\
  480. } while (false)
  481. #define WIA_ASSERT(x)\
  482. do\
  483. {\
  484. if (!(x))\
  485. {\
  486. WIA_ERROR((TEXT("WIA ASSERTION FAILED: %hs(%d): %hs"),__FILE__,__LINE__,#x));\
  487. DebugBreak();\
  488. }\
  489. }\
  490. while (false)
  491. #define WIA_CHECK_HR(hr,fnc)\
  492. if (FAILED(hr))\
  493. {\
  494. WIA_PRINTHRESULT((hr,"%s failed", fnc));\
  495. }
  496. #define WIA_RETURN_HR(hr)\
  497. if (FAILED(hr))\
  498. {\
  499. WIA_PRINTHRESULT((hr,"Returning WiaError"));\
  500. }\
  501. return hr
  502. #define WIA_RECORD_ALLOC(pv,size)\
  503. do\
  504. {\
  505. g_TheDebugClient.RecordAllocation(pv,size);\
  506. } while (false)
  507. #define WIA_RECORD_FREE(pv)\
  508. do\
  509. {\
  510. g_TheDebugClient.RecordFree(pv);\
  511. } while (false)
  512. #define WIA_REPORT_LEAKS()\
  513. do\
  514. {\
  515. g_TheDebugClient.ReportLeaks();\
  516. } while (false)
  517. #define WIA_FORCE_ERROR(DbgProgram,ForceFlag,RetailValue) ((CWiaDebugClient::GetForceFailurePoint(DbgProgram) == (ForceFlag)) ? (CWiaDebugClient::GetForceFailureValue(DbgProgram,true)) : (RetailValue))
  518. #else // !defined(DBG) || !defined(_DEBUG)
  519. #define WIA_DEBUG_CREATE(hInstance)
  520. #define WIA_DEBUG_DESTROY()
  521. #define WIA_SET_TRACE_MASK(__x)
  522. #define WIA_PUSHFUNCTION(__x)
  523. #define WIA_PUSH_FUNCTION(__x)
  524. #define WIA_PUSH_FUNCTION_MASK(__x)
  525. #define WIA_TRACE(args)
  526. #define WIA_WARNING(args)
  527. #define WIA_ERROR(args)
  528. #define WIA_PRINTHRESULT(args)
  529. #define WIA_PRINTGUID(args)
  530. #define WIA_PRINTWINDOWMESSAGE(args)
  531. #define WIA_ASSERT(x)
  532. #define WIA_CHECK_HR(hr,fnc)
  533. #define WIA_RETURN_HR(hr) return hr
  534. #define WIA_RECORD_ALLOC(pv,size)
  535. #define WIA_RECORD_FREE(pv)
  536. #define WIA_REPORT_LEAKS()
  537. #define WIA_FORCE_ERROR(DbgProgram,ForceFlag,RetailValue) (RetailValue)
  538. #endif // defined(DBG) || defined(_DEBUG)
  539. #endif //__WIADEBUG_H_INCLUDED