Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

707 lines
21 KiB

  1. //
  2. // Copyright (c) Microsoft Corporation 1993-1995
  3. //
  4. // common.h
  5. //
  6. // Declares common and useful data structures, macros and functions.
  7. // These items are broken down into the following sections. Defining
  8. // the associated flags will inhibit definition of the indicated
  9. // items.
  10. //
  11. // NORTL - run-time library functions
  12. // NOBASICS - basic macros
  13. // NOMEM - memory management, dynamic array functions
  14. // NODA - dynamic array functions
  15. // NOSHAREDHEAP - shared heap functions
  16. // NOFILEINFO - FileInfo functions
  17. // NOCOLOR - helper macros to derive COLOR_ values from state
  18. // NODRAWTEXT - enhanced version of DrawText
  19. // NODIALOGHELPER - dialog helper functions
  20. // NOMESSAGESTRING - construct message string functions
  21. // NOSTRING - string functions
  22. // NOPATH - path whacking functions
  23. // NODEBUGHELP - debug routines
  24. // NOSYNC - synchronization (critical sections, etc.)
  25. // NOPROFILE - profile (.ini) support functions
  26. //
  27. // Optional defines are:
  28. //
  29. // WANT_SHELL_SUPPORT - include SH* function support
  30. // SZ_MODULE - debug string prepended to debug spew
  31. // SHARED_DLL - DLL is in shared memory (may require
  32. // per-instance data)
  33. // SZ_DEBUGSECTION - .ini section name for debug options
  34. // SZ_DEBUGINI - .ini name for debug options
  35. //
  36. // This is the "master" header. The associated files are:
  37. //
  38. // common.c
  39. // path.c
  40. // mem.c, mem.h
  41. // profile.c
  42. //
  43. //
  44. // History:
  45. // 04-26-95 ScottH Transferred from Briefcase code
  46. // Added controlling defines
  47. //
  48. #ifndef __COMMON_H__
  49. #define __COMMON_H__
  50. #ifdef RC_INVOKED
  51. // Turn off a bunch of stuff to ensure that RC files compile OK
  52. #define NOMEM
  53. #define NOCOLOR
  54. #define NODRAWTEXT
  55. #define NODIALOGHELPER
  56. #define NOMESSAGESTRING
  57. #define NOSTRING
  58. #define NODEBUGHELP
  59. #define NODA
  60. #define NOSYNC
  61. #define NOPROFILE
  62. #endif // RC_INVOKED
  63. #ifdef _INC_OLE
  64. #define WANT_OLE_SUPPORT
  65. #endif
  66. // Check for any conflicting defines...
  67. #if !defined(WANT_SHELL_SUPPORT) && !defined(NOFILEINFO)
  68. #pragma message("FileInfo routines need WANT_SHELL_SUPPORT. Not providing FileInfo routines.")
  69. #define NOFILEINFO
  70. #endif
  71. #if !defined(NOFILEINFO) && defined(NOMEM)
  72. #pragma message("FileInfo routines need NOMEM undefined. Overriding.")
  73. #undef NOMEM
  74. #endif
  75. #if !defined(NOFILEINFO) && defined(NOMESSAGESTRING)
  76. #pragma message("FileInfo routines need NOMESSAGESTRING undefined. Overriding.")
  77. #undef NOMESSAGESTRING
  78. #endif
  79. #if !defined(NOFILEINFO) && defined(NOSTRING)
  80. #pragma message("FileInfo routines need NOSTRING undefined. Overriding.")
  81. #undef NOSTRING
  82. #endif
  83. #if !defined(NOMESSAGESTRING) && defined(NOMEM)
  84. #pragma message("ConstructMessage routines need NOMEM undefined. Overriding.")
  85. #undef NOMEM
  86. #endif
  87. #if !defined(NOPATH) && defined(NOSTRING)
  88. #pragma message("Path routines need NOSTRING undefined. Overriding.")
  89. #undef NOSTRING
  90. #endif
  91. #if !defined(NODA) && defined(NOMEM)
  92. #pragma message("Dynamic Array routines need NOMEM undefined. Overriding.")
  93. #undef NOMEM
  94. #endif
  95. #if !defined(NOSHAREDHEAP) && defined(NOMEM)
  96. #pragma message("Shared memory routines need NOMEM undefined. Overriding.")
  97. #undef NOMEM
  98. #endif
  99. #if !defined(NOPROFILE) && defined(NODEBUGHELP)
  100. #pragma message("Debug profiling routines need NODEBUGHELP undefined. Overriding.")
  101. #undef NODEBUGHELP
  102. #endif
  103. // Other include files...
  104. #if !defined(NOFILEINFO) && !defined(_SHLOBJ_H_)
  105. #include <shlobj.h>
  106. #endif
  107. //
  108. // Basics
  109. //
  110. #ifndef NOBASICS
  111. #define Unref(x) x
  112. #ifdef DEBUG
  113. #define INLINE
  114. #define DEBUG_CODE(x) x
  115. #else
  116. #define INLINE __inline
  117. #define DEBUG_CODE(x)
  118. #endif
  119. // General flag macros
  120. //
  121. #define SetFlag(obj, f) (obj |= (f))
  122. #define ToggleFlag(obj, f) (obj ^= (f))
  123. #define ClearFlag(obj, f) (obj &= ~(f))
  124. #define IsFlagSet(obj, f) (BOOL)(((obj) & (f)) == (f))
  125. #define IsFlagClear(obj, f) (BOOL)(((obj) & (f)) != (f))
  126. #define InRange(id, idFirst, idLast) ((UINT)(id-idFirst) <= (UINT)(idLast-idFirst))
  127. // Standard buffer lengths
  128. //
  129. #define MAX_BUF 260
  130. #define MAX_BUF_MSG 520
  131. #define MAX_BUF_MED 64
  132. #define MAX_BUF_SHORT 32
  133. #define NULL_CHAR '\0'
  134. #define CCH_NUL (sizeof(TCHAR))
  135. #define ARRAY_ELEMENTS(rg) (sizeof(rg) / sizeof((rg)[0]))
  136. // Comparison return values
  137. //
  138. #define CMP_GREATER 1
  139. #define CMP_LESSER (-1)
  140. #define CMP_EQUAL 0
  141. // Count of characters to count of bytes
  142. //
  143. #define CbFromCch(cch) ((cch)*sizeof(TCHAR))
  144. // Swap values
  145. //
  146. #define Swap(a, b) ((DWORD)(a) ^= (DWORD)(b) ^= (DWORD)(a) ^= (DWORD)(b))
  147. // 64-bit macros
  148. //
  149. #define HIDWORD(_qw) (DWORD)((_qw)>>32)
  150. #define LODWORD(_qw) (DWORD)(_qw)
  151. // Calling declarations
  152. //
  153. #define PUBLIC FAR PASCAL
  154. #define CPUBLIC FAR _cdecl
  155. #define PRIVATE NEAR PASCAL
  156. // Data segments
  157. //
  158. #define DATASEG_READONLY ".text"
  159. #define DATASEG_PERINSTANCE ".instanc"
  160. #define DATASEG_SHARED ".data"
  161. // Range of resource ID indexes are 0x000 - 0x7ff
  162. #define IDS_BASE 0x1000
  163. #define IDS_ERR_BASE (IDS_BASE + 0x0000)
  164. #define IDS_OOM_BASE (IDS_BASE + 0x0800)
  165. #define IDS_MSG_BASE (IDS_BASE + 0x1000)
  166. #define IDS_RANDO_BASE (IDS_BASE + 0x1800)
  167. #define IDS_COMMON_BASE (IDS_BASE + 0x2000)
  168. #ifndef DECLARE_STANDARD_TYPES
  169. // For a type "FOO", define the standard derived types PFOO, CFOO, and PCFOO.
  170. //
  171. #define DECLARE_STANDARD_TYPES(type) typedef type *P##type; \
  172. typedef const type C##type; \
  173. typedef const type *PC##type;
  174. #endif
  175. // Zero-initialize data-item
  176. //
  177. #define ZeroInit(pobj, type) MyZeroMemory(pobj, sizeof(type))
  178. // Copy chunk of memory
  179. //
  180. #define BltByte(pdest, psrc, cb) MyMoveMemory(pdest, psrc, cb)
  181. #endif // NOBASICS
  182. //
  183. // Run-time library replacements
  184. //
  185. #ifdef NORTL
  186. // (implemented privately)
  187. LPSTR PUBLIC lmemmove(LPSTR dst, LPCSTR src, int count);
  188. LPSTR PUBLIC lmemset(LPSTR dst, char val, UINT count);
  189. #define MyZeroMemory(p, cb) lmemset((LPSTR)(p), 0, cb)
  190. #define MyMoveMemory(pdest, psrc, cb) lmemmove((LPSTR)(pdest), (LPCSTR)(psrc), cb)
  191. #else // NORTL
  192. #define MyZeroMemory ZeroMemory
  193. #define MyMoveMemory MoveMemory
  194. #endif // NORTL
  195. //
  196. // Memory and dynamic array functions
  197. //
  198. #ifndef NOMEM
  199. #include "mem.h"
  200. #endif // NOMEM
  201. //
  202. // Message string helpers
  203. //
  204. #ifndef NOMESSAGESTRING
  205. LPSTR PUBLIC ConstructVMessageString(HINSTANCE hinst, LPCSTR pszMsg, va_list *ArgList);
  206. BOOL PUBLIC ConstructMessage(LPSTR * ppsz, HINSTANCE hinst, LPCSTR pszMsg, ...);
  207. #define SzFromIDS(hinst, ids, pszBuf, cchBuf) (LoadString(hinst, ids, pszBuf, cchBuf), pszBuf)
  208. int PUBLIC MsgBox(HINSTANCE hinst, HWND hwndOwner, LPCSTR pszText, LPCSTR pszCaption, HICON hicon, DWORD dwStyle, ...);
  209. // Additional MB_ flags
  210. #define MB_WARNING (MB_OK | MB_ICONWARNING)
  211. #define MB_INFO (MB_OK | MB_ICONINFORMATION)
  212. #define MB_ERROR (MB_OK | MB_ICONERROR)
  213. #define MB_QUESTION (MB_YESNO | MB_ICONQUESTION)
  214. #endif // NOMESSAGESTRING
  215. //
  216. // String functions
  217. //
  218. #ifndef NOSTRING
  219. int PUBLIC AnsiToInt(LPCSTR pszString);
  220. int PUBLIC lstrnicmp(LPCSTR psz1, LPCSTR psz2, UINT count);
  221. LPSTR PUBLIC AnsiChr(LPCSTR psz, WORD wMatch);
  222. #define IsSzEqual(sz1, sz2) (BOOL)(lstrcmpi(sz1, sz2) == 0)
  223. #define IsSzEqualC(sz1, sz2) (BOOL)(lstrcmp(sz1, sz2) == 0)
  224. #endif // NOSTRING
  225. //
  226. // FileInfo functions
  227. //
  228. #ifndef NOFILEINFO
  229. // FileInfo struct that contains file time/size info
  230. //
  231. typedef struct _FileInfo
  232. {
  233. HICON hicon;
  234. FILETIME ftMod;
  235. DWORD dwSize; // size of the file
  236. DWORD dwAttributes; // attributes
  237. LPARAM lParam;
  238. LPSTR pszDisplayName; // points to the display name
  239. char szPath[1];
  240. } FileInfo;
  241. #define FIGetSize(pfi) ((pfi)->dwSize)
  242. #define FIGetPath(pfi) ((pfi)->szPath)
  243. #define FIGetDisplayName(pfi) ((pfi)->pszDisplayName)
  244. #define FIGetAttributes(pfi) ((pfi)->dwAttributes)
  245. #define FIIsFolder(pfi) (IsFlagSet((pfi)->dwAttributes, SFGAO_FOLDER))
  246. // Flags for FICreate
  247. #define FIF_DEFAULT 0x0000
  248. #define FIF_ICON 0x0001
  249. #define FIF_DONTTOUCH 0x0002
  250. #define FIF_FOLDER 0x0004
  251. HRESULT PUBLIC FICreate(LPCSTR pszPath, FileInfo ** ppfi, UINT uFlags);
  252. BOOL PUBLIC FISetPath(FileInfo ** ppfi, LPCSTR pszPathNew, UINT uFlags);
  253. BOOL PUBLIC FIGetInfoString(FileInfo * pfi, LPSTR pszBuf, int cchBuf);
  254. void PUBLIC FIFree(FileInfo * pfi);
  255. void PUBLIC FileTimeToDateTimeString(LPFILETIME pft, LPSTR pszBuf, int cchBuf);
  256. // Resource string IDs
  257. #define IDS_BYTES (IDS_COMMON_BASE + 0x000)
  258. #define IDS_ORDERKB (IDS_COMMON_BASE + 0x001)
  259. #define IDS_ORDERMB (IDS_COMMON_BASE + 0x002)
  260. #define IDS_ORDERGB (IDS_COMMON_BASE + 0x003)
  261. #define IDS_ORDERTB (IDS_COMMON_BASE + 0x004)
  262. #define IDS_DATESIZELINE (IDS_COMMON_BASE + 0x005)
  263. #endif // NOFILEINFO
  264. //
  265. // Color-from-owner-draw-state macros
  266. //
  267. #ifndef NOCOLOR
  268. #define ColorText(nState) (((nState) & ODS_SELECTED) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT)
  269. #define ColorBk(nState) (((nState) & ODS_SELECTED) ? COLOR_HIGHLIGHT : COLOR_WINDOW)
  270. #define ColorMenuText(nState) (((nState) & ODS_SELECTED) ? COLOR_HIGHLIGHTTEXT : COLOR_MENUTEXT)
  271. #define ColorMenuBk(nState) (((nState) & ODS_SELECTED) ? COLOR_HIGHLIGHT : COLOR_MENU)
  272. #define GetImageDrawStyle(nState) (((nState) & ODS_SELECTED) ? ILD_SELECTED : ILD_NORMAL)
  273. #endif // NOCOLOR
  274. //
  275. // Dialog helper functions
  276. //
  277. #ifndef NODIALOGHELPER
  278. // Sets the dialog handle in the given data struct on first
  279. // message that the dialog gets (WM_SETFONT).
  280. //
  281. #define SetDlgHandle(hwnd, msg, lp) if((msg)==WM_SETFONT) (lp)->hdlg=(hwnd);
  282. int PUBLIC DoModal (HWND hwndParent, DLGPROC lpfnDlgProc, UINT uID, LPARAM lParam);
  283. VOID PUBLIC SetRectFromExtent(HDC hdc, LPRECT lprc, LPCSTR lpcsz);
  284. #endif // NODIALOGHELPER
  285. //
  286. // Enhanced form of DrawText()
  287. //
  288. #ifndef NODRAWTEXT
  289. // Flags for MyDrawText()
  290. #define MDT_DRAWTEXT 0x00000001
  291. #define MDT_ELLIPSES 0x00000002
  292. #define MDT_LINK 0x00000004
  293. #define MDT_SELECTED 0x00000008
  294. #define MDT_DESELECTED 0x00000010
  295. #define MDT_DEPRESSED 0x00000020
  296. #define MDT_EXTRAMARGIN 0x00000040
  297. #define MDT_TRANSPARENT 0x00000080
  298. #define MDT_LEFT 0x00000100
  299. #define MDT_RIGHT 0x00000200
  300. #define MDT_CENTER 0x00000400
  301. #define MDT_VCENTER 0x00000800
  302. #define MDT_CLIPPED 0x00001000
  303. #ifndef CLR_DEFAULT // (usually defined in commctrl.h)
  304. #define CLR_DEFAULT 0xFF000000L
  305. #endif
  306. void PUBLIC MyDrawText(HDC hdc, LPCSTR pszText, RECT FAR* prc, UINT flags, int cyChar, int cxEllipses, COLORREF clrText, COLORREF clrTextBk);
  307. void PUBLIC GetCommonMetrics(WPARAM wParam);
  308. extern int g_cxLabelMargin;
  309. extern int g_cxBorder;
  310. extern int g_cyBorder;
  311. extern COLORREF g_clrHighlightText;
  312. extern COLORREF g_clrHighlight;
  313. extern COLORREF g_clrWindowText;
  314. extern COLORREF g_clrWindow;
  315. extern HBRUSH g_hbrHighlight;
  316. extern HBRUSH g_hbrWindow;
  317. #endif // NODRAWTEXT
  318. //
  319. // Synchronization
  320. //
  321. #ifndef NOSYNC
  322. #define INIT_EXCLUSIVE() Common_InitExclusive();
  323. #define ENTER_EXCLUSIVE() Common_EnterExclusive();
  324. #define LEAVE_EXCLUSIVE() Common_LeaveExclusive();
  325. #define ASSERT_EXCLUSIVE() ASSERT(0 < g_cRefCommonCS)
  326. #define ASSERT_NOT_EXCLUSIVE() ASSERT(0 == g_cRefCommonCS)
  327. extern UINT g_cRefCommonCS;
  328. void PUBLIC Common_InitExclusive(void);
  329. void PUBLIC Common_EnterExclusive(void);
  330. void PUBLIC Common_LeaveExclusive(void);
  331. // Safe version of MsgWaitMultipleObjects()
  332. //
  333. DWORD PUBLIC MsgWaitObjectsSendMessage(DWORD cObjects, LPHANDLE phObjects, DWORD dwTimeout);
  334. #else // NOSYNC
  335. #define INIT_EXCLUSIVE()
  336. #define ENTER_EXCLUSIVE()
  337. #define LEAVE_EXCLUSIVE()
  338. #define ASSERT_EXCLUSIVE()
  339. #define ASSERT_NOT_EXCLUSIVE()
  340. #endif // NOSYNC
  341. //
  342. // Path whacking functions
  343. //
  344. #ifndef NOPATH
  345. BOOL PUBLIC WPPathIsRoot(LPCSTR pszPath);
  346. BOOL PUBLIC WPPathIsUNC(LPCSTR pszPath);
  347. LPSTR PUBLIC WPRemoveBackslash(LPSTR lpszPath);
  348. LPSTR PUBLIC WPRemoveExt(LPCSTR pszPath, LPSTR pszBuf);
  349. LPSTR PUBLIC WPFindNextComponentI(LPCSTR lpszPath);
  350. void PUBLIC WPMakePresentable(LPSTR pszPath);
  351. BOOL PUBLIC WPPathsTooLong(LPCSTR pszFolder, LPCSTR pszName);
  352. void PUBLIC WPCanonicalize(LPCSTR pszPath, LPSTR pszBuf);
  353. LPSTR PUBLIC WPFindFileName(LPCSTR pPath);
  354. BOOL PUBLIC WPPathExists(LPCSTR pszPath);
  355. LPCSTR PUBLIC WPFindEndOfRoot(LPCSTR pszPath);
  356. BOOL PUBLIC WPPathIsPrefix(LPCSTR lpcszPath1, LPCSTR lpcszPath2);
  357. #ifdef WANT_SHELL_SUPPORT
  358. LPSTR PUBLIC WPGetDisplayName(LPCSTR pszPath, LPSTR pszBuf);
  359. // Events for WPNotifyShell
  360. typedef enum _notifyshellevent
  361. {
  362. NSE_CREATE = 0,
  363. NSE_MKDIR,
  364. NSE_UPDATEITEM,
  365. NSE_UPDATEDIR
  366. } NOTIFYSHELLEVENT;
  367. void PUBLIC WPNotifyShell(LPCSTR pszPath, NOTIFYSHELLEVENT nse, BOOL bDoNow);
  368. #endif
  369. #endif // NOPATH
  370. //
  371. // Profile (.ini) support functions
  372. //
  373. // (Currently all profile functions are for DEBUG use only
  374. #ifndef DEBUG
  375. #define NOPROFILE
  376. #endif
  377. #ifndef NOPROFILE
  378. #ifndef SZ_DEBUGINI
  379. #pragma message("SZ_DEBUGINI is not #defined. Assuming \"rover.ini\".")
  380. #define SZ_DEBUGINI "rover.ini"
  381. #endif
  382. #ifndef SZ_DEBUGSECTION
  383. #pragma message("SZ_DEBUGSECTION is not #defined. Assuming [Debug].")
  384. #define SZ_DEBUGSECTION "Debug"
  385. #endif
  386. BOOL PUBLIC ProcessIniFile(void);
  387. #else // NOPROFILE
  388. #define ProcessIniFile()
  389. #endif // NOPROFILE
  390. //
  391. // Debug helper functions
  392. //
  393. // Break flags
  394. #define BF_ONTHREADATT 0x00000001
  395. #define BF_ONTHREADDET 0x00000002
  396. #define BF_ONPROCESSATT 0x00000004
  397. #define BF_ONPROCESSDET 0x00000008
  398. #define BF_ONVALIDATE 0x00000010
  399. #define BF_ONOPEN 0x00000020
  400. #define BF_ONCLOSE 0x00000040
  401. // Trace flags
  402. #define TF_ALWAYS 0x00000000
  403. #define TF_WARNING 0x00000001
  404. #define TF_ERROR 0x00000002
  405. #define TF_GENERAL 0x00000004 // Standard messages
  406. #define TF_FUNC 0x00000008 // Trace function calls
  407. // (Upper 16 bits reserved for user)
  408. #if defined(NODEBUGHELP) || !defined(DEBUG)
  409. #define DEBUG_BREAK 1 ? (void)0 : (void)
  410. #define ASSERT(f)
  411. #define EVAL(f) (f)
  412. #define ASSERT_MSG 1 ? (void)0 : (void)
  413. #define DEBUG_MSG 1 ? (void)0 : (void)
  414. #define TRACE_MSG 1 ? (void)0 : (void)
  415. #define VERIFY_SZ(f, szFmt, x) (f)
  416. #define VERIFY_SZ2(f, szFmt, x1, x2) (f)
  417. #define DBG_ENTER(fn)
  418. #define DBG_ENTER_SZ(fn, sz)
  419. #define DBG_ENTER_DTOBJ(fn, pdtobj, sz)
  420. #define DBG_ENTER_RIID(fn, riid)
  421. #define DBG_EXIT(fn)
  422. #define DBG_EXIT_TYPE(fn, dw, pfnStrFromType)
  423. #define DBG_EXIT_INT(fn, n)
  424. #define DBG_EXIT_BOOL(fn, b)
  425. #define DBG_EXIT_US(fn, us)
  426. #define DBG_EXIT_UL(fn, ul)
  427. #define DBG_EXIT_PTR(fn, ptr)
  428. #define DBG_EXIT_HRES(fn, hres)
  429. #else // defined(NODEBUGHELP) || !defined(DEBUG)
  430. extern DWORD g_dwDumpFlags;
  431. extern DWORD g_dwBreakFlags;
  432. extern DWORD g_dwTraceFlags;
  433. // Debugging macros
  434. //
  435. #ifndef SZ_MODULE
  436. #pragma message("SZ_MODULE is not #defined. Debug spew will use UNKNOWN module.")
  437. #define SZ_MODULE "UNKNOWN"
  438. #endif
  439. #define DEBUG_CASE_STRING(x) case x: return #x
  440. #define DEBUG_STRING_MAP(x) { x, #x }
  441. #define ASSERTSEG
  442. // Use this macro to declare message text that will be placed
  443. // in the CODE segment (useful if DS is getting full)
  444. //
  445. // Ex: DEBUGTEXT(szMsg, "Invalid whatever: %d");
  446. //
  447. #define DEBUGTEXT(sz, msg) \
  448. static const char ASSERTSEG sz[] = msg;
  449. void PUBLIC CommonDebugBreak(DWORD flag);
  450. void PUBLIC CommonAssertFailed(LPCSTR szFile, int line);
  451. void CPUBLIC CommonAssertMsg(BOOL f, LPCSTR pszMsg, ...);
  452. void CPUBLIC CommonDebugMsg(DWORD mask, LPCSTR pszMsg, ...);
  453. LPCSTR PUBLIC Dbg_SafeStr(LPCSTR psz);
  454. #define DEBUG_BREAK CommonDebugBreak
  455. // ASSERT(f) -- Generate "assertion failed in line x of file.c"
  456. // message if f is NOT true.
  457. //
  458. #define ASSERT(f) \
  459. { \
  460. DEBUGTEXT(szFile, __FILE__); \
  461. if (!(f)) \
  462. CommonAssertFailed(szFile, __LINE__); \
  463. }
  464. #define EVAL ASSERT
  465. // ASSERT_MSG(f, msg, args...) -- Generate wsprintf-formatted msg w/params
  466. // if f is NOT true.
  467. //
  468. #define ASSERT_MSG CommonAssertMsg
  469. // TRACE_MSG(mask, msg, args...) - Generate wsprintf-formatted msg using
  470. // specified debug mask. System debug mask
  471. // governs whether message is output.
  472. //
  473. #define DEBUG_MSG CommonDebugMsg
  474. #define TRACE_MSG DEBUG_MSG
  475. // VERIFY_SZ(f, msg, arg) -- Generate wsprintf-formatted msg w/ 1 param
  476. // if f is NOT true
  477. //
  478. #define VERIFY_SZ(f, szFmt, x) ASSERT_MSG(f, szFmt, x)
  479. // VERIFY_SZ2(f, msg, arg1, arg2) -- Generate wsprintf-formatted msg w/ 2
  480. // param if f is NOT true
  481. //
  482. #define VERIFY_SZ2(f, szFmt, x1, x2) ASSERT_MSG(f, szFmt, x1, x2)
  483. // DBG_ENTER(fn) -- Generates a function entry debug spew for
  484. // a function
  485. //
  486. #define DBG_ENTER(fn) \
  487. TRACE_MSG(TF_FUNC, " > " #fn "()")
  488. // DBG_ENTER_SZ(fn, sz) -- Generates a function entry debug spew for
  489. // a function that accepts a string as one of its
  490. // parameters.
  491. //
  492. #define DBG_ENTER_SZ(fn, sz) \
  493. TRACE_MSG(TF_FUNC, " > " #fn "(..., \"%s\",...)", Dbg_SafeStr(sz))
  494. #ifdef WANT_OLE_SUPPORT
  495. // DBG_ENTER_RIID(fn, riid) -- Generates a function entry debug spew for
  496. // a function that accepts an riid as one of its
  497. // parameters.
  498. //
  499. #define DBG_ENTER_RIID(fn, riid) \
  500. TRACE_MSG(TF_FUNC, " > " #fn "(..., %s,...)", Dbg_GetRiidName(riid))
  501. #endif
  502. // DBG_EXIT(fn) -- Generates a function exit debug spew
  503. //
  504. #define DBG_EXIT(fn) \
  505. TRACE_MSG(TF_FUNC, " < " #fn "()")
  506. // DBG_EXIT_TYPE(fn, dw, pfnStrFromType) -- Generates a function exit debug
  507. // spew for functions that return <type>.
  508. //
  509. #define DBG_EXIT_TYPE(fn, dw, pfnStrFromType) \
  510. TRACE_MSG(TF_FUNC, " < " #fn "() with %s", (LPCSTR)pfnStrFromType(dw))
  511. // DBG_EXIT_INT(fn, us) -- Generates a function exit debug spew for
  512. // functions that return an INT.
  513. //
  514. #define DBG_EXIT_INT(fn, n) \
  515. TRACE_MSG(TF_FUNC, " < " #fn "() with %d", (int)(n))
  516. // DBG_EXIT_BOOL(fn, b) -- Generates a function exit debug spew for
  517. // functions that return a boolean.
  518. //
  519. #define DBG_EXIT_BOOL(fn, b) \
  520. TRACE_MSG(TF_FUNC, " < " #fn "() with %s", (b) ? (LPSTR)"TRUE" : (LPSTR)"FALSE")
  521. // DBG_EXIT_US(fn, us) -- Generates a function exit debug spew for
  522. // functions that return a USHORT.
  523. //
  524. #define DBG_EXIT_US(fn, us) \
  525. TRACE_MSG(TF_FUNC, " < " #fn "() with %#x", (USHORT)(us))
  526. // DBG_EXIT_UL(fn, ul) -- Generates a function exit debug spew for
  527. // functions that return a ULONG.
  528. //
  529. #define DBG_EXIT_UL(fn, ul) \
  530. TRACE_MSG(TF_FUNC, " < " #fn "() with %#lx", (ULONG)(ul))
  531. // DBG_EXIT_PTR(fn, pv) -- Generates a function exit debug spew for
  532. // functions that return a pointer.
  533. //
  534. #define DBG_EXIT_PTR(fn, pv) \
  535. TRACE_MSG(TF_FUNC, " < " #fn "() with %#lx", (LPVOID)(pv))
  536. // DBG_EXIT_HRES(fn, hres) -- Generates a function exit debug spew for
  537. // functions that return an HRESULT.
  538. //
  539. #define DBG_EXIT_HRES(fn, hres) DBG_EXIT_TYPE(fn, hres, Dbg_GetScode)
  540. #endif // defined(NODEBUGHELP) || !defined(DEBUG)
  541. //
  542. // TRACING macros specific to RASSCRPIT
  543. //
  544. extern DWORD g_dwRasscrptTraceId;
  545. #define RASSCRPT_TRACE_INIT(module) DebugInitEx(module, &g_dwRasscrptTraceId)
  546. #define RASSCRPT_TRACE_TERM() DebugTermEx(&g_dwRasscrptTraceId)
  547. #define RASSCRPT_TRACE(a) TRACE_ID(g_dwRasscrptTraceId, a)
  548. #define RASSCRPT_TRACE1(a,b) TRACE_ID1(g_dwRasscrptTraceId, a,b)
  549. #define RASSCRPT_TRACE2(a,b,c) TRACE_ID2(g_dwRasscrptTraceId, a,b,c)
  550. #define RASSCRPT_TRACE3(a,b,c,d) TRACE_ID3(g_dwRasscrptTraceId, a,b,c,d)
  551. #define RASSCRPT_TRACE4(a,b,c,d,e) TRACE_ID4(g_dwRasscrptTraceId, a,b,c,d,e)
  552. #define RASSCRPT_TRACE5(a,b,c,d,e,f) TRACE_ID5(g_dwRasscrptTraceId, a,b,c,d,e,f)
  553. #define RASSCRPT_TRACE6(a,b,c,d,e,f,g) TRACE_ID6(g_dwRasscrptTraceId, a,b,c,d,e,f,g)
  554. #endif // __COMMON_H__