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.

177 lines
5.8 KiB

  1. #ifndef __inc_common_h
  2. #define __inc_common_h
  3. /*-----------------------------------------------------------------------------
  4. / Debugging APIs (use the Macros, they make it easier and cope with correctly
  5. / removing debugging when it is disabled at built time).
  6. /----------------------------------------------------------------------------*/
  7. #define TRACE_COMMON_ASSERT 0x80000000
  8. #define TRACE_COMMON_MISC 0x40000000
  9. #ifdef DBG
  10. EXTERN_C void DoTraceSetMask(DWORD dwMask);
  11. EXTERN_C void DoTraceSetMaskFromCLSID(REFCLSID rCLSID);
  12. EXTERN_C void DoTraceEnter(DWORD dwMask, LPCTSTR pName);
  13. EXTERN_C void DoTraceLeave(void);
  14. EXTERN_C LPCTSTR DoTraceGetCurrentFn(VOID);
  15. EXTERN_C void DoTrace(LPCTSTR pFormat, ...);
  16. EXTERN_C void DoTraceGUID(LPCTSTR pPrefix, REFGUID rGUID);
  17. EXTERN_C void DoTraceAssert(int iLine, LPTSTR pFilename);
  18. #else // DBG not defined (e.g. retail build)
  19. #define DoTraceMask(mask)
  20. #define DoTraceSetMaskFromCLSID(rCLSID)
  21. #define DoTraceEnter(dwMask, pName)
  22. #define DoTraceLeave()
  23. #define DoTraceGetCurrentFn() ("")
  24. #define DoTrace 1 ? (void) 0: (void)
  25. #define DoTraceGUID(pPrefix, rGUID)
  26. #define DoTraceAssert( iLine , pFilename)
  27. #endif // DBG
  28. /*-----------------------------------------------------------------------------
  29. / Macros to ease the use of the debugging APIS.
  30. /----------------------------------------------------------------------------*/
  31. #if DBG
  32. #define DSUI_DEBUG 1
  33. #define debug if ( TRUE )
  34. #else
  35. #undef DSUI_DEBUG
  36. #define debug
  37. #endif
  38. #define TraceSetMask(dwMask) debug DoTraceSetMask(dwMask)
  39. #define TraceSetMaskFromCLSID(rCLSID) debug DoTraceSetMaskFromCLSID(rCLSID)
  40. #define TraceEnter(dwMask, fn) debug DoTraceEnter(dwMask, TEXT(fn))
  41. #define TraceLeave debug DoTraceLeave
  42. #define Trace debug DoTrace
  43. #define TraceMsg(s) debug DoTrace(TEXT(s))
  44. #define TraceGUID(s, rGUID) debug DoTraceGUID(TEXT(s), rGUID)
  45. #ifdef DSUI_DEBUG
  46. #define TraceAssert(x) \
  47. { if ( !(x) ) DoTraceAssert(__LINE__, TEXT(__FILE__)); }
  48. #define TraceLeaveResult(hr) \
  49. { HRESULT __hr = hr; if (FAILED(__hr)) Trace(TEXT("Failed (%08x)"), hr); TraceLeave(); return __hr; }
  50. #define TraceLeaveVoid() \
  51. { TraceLeave(); return; }
  52. #define TraceLeaveValue(value) \
  53. { TraceLeave(); return(value); }
  54. #else
  55. #define TraceAssert(x)
  56. #define TraceLeaveResult(hr) { return hr; }
  57. #define TraceLeaveVoid() { return; }
  58. #define TraceLeaveValue(value) { return(value); }
  59. #endif
  60. //
  61. // flow control helpers, these expect you to have a exit_gracefully: label
  62. // defined in your function which is called to exit the body of the
  63. // routine.
  64. //
  65. #define ExitGracefully(hr, result, text) \
  66. { TraceMsg(text); hr = result; goto exit_gracefully; }
  67. #define FailGracefully(hr, text) \
  68. { if ( FAILED(hr) ) { TraceMsg(text); goto exit_gracefully; } }
  69. //
  70. // Some atomic free macros (should be replaced with calls to the shell ones)
  71. //
  72. #define DoRelease(pInterface) \
  73. { if ( pInterface ) { pInterface->Release(); pInterface = NULL; } }
  74. #define DoILFree(pidl) \
  75. { ILFree(pidl); pidl = NULL; }
  76. /*-----------------------------------------------------------------------------
  77. / String/byte helper macros
  78. /----------------------------------------------------------------------------*/
  79. #define StringByteSizeA(sz) ((sz) ? ((lstrlenA(sz)+1)*SIZEOF(CHAR)):0)
  80. #define StringByteSizeW(sz) ((sz) ? ((lstrlenW(sz)+1)*SIZEOF(WCHAR)):0)
  81. #define StringByteCopyA(pDest, iOffset, sz) \
  82. { CopyMemory(&(((LPBYTE)pDest)[iOffset]), sz, StringByteSizeA(sz)); }
  83. #define StringByteCopyW(pDest, iOffset, sz) \
  84. { CopyMemory(&(((LPBYTE)pDest)[iOffset]), sz, StringByteSizeW(sz)); }
  85. #ifndef UNICODE
  86. #define StringByteSize StringByteSizeA
  87. #define StringByteCopy StringByteCopyA
  88. #else
  89. #define StringByteSize StringByteSizeW
  90. #define StringByteCopy StringByteCopyW
  91. #endif
  92. #define ByteOffset(base, offset) (((LPBYTE)base)+offset)
  93. //
  94. // Lifted from ccstock.h
  95. //
  96. #ifndef InRange
  97. #define InRange(id, idFirst, idLast) ((UINT)((id)-(idFirst)) <= (UINT)((idLast)-(idFirst)))
  98. #endif
  99. #define SAFECAST(_obj, _type) (((_type)(_obj)==(_obj)?0:0), (_type)(_obj))
  100. /*-----------------------------------------------------------------------------
  101. / Helper functions (misc.cpp)
  102. /----------------------------------------------------------------------------*/
  103. EXTERN_C HRESULT GetKeyForCLSID(REFCLSID clsid, LPCTSTR pSubKey, HKEY* phkey);
  104. EXTERN_C HRESULT PutRegistryString(HINSTANCE hInstance, UINT uID, HKEY hKey, LPCTSTR pSubKey, LPCTSTR pValue);
  105. EXTERN_C HRESULT GetRealWindowInfo(HWND hwnd, LPRECT pRect, LPSIZE pSize);
  106. EXTERN_C VOID OffsetWindow(HWND hwnd, INT dx, INT dy);
  107. EXTERN_C HRESULT CallRegInstall(HINSTANCE hInstance, LPSTR szSection);
  108. EXTERN_C VOID SetDefButton(HWND hwndDlg, int idButton);
  109. EXTERN_C HRESULT AllocStorageMedium(FORMATETC* pFmt, STGMEDIUM* pMedium, SIZE_T cbStruct, LPVOID* ppAlloc);
  110. EXTERN_C HRESULT CopyStorageMedium(FORMATETC* pFmt, STGMEDIUM* pMediumDst, STGMEDIUM* pMediumSrc);
  111. //
  112. // The shell defines these on newer platforms, but for downlevel clients we will use our
  113. // own home grown (stollen versions)
  114. //
  115. EXTERN_C BOOL GetGUIDFromString(LPCTSTR psz, GUID* pguid);
  116. EXTERN_C INT GetStringFromGUID(UNALIGNED REFGUID rguid, LPTSTR psz, INT cchMax);
  117. #ifndef UNICODE
  118. EXTERN_C BOOL GetGUIDFromStringW(LPCWSTR psz, GUID* pguid);
  119. #else
  120. #define GetGUIDFromStringW(a, b) GetGUIDFromString(a, b)
  121. #endif
  122. //
  123. // replace LoadStringW with our own version that will work on the downlevel platforms
  124. //
  125. #ifndef UNICODE
  126. EXTERN_C INT MyLoadStringW(HINSTANCE hInstance, UINT uID, LPWSTR pszBuffer, INT cchBuffer);
  127. #define LoadStringW MyLoadStringW
  128. #endif
  129. #endif