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.

656 lines
21 KiB

  1. //
  2. // CCSHELL stock definition and declaration header
  3. //
  4. #ifndef __CCSTOCK_H__
  5. #define __CCSTOCK_H__
  6. #ifndef RC_INVOKED
  7. // NT and Win95 environments set warnings differently. This makes
  8. // our project consistent across environments.
  9. #pragma warning(3:4101) // Unreferenced local variable
  10. //
  11. // Sugar-coating
  12. //
  13. #define PUBLIC
  14. #define PRIVATE
  15. #define IN
  16. #define OUT
  17. #define BLOCK
  18. #ifndef DECLARE_STANDARD_TYPES
  19. /*
  20. * For a type "FOO", define the standard derived types PFOO, CFOO, and PCFOO.
  21. */
  22. #define DECLARE_STANDARD_TYPES(type) typedef type *P##type; \
  23. typedef const type C##type; \
  24. typedef const type *PC##type;
  25. #endif
  26. #ifndef DECLARE_STANDARD_TYPES_U
  27. /*
  28. * For a type "FOO", define the standard derived UNALIGNED types PFOO, CFOO, and PCFOO.
  29. * WINNT: RISC boxes care about ALIGNED, intel does not.
  30. */
  31. #define DECLARE_STANDARD_TYPES_U(type) typedef UNALIGNED type *P##type; \
  32. typedef UNALIGNED const type C##type; \
  33. typedef UNALIGNED const type *PC##type;
  34. #endif
  35. // For string constants that are always wide
  36. #define __TEXTW(x) L##x
  37. #define TEXTW(x) __TEXTW(x)
  38. //
  39. // Count of characters to count of bytes
  40. //
  41. #define CbFromCchW(cch) ((cch)*sizeof(WCHAR))
  42. #define CbFromCchA(cch) ((cch)*sizeof(CHAR))
  43. #ifdef UNICODE
  44. #define CbFromCch CbFromCchW
  45. #else // UNICODE
  46. #define CbFromCch CbFromCchA
  47. #endif // UNICODE
  48. //
  49. // General flag macros
  50. //
  51. #define SetFlag(obj, f) do {obj |= (f);} while (0)
  52. #define ToggleFlag(obj, f) do {obj ^= (f);} while (0)
  53. #define ClearFlag(obj, f) do {obj &= ~(f);} while (0)
  54. #define IsFlagSet(obj, f) (BOOL)(((obj) & (f)) == (f))
  55. #define IsFlagClear(obj, f) (BOOL)(((obj) & (f)) != (f))
  56. //
  57. // String macros
  58. //
  59. #define IsSzEqual(sz1, sz2) (BOOL)(lstrcmpi(sz1, sz2) == 0)
  60. #define IsSzEqualC(sz1, sz2) (BOOL)(lstrcmp(sz1, sz2) == 0)
  61. #define lstrnicmpA(sz1, sz2, cch) StrCmpNIA(sz1, sz2, cch)
  62. #define lstrnicmpW(sz1, sz2, cch) StrCmpNIW(sz1, sz2, cch)
  63. #define lstrncmpA(sz1, sz2, cch) StrCmpNA(sz1, sz2, cch)
  64. #define lstrncmpW(sz1, sz2, cch) StrCmpNW(sz1, sz2, cch)
  65. //
  66. // lstrcatnA and lstrcatnW are #defined here to StrCatBuff which is implemented
  67. // in shlwapi. We do this here (and not in shlwapi.h or shlwapip.h) in case the
  68. // kernel guys ever decided to implement this.
  69. //
  70. #define lstrcatnA(sz1, sz2, cchBuffSize) StrCatBuffA(sz1, sz2, cchBuffSize)
  71. #define lstrcatnW(sz1, sz2, cchBuffSize) StrCatBuffW(sz1, sz2, cchBuffSize)
  72. #ifdef UNICODE
  73. #define lstrcatn lstrcatnW
  74. #else
  75. #define lstrcatn lstrcatnA
  76. #endif // UNICODE
  77. #ifdef UNICODE
  78. #define lstrnicmp lstrnicmpW
  79. #define lstrncmp lstrncmpW
  80. #else
  81. #define lstrnicmp lstrnicmpA
  82. #define lstrncmp lstrncmpA
  83. #endif
  84. #ifndef SIZEOF
  85. #define SIZEOF(a) sizeof(a)
  86. #endif
  87. #ifndef ARRAYSIZE
  88. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  89. #endif
  90. #define SIZECHARS(sz) (sizeof(sz)/sizeof(sz[0]))
  91. #define InRange(id, idFirst, idLast) ((UINT)((id)-(idFirst)) <= (UINT)((idLast)-(idFirst)))
  92. #define IsInRange InRange
  93. #define ZeroInit(pv, cb) (memset((pv), 0, (cb)))
  94. // ATOMICRELEASE
  95. //
  96. #ifndef ATOMICRELEASE
  97. #ifdef __cplusplus
  98. #define ATOMICRELEASET(p, type) { if(p) { type* punkT=p; p=NULL; punkT->Release();} }
  99. #else
  100. #define ATOMICRELEASET(p, type) { if(p) { type* punkT=p; p=NULL; punkT->lpVtbl->Release(punkT);} }
  101. #endif
  102. // doing this as a function instead of inline seems to be a size win.
  103. //
  104. #ifdef NOATOMICRELESEFUNC
  105. #define ATOMICRELEASE(p) ATOMICRELEASET(p, IUnknown)
  106. #else
  107. #define ATOMICRELEASE(p) IUnknown_AtomicRelease((void **)&p)
  108. #endif
  109. #endif //ATOMICRELEASE
  110. //
  111. // Helper macro for managing weak pointers to inner interfaces.
  112. // (It's the weak version of ATOMICRELEASE.)
  113. //
  114. // The extra cast to (void **) is to keep C++ from doing strange
  115. // inheritance games when all I want to do is change the type.
  116. //
  117. #ifndef RELEASEINNERINTERFACE
  118. #define RELEASEINNERINTERFACE(pOuter, p) \
  119. SHReleaseInnerInterface(pOuter, (IUnknown**)(void **)&(p))
  120. #endif // RELEASEINNERINTERFACE
  121. // For checking window charsets
  122. #ifdef UNICODE
  123. #define IsWindowTchar IsWindowUnicode
  124. #else // !UNICODE
  125. #define IsWindowTchar !IsWindowUnicode
  126. #endif // UNICODE
  127. #ifdef DEBUG
  128. // This macro is especially useful for cleaner looking code in
  129. // declarations or for single lines. For example, instead of:
  130. //
  131. // {
  132. // DWORD dwRet;
  133. // #ifdef DEBUG
  134. // DWORD dwDebugOnlyVariable;
  135. // #endif
  136. //
  137. // ....
  138. // }
  139. //
  140. // You can type:
  141. //
  142. // {
  143. // DWORD dwRet;
  144. // DEBUG_CODE( DWORD dwDebugOnlyVariable; )
  145. //
  146. // ....
  147. // }
  148. #define DEBUG_CODE(x) x
  149. #else
  150. #define DEBUG_CODE(x)
  151. #endif // DEBUG
  152. //
  153. // SAFECAST(obj, type)
  154. //
  155. // This macro is extremely useful for enforcing strong typechecking on other
  156. // macros. It generates no code.
  157. //
  158. // Simply insert this macro at the beginning of an expression list for
  159. // each parameter that must be typechecked. For example, for the
  160. // definition of MYMAX(x, y), where x and y absolutely must be integers,
  161. // use:
  162. //
  163. // #define MYMAX(x, y) (SAFECAST(x, int), SAFECAST(y, int), ((x) > (y) ? (x) : (y)))
  164. //
  165. //
  166. #define SAFECAST(_obj, _type) (((_type)(_obj)==(_obj)?0:0), (_type)(_obj))
  167. //
  168. // Bitfields don't get along too well with bools,
  169. // so here's an easy way to convert them:
  170. //
  171. #define BOOLIFY(expr) (!!(expr))
  172. // Issue (scotth): we should probably make this a 'bool', but be careful
  173. // because the Alpha compiler might not recognize it yet. Talk to AndyP.
  174. // This isn't a BOOL because BOOL is signed and the compiler produces
  175. // sloppy code when testing for a single bit.
  176. typedef DWORD BITBOOL;
  177. // STOCKLIB util functions
  178. // IsOS(): returns TRUE/FALSE if the platform is the indicated OS.
  179. #ifndef OS_WINDOWS
  180. #define OS_WINDOWS 0 // windows vs. NT
  181. #define OS_NT 1 // windows vs. NT
  182. #define OS_WIN95 2 // Win95 or greater
  183. #define OS_NT4 3 // NT4 or greater
  184. #define OS_NT5 4 // NT5 or greater
  185. #define OS_MEMPHIS 5 // Win98 or greater
  186. #define OS_MEMPHIS_GOLD 6 // Win98 Gold
  187. #endif
  188. STDAPI_(BOOL) staticIsOS(DWORD dwOS);
  189. #include <pshpack2.h>
  190. typedef struct tagDLGTEMPLATEEX
  191. {
  192. WORD wDlgVer;
  193. WORD wSignature;
  194. DWORD dwHelpID;
  195. DWORD dwExStyle;
  196. DWORD dwStyle;
  197. WORD cDlgItems;
  198. short x;
  199. short y;
  200. short cx;
  201. short cy;
  202. } DLGTEMPLATEEX, *LPDLGTEMPLATEEX;
  203. #include <poppack.h>
  204. //
  205. // round macro that rounds a to the next multiple of b.
  206. //
  207. #ifndef ROUNDUP
  208. #define ROUNDUP(a,b) ((((a)+(b)-1)/(b))*(b))
  209. #endif
  210. #define ROUND_TO_CLUSTER ROUNDUP
  211. //
  212. // macro that sees if a give char is an number
  213. //
  214. #define ISDIGIT(c) ((c) >= TEXT('0') && (c) <= TEXT('9'))
  215. //
  216. // inline that does PathIsDotOrDotDot
  217. //
  218. __inline BOOL PathIsDotOrDotDotW(LPCWSTR pszPath)
  219. {
  220. return ((pszPath[0] == L'.') &&
  221. ((pszPath[1] == L'\0') || ((pszPath[1] == L'.') && (pszPath[2] == L'\0'))));
  222. }
  223. __inline BOOL PathIsDotOrDotDotA(LPCSTR pszPath)
  224. {
  225. return ((pszPath[0] == '.') &&
  226. ((pszPath[1] == '\0') || ((pszPath[1] == '.') && (pszPath[2] == '\0'))));
  227. }
  228. #ifdef UNICODE
  229. #define PathIsDotOrDotDot PathIsDotOrDotDotW
  230. #else
  231. #define PathIsDotOrDotDot PathIsDotOrDotDotA
  232. #endif
  233. //
  234. // WindowLong accessor macros and other Win64 niceness
  235. //
  236. __inline void * GetWindowPtr(HWND hWnd, int nIndex) {
  237. return (void *)GetWindowLongPtr(hWnd, nIndex);
  238. }
  239. __inline void * SetWindowPtr(HWND hWnd, int nIndex, void * p) {
  240. return (void *)SetWindowLongPtr(hWnd, nIndex, (LONG_PTR)p);
  241. }
  242. //*** GetWindowLong0 -- 'fast' GetWindowLong (and GetWindowLongPtr)
  243. // DESCRIPTION
  244. // what's up w/ this? it's all about perf. GetWindowLong has 'A' and 'W'
  245. // versions. however 99% of the time they do the same thing (the other
  246. // 0.1% has to do w/ setting the WndProc and having to go thru a thunk).
  247. // but we still need wrappers for the general case. but most of the time
  248. // we're just doing a GWL(0), e.g. on entry to a wndproc to get our private
  249. // data. so by having a special version of that, we save going thru the
  250. // wrapper (which was costing us 1-3% of our profile).
  251. // NOTES
  252. // note that we call the 'A' version since that's guaranteed to exist on
  253. // all platforms.
  254. __inline LONG GetWindowLong0(HWND hWnd) {
  255. return GetWindowLongA(hWnd, 0);
  256. }
  257. __inline LONG SetWindowLong0(HWND hWnd, LONG l) {
  258. return SetWindowLongA(hWnd, 0, l);
  259. }
  260. __inline void * GetWindowPtr0(HWND hWnd) {
  261. return (void *)GetWindowLongPtrA(hWnd, 0);
  262. }
  263. __inline void * SetWindowPtr0(HWND hWnd, void * p) {
  264. return (void *)SetWindowLongPtrA(hWnd, 0, (LONG_PTR)p);
  265. }
  266. #define IS_WM_CONTEXTMENU_KEYBOARD(lParam) ((DWORD)(lParam) == 0xFFFFFFFF)
  267. //
  268. // CharUpperChar - Convert a single character to uppercase
  269. //
  270. __inline WCHAR CharUpperCharW(WCHAR c)
  271. {
  272. return (WCHAR)(DWORD_PTR)CharUpperW((LPWSTR)(DWORD_PTR)(c));
  273. }
  274. __inline CHAR CharUpperCharA(CHAR c)
  275. {
  276. return (CHAR)(DWORD_PTR)CharUpperA((LPSTR)(DWORD_PTR)(c));
  277. }
  278. #ifdef UNICODE
  279. #define CharUpperChar CharUpperCharW
  280. #else
  281. #define CharUpperChar CharUpperCharA
  282. #endif
  283. //
  284. // ShrinkProcessWorkingSet - Use this to stay Sundown-happy.
  285. //
  286. #define ShrinkWorkingSet() \
  287. SetProcessWorkingSetSize(GetCurrentProcess(), (SIZE_T) -1, (SIZE_T) -1)
  288. //
  289. // COM Initialization.
  290. //
  291. // Usage:
  292. //
  293. // HRESULT hrInit = SHCoInitialize();
  294. // ... do COM stuff ...
  295. // SHCoUninitialize(hrInit);
  296. //
  297. // Notice: Continue doing COM stuff even if SHCoInitialize fails.
  298. // It might fail if somebody else already CoInit'd with different
  299. // flags, but we don't want to barf under those conditions.
  300. //
  301. STDAPI SHCoInitialize(void);
  302. #define SHCoUninitialize(hr) if (SUCCEEDED(hr)) CoUninitialize()
  303. //
  304. // OLE Initialization.
  305. //
  306. // Usage:
  307. //
  308. // HRESULT hrInit = SHOleInitialize(pMalloc);
  309. // ... do COM stuff ...
  310. // SHOleUninitialize(hrInit);
  311. //
  312. #define SHOleInitialize(pMalloc) OleInitialize(pMalloc)
  313. #define SHOleUninitialize(hr) if (SUCCEEDED(hr)) OleUninitialize()
  314. //
  315. // MACRO HACK - Since not all clients of ccstock.h include shlobj.h first,
  316. // we need to use the long form of LP[C]ITEMIDLIST. Since nobody remembers
  317. // this little quirk, to avoid future build breaks, redefine the symbols
  318. // to their long forms.
  319. //
  320. #define LPCITEMIDLIST const UNALIGNED struct _ITEMIDLIST *
  321. #define LPITEMIDLIST UNALIGNED struct _ITEMIDLIST *
  322. //
  323. // Name Parsing generic across the shell
  324. //
  325. // Usage:
  326. //
  327. // HRESULT SHGetNameAndFlags()
  328. // wrapper to bind to the folder and do a GetDisplayName()
  329. //
  330. STDAPI SHGetNameAndFlagsA(LPCITEMIDLIST pidl, DWORD dwFlags, LPSTR pszName, UINT cchName, DWORD *pdwAttribs);
  331. STDAPI SHGetNameAndFlagsW(LPCITEMIDLIST pidl, DWORD dwFlags, LPWSTR pszName, UINT cchName, DWORD *pdwAttribs);
  332. STDAPI SHGetNameAndFlags2A(struct IShellFolder *psfRoot, LPCITEMIDLIST pidl, DWORD dwFlags, LPSTR pszName, UINT cchName, DWORD *pdwAttribs);
  333. STDAPI SHGetNameAndFlags2W(struct IShellFolder *psfRoot, LPCITEMIDLIST pidl, DWORD dwFlags, LPWSTR pszName, UINT cchName, DWORD *pdwAttribs);
  334. //
  335. // Special values for SHGetNameAndFlags2::psfRoot
  336. //
  337. #define NAF2_SHELLDESKTOP ((IShellFolder *)0) // relative to shell desktop
  338. #define NAF2_CURRENTROOT ((IShellFolder *)-1) // relative to current root
  339. STDAPI SHBindToObject(struct IShellFolder *psf, REFIID riid, LPCITEMIDLIST pidl, void **ppvOut);
  340. #define SHGetAttributesOf(pidl, prgfInOut) SHGetNameAndFlags(pidl, 0, NULL, 0, prgfInOut)
  341. STDAPI_(DWORD) GetUrlSchemeW(LPCWSTR pszUrl);
  342. STDAPI_(DWORD) GetUrlSchemeA(LPCSTR pszUrl);
  343. #ifdef UNICODE
  344. #define SHGetNameAndFlags SHGetNameAndFlagsW
  345. #define SHGetNameAndFlags2 SHGetNameAndFlags2W
  346. #define GetUrlScheme GetUrlSchemeW
  347. #else
  348. #define SHGetNameAndFlags SHGetNameAndFlagsA
  349. #define SHGetNameAndFlags2 SHGetNameAndFlags2A
  350. #define GetUrlScheme GetUrlSchemeA
  351. #endif
  352. // SHBindToIDListParent(LPCITEMIDLIST pidl, REFIID riid, void **ppv, LPCITEMIDLIST *ppidlLast)
  353. //
  354. // Given a pidl, you can get an interface pointer (as specified by riid) of the pidl's parent folder (in ppv)
  355. // If ppidlLast is non-NULL, you can also get the pidl of the last item.
  356. //
  357. STDAPI SHBindToIDListParent(LPCITEMIDLIST pidl, REFIID riid, void **ppv, LPCITEMIDLIST *ppidlLast);
  358. //
  359. // SHBindToFolderIDListParent
  360. //
  361. // Same as SHBindToIDListParent, except you also specify which root to use.
  362. //
  363. STDAPI SHBindToFolderIDListParent(struct IShellFolder *psfRoot, LPCITEMIDLIST pidl, REFIID riid, void **ppv, LPCITEMIDLIST *ppidlLast);
  364. STDAPI_(void) SHRemoveURLTurd(LPTSTR pszUrl);
  365. // clones the parent of the pidl
  366. STDAPI_(LPITEMIDLIST) ILCloneParent(LPCITEMIDLIST pidl);
  367. //
  368. // END OF MACRO HACK
  369. //
  370. #undef LPITEMIDLIST
  371. #undef LPCITEMIDLIST
  372. //
  373. // Mirroring-Support APIs (astracted in \shell\lib\stock5\rtlmir.cpp)
  374. //
  375. #ifdef __cplusplus
  376. extern "C" {
  377. #endif
  378. extern BOOL g_bMirroredOS;
  379. WORD GetDefaultLang(BOOL bForceEnglish);
  380. WORD GetWindowLang (HWND hWndOwner);
  381. BOOL UseProperDlgTemplate(HINSTANCE hInst, HGLOBAL *phDlgTemplate, HRSRC *phResInfo, LPCSTR lpName,
  382. HWND hWndOwner, LPWORD lpwLangID, BOOL bForceEnglish);
  383. #ifdef USE_MIRRORING
  384. BOOL IsBiDiLocalizedSystem( void );
  385. BOOL Mirror_IsEnabledOS( void );
  386. LANGID Mirror_GetUserDefaultUILanguage( void );
  387. BOOL Mirror_IsWindowMirroredRTL( HWND hWnd );
  388. DWORD Mirror_IsDCMirroredRTL( HDC hdc );
  389. DWORD Mirror_MirrorDC( HDC hdc );
  390. BOOL Mirror_MirrorProcessRTL( void );
  391. DWORD Mirror_GetLayout( HDC hdc );
  392. DWORD Mirror_SetLayout( HDC hdc , DWORD dwLayout );
  393. BOOL Mirror_GetProcessDefaultLayout( DWORD *pdwDefaultLayout );
  394. BOOL Mirror_IsProcessRTL( void );
  395. extern const DWORD dwNoMirrorBitmap;
  396. extern const DWORD dwExStyleRTLMirrorWnd;
  397. extern const DWORD dwExStyleNoInheritLayout;
  398. extern const DWORD dwPreserveBitmap;
  399. //
  400. // 'g_bMirroredOS' is defined in each component which will use the
  401. // mirroring APIs. I decided to put it here, in order to make sure
  402. // each component has validated that the OS supports the mirroring
  403. // APIs before calling them.
  404. //
  405. #define IS_BIDI_LOCALIZED_SYSTEM() IsBiDiLocalizedSystem()
  406. #define IS_MIRRORING_ENABLED() Mirror_IsEnabledOS()
  407. #define IS_WINDOW_RTL_MIRRORED(hwnd) (g_bMirroredOS && Mirror_IsWindowMirroredRTL(hwnd))
  408. #define IS_DC_RTL_MIRRORED(hdc) (g_bMirroredOS && Mirror_IsDCMirroredRTL(hdc))
  409. #define GET_PROCESS_DEF_LAYOUT(pdwl) (g_bMirroredOS && Mirror_GetProcessDefaultLayout(pdwl))
  410. #define IS_PROCESS_RTL_MIRRORED() (g_bMirroredOS && Mirror_IsProcessRTL())
  411. #define SET_DC_RTL_MIRRORED(hdc) Mirror_MirrorDC(hdc)
  412. #define SET_DC_LAYOUT(hdc,dwl) Mirror_SetLayout(hdc,dwl)
  413. #define SET_PROCESS_RTL_LAYOUT() Mirror_MirrorProcessRTL()
  414. #define GET_DC_LAYOUT(hdc) Mirror_GetLayout(hdc)
  415. #define DONTMIRRORBITMAP dwNoMirrorBitmap
  416. #define RTL_MIRRORED_WINDOW dwExStyleRTLMirrorWnd
  417. #define RTL_NOINHERITLAYOUT dwExStyleNoInheritLayout
  418. #define LAYOUT_PRESERVEBITMAP dwPreserveBitmap
  419. #else
  420. #define IS_BIDI_LOCALIZED_SYSTEM() FALSE
  421. #define IS_MIRRORING_ENABLED() FALSE
  422. #define IS_WINDOW_RTL_MIRRORED(hwnd) FALSE
  423. #define IS_DC_RTL_MIRRORED(hdc) FALSE
  424. #define GET_PROCESS_DEF_LAYOUT(pdwl) FALSE
  425. #define IS_PROCESS_RTL_MIRRORED() FALSE
  426. #define SET_DC_RTL_MIRRORED(hdc)
  427. #define SET_DC_LAYOUT(hdc,dwl)
  428. #define SET_PROCESS_DEFAULT_LAYOUT()
  429. #define GET_DC_LAYOUT(hdc) 0L
  430. #define DONTMIRRORBITMAP 0L
  431. #define RTL_MIRRORED_WINDOW 0L
  432. #define LAYOUT_PRESERVEBITMAP 0L
  433. #endif // USE_MIRRROING
  434. BOOL IsBiDiLocalizedWin95( BOOL bArabicOnly );
  435. //
  436. //====== Dynamic array functions ================================================
  437. //
  438. //------------------------------------------------------------------------
  439. // Dynamic key array
  440. //
  441. typedef struct _DKA * HDKA; // hdka
  442. HDKA DKA_CreateA(HKEY hkey, LPCSTR pszSubKey, LPCSTR pszFirst, LPCSTR pszDefOrder, BOOL fDefault);
  443. HDKA DKA_CreateW(HKEY hkey, LPCWSTR pszSubKey, LPCWSTR pszFirst, LPCWSTR pszDefOrder, BOOL fDefault);
  444. int DKA_GetItemCount(HDKA hdka);
  445. LPCSTR DKA_GetKeyA(HDKA hdka, int iItem);
  446. LPCWSTR DKA_GetKeyW(HDKA hdka, int iItem);
  447. LONG DKA_QueryValueA(HDKA hdka, int iItem, LPSTR szValue, LONG * pcb);
  448. LONG DKA_QueryValueW(HDKA hdka, int iItem, LPWSTR szValue, LONG * pcb);
  449. DWORD DKA_QueryOtherValueA(HDKA pdka, int iItem, LPCSTR pszName, LPSTR pszValue, LONG * pcb);
  450. DWORD DKA_QueryOtherValueW(HDKA pdka, int iItem, LPCWSTR pszName, LPWSTR pszValue, LONG * pcb);
  451. void DKA_Destroy(HDKA hdka);
  452. #ifdef UNICODE
  453. #define DKA_Create DKA_CreateW
  454. #define DKA_GetKey DKA_GetKeyW
  455. #define DKA_QueryValue DKA_QueryValueW
  456. #define DKA_QueryOtherValue DKA_QueryOtherValueW
  457. #else
  458. #define DKA_Create DKA_CreateA
  459. #define DKA_GetKey DKA_GetKeyA
  460. #define DKA_QueryValue DKA_QueryValueA
  461. #define DKA_QueryOtherValue DKA_QueryOtherValueA
  462. #endif
  463. //------------------------------------------------------------------------
  464. // Dynamic class array
  465. //
  466. typedef struct _DCA * HDCA; // hdca
  467. HDCA DCA_Create();
  468. void DCA_Destroy(HDCA hdca);
  469. int DCA_GetItemCount(HDCA hdca);
  470. BOOL DCA_AddItem(HDCA hdca, REFCLSID rclsid);
  471. const CLSID * DCA_GetItem(HDCA hdca, int i);
  472. void DCA_AddItemsFromKeyA(HDCA hdca, HKEY hkey, LPCSTR pszSubKey);
  473. void DCA_AddItemsFromKeyW(HDCA hdca, HKEY hkey, LPCWSTR pszSubKey);
  474. #ifdef UNICODE
  475. #define DCA_AddItemsFromKey DCA_AddItemsFromKeyW
  476. #else
  477. #define DCA_AddItemsFromKey DCA_AddItemsFromKeyA
  478. #endif
  479. STDAPI DCA_CreateInstance(HDCA hdca, int iItem, REFIID riid, void ** ppv);
  480. #ifdef __cplusplus
  481. };
  482. #endif
  483. #endif // RC_INVOKED
  484. //------------------------------------------------------------------------
  485. // Random helpful functions
  486. //------------------------------------------------------------------------
  487. //
  488. STDAPI_(BOOL) _SHIsButtonObscured(HWND hwnd, PRECT prc, INT_PTR i);
  489. STDAPI_(void) _SHPrettyMenu(HMENU hm);
  490. STDAPI_(BOOL) _SHIsMenuSeparator(HMENU hm, int i);
  491. STDAPI_(BOOL) _SHIsMenuSeparator2(HMENU hm, int i, BOOL *pbIsNamed);
  492. STDAPI_(BYTE) SHBtnStateFromRestriction(DWORD dwRest, BYTE fsState);
  493. STDAPI_(BOOL) SHIsDisplayable(LPCWSTR pwszName, BOOL fRunOnFE, BOOL fRunOnNT5);
  494. STDAPI_(void) EnableOKButtonFromString(HWND hDlg, LPTSTR pszText);
  495. STDAPI_(void) EnableOKButtonFromID(HWND hDlg, int id);
  496. //------------------------------------------------------------------------
  497. ////////////////
  498. //
  499. // Critical section stuff
  500. //
  501. // Helper macros that give nice debug support
  502. //
  503. EXTERN_C CRITICAL_SECTION g_csDll;
  504. #ifdef DEBUG
  505. EXTERN_C UINT g_CriticalSectionCount;
  506. EXTERN_C DWORD g_CriticalSectionOwner;
  507. EXTERN_C void Dll_EnterCriticalSection(CRITICAL_SECTION*);
  508. EXTERN_C void Dll_LeaveCriticalSection(CRITICAL_SECTION*);
  509. #if defined(__cplusplus) && defined(AssertMsg)
  510. class DEBUGCRITICAL {
  511. protected:
  512. BOOL fClosed;
  513. public:
  514. DEBUGCRITICAL() {fClosed = FALSE;};
  515. void Leave() {fClosed = TRUE;};
  516. ~DEBUGCRITICAL()
  517. {
  518. AssertMsg(fClosed, TEXT("you left scope while holding the critical section"));
  519. }
  520. };
  521. #define ENTERCRITICAL DEBUGCRITICAL debug_crit; Dll_EnterCriticalSection(&g_csDll)
  522. #define LEAVECRITICAL debug_crit.Leave(); Dll_LeaveCriticalSection(&g_csDll)
  523. #define ENTERCRITICALNOASSERT Dll_EnterCriticalSection(&g_csDll)
  524. #define LEAVECRITICALNOASSERT Dll_LeaveCriticalSection(&g_csDll)
  525. #else // __cplusplus
  526. #define ENTERCRITICAL Dll_EnterCriticalSection(&g_csDll)
  527. #define LEAVECRITICAL Dll_LeaveCriticalSection(&g_csDll)
  528. #define ENTERCRITICALNOASSERT Dll_EnterCriticalSection(&g_csDll)
  529. #define LEAVECRITICALNOASSERT Dll_LeaveCriticalSection(&g_csDll)
  530. #endif // __cplusplus
  531. #define ASSERTCRITICAL ASSERT(g_CriticalSectionCount > 0 && GetCurrentThreadId() == g_CriticalSectionOwner)
  532. #define ASSERTNONCRITICAL ASSERT(GetCurrentThreadId() != g_CriticalSectionOwner)
  533. #else // DEBUG
  534. #define ENTERCRITICAL EnterCriticalSection(&g_csDll)
  535. #define LEAVECRITICAL LeaveCriticalSection(&g_csDll)
  536. #define ENTERCRITICALNOASSERT EnterCriticalSection(&g_csDll)
  537. #define LEAVECRITICALNOASSERT LeaveCriticalSection(&g_csDll)
  538. #define ASSERTCRITICAL
  539. #define ASSERTNONCRITICAL
  540. #endif // DEBUG
  541. #endif // __CCSTOCK_H__