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.

212 lines
6.8 KiB

  1. /*****************************************************************************\
  2. FILE: fromshell.h
  3. DESCRIPTION:
  4. These declarations are from Copied Shell\{inc,lib}\ files. I need
  5. to fork these since I moved out of the shell tree.
  6. BryanSt 4/10/2000
  7. Copyright (C) Microsoft Corp 2000-2000. All rights reserved.
  8. \*****************************************************************************/
  9. #ifndef _FROMSHELL_H
  10. #define _FROMSHELL_H
  11. // These declarations are from Copied Shell\{inc,lib}\ files
  12. // ATOMICRELEASE
  13. #ifndef ATOMICRELEASE
  14. #ifdef __cplusplus
  15. #define ATOMICRELEASET(p, type) { if(p) { type* punkT=p; p=NULL; punkT->Release();} }
  16. #else
  17. #define ATOMICRELEASET(p, type) { if(p) { type* punkT=p; p=NULL; punkT->lpVtbl->Release(punkT);} }
  18. #endif
  19. // doing this as a function instead of inline seems to be a size win.
  20. #ifdef NOATOMICRELESEFUNC
  21. #define ATOMICRELEASE(p) ATOMICRELEASET(p, IUnknown)
  22. #else
  23. #define ATOMICRELEASE(p) IUnknown_AtomicRelease((void **)&p)
  24. #endif
  25. #endif //ATOMICRELEASE
  26. // SAFECAST(obj, type)
  27. //
  28. // This macro is extremely useful for enforcing strong typechecking on other
  29. // macros. It generates no code.
  30. //
  31. // Simply insert this macro at the beginning of an expression list for
  32. // each parameter that must be typechecked. For example, for the
  33. // definition of MYMAX(x, y), where x and y absolutely must be integers,
  34. // use:
  35. //
  36. // #define MYMAX(x, y) (SAFECAST(x, int), SAFECAST(y, int), ((x) > (y) ? (x) : (y)))
  37. //
  38. //
  39. #define SAFECAST(_obj, _type) (((_type)(_obj)==(_obj)?0:0), (_type)(_obj))
  40. // Count of characters to count of bytes
  41. //
  42. #define CbFromCchW(cch) ((cch)*sizeof(WCHAR))
  43. #define CbFromCchA(cch) ((cch)*sizeof(CHAR))
  44. #ifdef UNICODE
  45. #define CbFromCch CbFromCchW
  46. #else // UNICODE
  47. #define CbFromCch CbFromCchA
  48. #endif // UNICODE
  49. typedef UINT FAR *LPUINT;
  50. // The following are declarations AutoDiscovery lost when it left the
  51. // shell tree.
  52. #define TF_ALWAYS 0xFFFFFFFF
  53. void TraceMsg(DWORD dwFlags, LPCSTR pszMessage, ...);
  54. void AssertMsg(BOOL fCondition, LPCSTR pszMessage, ...);
  55. // IID_PPV_ARG(IType, ppType)
  56. // IType is the type of pType
  57. // ppType is the variable of type IType that will be filled
  58. //
  59. // RESULTS in: IID_IType, ppvType
  60. // will create a compiler error if wrong level of indirection is used.
  61. //
  62. // macro for QueryInterface and related functions
  63. // that require a IID and a (void **)
  64. // this will insure that the cast is safe and appropriate on C++
  65. //
  66. // IID_PPV_ARG_NULL(IType, ppType)
  67. //
  68. // Just like IID_PPV_ARG, except that it sticks a NULL between the
  69. // IID and PPV (for IShellFolder::GetUIObjectOf).
  70. //
  71. // IID_X_PPV_ARG(IType, X, ppType)
  72. //
  73. // Just like IID_PPV_ARG, except that it sticks X between the
  74. // IID and PPV (for SHBindToObject).
  75. #ifdef __cplusplus
  76. #define IID_PPV_ARG(IType, ppType) IID_##IType, reinterpret_cast<void**>(static_cast<IType**>(ppType))
  77. #define IID_X_PPV_ARG(IType, X, ppType) IID_##IType, X, reinterpret_cast<void**>(static_cast<IType**>(ppType))
  78. #else
  79. #define IID_PPV_ARG(IType, ppType) &IID_##IType, (void**)(ppType)
  80. #define IID_X_PPV_ARG(IType, X, ppType) &IID_##IType, X, (void**)(ppType)
  81. #endif
  82. #define IID_PPV_ARG_NULL(IType, ppType) IID_X_PPV_ARG(IType, NULL, ppType)
  83. #define IN
  84. #define OUT
  85. #define ASSERT(condition)
  86. // Convert an array name (A) to a generic count (c).
  87. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  88. // General flag macros
  89. #define SetFlag(obj, f) do {obj |= (f);} while (0)
  90. #define ToggleFlag(obj, f) do {obj ^= (f);} while (0)
  91. #define ClearFlag(obj, f) do {obj &= ~(f);} while (0)
  92. #define IsFlagSet(obj, f) (BOOL)(((obj) & (f)) == (f))
  93. #define IsFlagClear(obj, f) (BOOL)(((obj) & (f)) != (f))
  94. #define RECTWIDTH(rc) ((rc).right - (rc).left)
  95. #define RECTHEIGHT(rc) ((rc).bottom - (rc).top)
  96. #ifdef DEBUG
  97. #define DEBUG_CODE(x) x
  98. #else // DEBUG
  99. #define DEBUG_CODE(x)
  100. #endif // DEBUG
  101. #define HRESULT_TO_SCRIPT(hr) ((S_OK == (hr)) ? S_OK : S_FALSE)
  102. #define SUCCEEDED_SCRIPT(hr) (S_OK == (hr))
  103. #define FAILED_SCRIPT(hr) (S_OK != (hr))
  104. #define SCRIPT_TO_HRESULT(hr) (((S_OK != (hr)) && (SUCCEEDED((hr)))) ? E_FAIL : hr)
  105. ////////////////
  106. // Critical section stuff
  107. //
  108. // Helper macros that give nice debug support
  109. EXTERN_C CRITICAL_SECTION g_csDll;
  110. #ifdef DEBUG
  111. EXTERN_C UINT g_CriticalSectionCount;
  112. EXTERN_C DWORD g_CriticalSectionOwner;
  113. EXTERN_C void Dll_EnterCriticalSection(CRITICAL_SECTION*);
  114. EXTERN_C void Dll_LeaveCriticalSection(CRITICAL_SECTION*);
  115. #if defined(__cplusplus) && defined(AssertMsg)
  116. class DEBUGCRITICAL {
  117. protected:
  118. BOOL fClosed;
  119. public:
  120. DEBUGCRITICAL() {fClosed = FALSE;};
  121. void Leave() {fClosed = TRUE;};
  122. ~DEBUGCRITICAL()
  123. {
  124. AssertMsg(fClosed, TEXT("you left scope while holding the critical section"));
  125. }
  126. };
  127. #define ENTERCRITICAL DEBUGCRITICAL debug_crit; Dll_EnterCriticalSection(&g_csDll)
  128. #define LEAVECRITICAL debug_crit.Leave(); Dll_LeaveCriticalSection(&g_csDll)
  129. #define ENTERCRITICALNOASSERT Dll_EnterCriticalSection(&g_csDll)
  130. #define LEAVECRITICALNOASSERT Dll_LeaveCriticalSection(&g_csDll)
  131. #else // __cplusplus
  132. #define ENTERCRITICAL Dll_EnterCriticalSection(&g_csDll)
  133. #define LEAVECRITICAL Dll_LeaveCriticalSection(&g_csDll)
  134. #define ENTERCRITICALNOASSERT Dll_EnterCriticalSection(&g_csDll)
  135. #define LEAVECRITICALNOASSERT Dll_LeaveCriticalSection(&g_csDll)
  136. #endif // __cplusplus
  137. #define ASSERTCRITICAL ASSERT(g_CriticalSectionCount > 0 && GetCurrentThreadId() == g_CriticalSectionOwner)
  138. #define ASSERTNONCRITICAL ASSERT(GetCurrentThreadId() != g_CriticalSectionOwner)
  139. #else // DEBUG
  140. #define ENTERCRITICAL EnterCriticalSection(&g_csDll)
  141. #define LEAVECRITICAL LeaveCriticalSection(&g_csDll)
  142. #define ENTERCRITICALNOASSERT EnterCriticalSection(&g_csDll)
  143. #define LEAVECRITICALNOASSERT LeaveCriticalSection(&g_csDll)
  144. #define ASSERTCRITICAL
  145. #define ASSERTNONCRITICAL
  146. #endif // DEBUG
  147. /////////////////////////////////////////////////////////////
  148. // Are these even needed?
  149. /////////////////////////////////////////////////////////////
  150. #ifdef OLD_HLIFACE
  151. #define HLNF_OPENINNEWWINDOW HLBF_OPENINNEWWINDOW
  152. #endif // OLD_HLIFACE
  153. #define ISVISIBLE(hwnd) ((GetWindowStyle(hwnd) & WS_VISIBLE) == WS_VISIBLE)
  154. #ifdef SAFERELEASE
  155. #undef SAFERELEASE
  156. #endif // SAFERELEASE
  157. #define SAFERELEASE(p) ATOMICRELEASE(p)
  158. #define IsInRange InRange
  159. //
  160. // Neutral ANSI/UNICODE types and macros... 'cus Chicago seems to lack them
  161. //
  162. #ifdef UNICODE
  163. typedef WCHAR TUCHAR, *PTUCHAR;
  164. #else /* UNICODE */
  165. typedef unsigned char TUCHAR, *PTUCHAR;
  166. #endif /* UNICODE */
  167. #endif // _FROMSHELL_H