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.

338 lines
10 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997 - 1999
  5. //
  6. // File: regutil.h
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 3/20/1997 RaviR Created
  15. //____________________________________________________________________________
  16. //
  17. #pragma once
  18. #include "nmtempl.h"
  19. #ifdef COMMENTS_ONLY
  20. /*
  21. REGISTRY LAYOUT USED BY MMC:
  22. SNAPINS
  23. HKEY_LOCAL_MACHINE\Software\Microsoft\MMC\SnapIns
  24. {04ebc1e6-a16c-11d0-a799-00c04fd8d565} // See N-1.
  25. NameString = REG_SZ "Snapin Name"
  26. About = REG_SZ "{128ac4e6-a16c-11d0-a799-00c04fd8d565}" // See N-2.
  27. NodeTypes // See N-3.
  28. {c713e06c-a16e-11d0-a799-00c04fd8d565}
  29. {c713e06d-a16e-11d0-a799-00c04fd8d565}
  30. {c713e06e-a16e-11d0-a799-00c04fd8d565}
  31. {c713e06f-a16e-11d0-a799-00c04fd8d565}
  32. StandAlone // See N-4.
  33. RequiredExtensions // See N-5.
  34. {a2087336-a16c-11d0-a799-00c04fd8d565}
  35. {70098cd3-a16c-11d0-a799-00c04fd8d565}
  36. N-1) Snapin clsid. Only snapins that add to the name space should be
  37. entered here.
  38. N-2) Clisd of the object that will be cocreated to get the IAbout interface
  39. ptr for the snapin.
  40. N-3) Enumerate all the node type GUIDs that may be put up by this snapin.
  41. N-4) [Optional] Add the 'StandAlone' key only if the snapin can appear by
  42. itself under the Console Root. If this key is not present the snapin is
  43. assumed to be name space extension snapin. Note: A stand alone snapin
  44. can also be an extension snapin (i.e. it can extend some other snapin).
  45. N-5) [Optional] Enumerate the CLSIDs of extension snapins that are required
  46. for this snapin to function.
  47. NODETYPES
  48. HKEY_LOCAL_MACHINE\Software\Microsoft\MMC\NodeTypes
  49. {12345601-EA27-11CF-ADCF-00AA00A80033} // Node type GUID
  50. = REG_SZ "Log object"
  51. Extensions
  52. NameSpace // See N-7.
  53. {19876201-EA27-11CF-ADCF-00AA00A80033} = REG_SZ "Alert SnapIn"
  54. {34346202-EA27-11CF-ADCF-00AA00A80033} = REG_SZ "Viewer SnapIn"
  55. ContextMenu // See N-8.
  56. {19876202-EA27-11CF-ADCF-00AA00A80033} = REG_SZ "Alert SnapIn"
  57. {34346202-EA27-11CF-ADCF-00AA00A80033} = REG_SZ "Viewer SnapIn"
  58. ToolBar // See N-9.
  59. {19876202-EA27-11CF-ADCF-00AA00A80033} = REG_SZ "Alert SnapIn"
  60. {00234ca8-EA27-11CF-ADCF-00AA00A80033} = REG_SZ "Pure toolbar extn obj"
  61. PropertySheet // See N-10.
  62. {12222222-EA27-11CF-ADCF-00AA00A80033} = REG_SZ "Pure propery sheet extn obj"
  63. View // See N-12.
  64. {12222222-EA27-11CF-ADCF-00AA00A80033} = REG_SZ "View extn obj"
  65. Task // See N-13.
  66. {12222222-EA27-11CF-ADCF-00AA00A80033} = REG_SZ "Snapin Taskpad extn obj"
  67. Taskpad // See N-14.
  68. {12222222-EA27-11CF-ADCF-00AA00A80033} = REG_SZ "MMC2.0 Taskpad extn obj"
  69. Dynamic Extensions // See N-11
  70. {34346202-EA27-11CF-ADCF-00AA00A80033} = REG_SZ "Viewer SnapIn"
  71. N-7) Under the key 'NameSpace' list the CLSIDs of snapins that can extend the
  72. name space of this nodetype.
  73. N-8) Under the 'ContextMenu' key list the CLSIDs of snapins that can extend
  74. the context menu of items put up by this nodetype.
  75. N-9) Under the 'ToolBar' key list the CLSIDs of snapins that can extend
  76. the toolbar of items put up by this nodetype.
  77. N-10)Under the 'PropertySheet' key list the CLSIDs of snapins that can extend
  78. the property sheet of items put up by this nodetype.
  79. N-11)Under the 'Dynamic Extensions' Key list the CLSIDs of extensions that can only
  80. be enabled dynamically, not by the snap-in manager. Any CLSIDs listed here
  81. should also appear under one on the other extension sub-keys.
  82. N-12)Under the 'View' key list the CLSIDs of snapins that can extend
  83. the view of items put up by this nodetype.
  84. N-13)Under the 'Task' key list the CLSIDs of snapins that can extend
  85. the Taskpad of items put up by this nodetype.
  86. */
  87. #endif // COMMENTS_ONLY
  88. #ifndef _REGUTIL_H_
  89. #define _REGUTIL_H_
  90. #ifdef DBG
  91. #define ASSERT_INITIALIZED ASSERT(dbg_m_fInit == TRUE)
  92. #else
  93. #define ASSERT_INITIALIZED
  94. #endif
  95. // Forward decl
  96. class CPolicy;
  97. /*+-------------------------------------------------------------------------*
  98. * class CExtensionsIterator
  99. *
  100. *
  101. * PURPOSE: Allows iterating through all the extension snap-ins for a particular
  102. * nodetype.
  103. * Once initialized, returns, in order, all the registered extensions
  104. * followed by all the dynamic extensions. If a dynamic extension was
  105. * also a static extension, does not repeat the snap-in.
  106. *
  107. *
  108. * USAGE: Initialize the object, then make calls to GetCLSID() followed by
  109. * Advance() until IsEnd() returns true.
  110. *
  111. *+-------------------------------------------------------------------------*/
  112. class CExtensionsIterator
  113. {
  114. public:
  115. // Constructor & destructor
  116. CExtensionsIterator();
  117. ~CExtensionsIterator();
  118. // 1st variation - initializes the iterator from a dataobject and an extension type
  119. SC ScInitialize(LPDATAOBJECT pDataObject, LPCTSTR pszExtensionTypeKey);
  120. // 2nd variation (legacy)
  121. SC ScInitialize(CSnapIn *pSnapIn, GUID& rGuidNodeType, LPCTSTR pszExtensionTypeKey, LPCLSID pDynExtCLSID = NULL, int cDynExt = 0);
  122. // Attributes
  123. BOOL IsEnd()
  124. {
  125. ASSERT_INITIALIZED;
  126. return (m_pExtSI == NULL && m_nDynIndex >= m_cDynExt);
  127. }
  128. BOOL IsDynamic()
  129. {
  130. ASSERT_INITIALIZED;
  131. return (m_pExtSI == NULL);
  132. }
  133. void Reset()
  134. {
  135. ASSERT_INITIALIZED;
  136. m_pExtSI = m_spSnapIn->GetExtensionSnapIn();
  137. m_nDynIndex = 0;
  138. m_cExtUsed = 0;
  139. _EnsureExtension();
  140. }
  141. void Advance()
  142. {
  143. ASSERT_INITIALIZED;
  144. if (m_pExtSI != NULL)
  145. m_pExtSI = m_pExtSI->Next();
  146. else
  147. m_nDynIndex++;
  148. _EnsureExtension();
  149. }
  150. const CLSID& GetCLSID()
  151. {
  152. ASSERT_INITIALIZED;
  153. if (m_pExtSI != NULL)
  154. return m_pExtSI->GetCLSID();
  155. else if (m_nDynIndex < m_cDynExt)
  156. return m_pDynExtCLSID[m_nDynIndex];
  157. ASSERT(FALSE);
  158. return GUID_NULL;
  159. }
  160. CSnapIn* GetSnapIn()
  161. {
  162. ASSERT_INITIALIZED;
  163. if (m_pExtSI != NULL)
  164. {
  165. return m_pExtSI->GetSnapIn();
  166. }
  167. ASSERT(FALSE);
  168. return NULL;
  169. }
  170. private:
  171. HRESULT Init(GUID& rGuidNodeType, LPCTSTR pszExtensionTypeKey);
  172. // Implementation
  173. private:
  174. CSnapInPtr m_spSnapIn;
  175. CRegKeyEx m_rkey;
  176. CRegKeyEx m_rkeyDynExt;
  177. CExtSI* m_pExtSI;
  178. CExtSI** m_ppExtUsed;
  179. CArray<GUID,GUID&> m_cachedDynExtens;
  180. LPCLSID m_pDynExtCLSID;
  181. int m_cDynExt;
  182. int m_nDynIndex;
  183. int m_cExtUsed;
  184. CPolicy* m_pMMCPolicy;
  185. #ifdef DBG
  186. BOOL dbg_m_fInit;
  187. #endif
  188. void _EnsureExtension()
  189. {
  190. ASSERT_INITIALIZED;
  191. // Step through the snap-in's static extensions first
  192. for (; m_pExtSI != NULL; m_pExtSI = m_pExtSI->Next())
  193. {
  194. if (m_pExtSI->IsNew() == TRUE)
  195. continue;
  196. // Is this registered as the correct extension type?
  197. // Note: if extension is required, then it doesn't
  198. // have to be registered as a static extension
  199. if (_Extends(!m_pExtSI->IsRequired()) == TRUE)
  200. {
  201. m_ppExtUsed[m_cExtUsed++] = m_pExtSI;
  202. return;
  203. }
  204. }
  205. // When they are exhausted, go through the dynamic list
  206. for (; m_nDynIndex < m_cDynExt; m_nDynIndex++)
  207. {
  208. if (_Extends() == FALSE)
  209. continue;
  210. // Don't use dynamic extension that is already used statically
  211. for (int i=0; i< m_cExtUsed; i++)
  212. {
  213. if (IsEqualCLSID(m_pDynExtCLSID[m_nDynIndex], m_ppExtUsed[i]->GetCLSID()))
  214. break;
  215. }
  216. if (i == m_cExtUsed)
  217. return;
  218. }
  219. }
  220. BOOL _Extends(BOOL bStatically = FALSE);
  221. // Undefined
  222. CExtensionsIterator(const CExtensionsIterator& rhs);
  223. CExtensionsIterator& operator= (const CExtensionsIterator& rhs);
  224. }; // class CExtensionsIterator
  225. inline UINT HashKey(GUID& guid)
  226. {
  227. unsigned short* Values = (unsigned short *)&guid;
  228. return (Values[0] ^ Values[1] ^ Values[2] ^ Values[3] ^
  229. Values[4] ^ Values[5] ^ Values[6] ^ Values[7]);
  230. }
  231. class CExtensionsCache : public CMap<GUID, GUID&, int, int>
  232. {
  233. public:
  234. CExtensionsCache()
  235. {
  236. InitHashTable(31);
  237. }
  238. void Add(GUID& guid)
  239. {
  240. SetAt(guid, 0);
  241. }
  242. }; // class CExtensionsCache
  243. typedef XMapIterator<CExtensionsCache, GUID, int> CExtensionsCacheIterator;
  244. HRESULT ExtractDynExtensions(IDataObject* pdataObj, CArray<GUID, GUID&>& arrayGuid);
  245. SC ScGetExtensionsForNodeType(GUID& guid, CExtensionsCache& extnsCache);
  246. HRESULT MMCGetExtensionsForSnapIn(const CLSID& clsid,
  247. CExtensionsCache& extnsCache);
  248. BOOL ExtendsNodeNameSpace(GUID& rguidNodeType, CLSID* pclsidExtn);
  249. bool GetSnapinNameFromCLSID(const CLSID& clsid, tstring& tszSnapinName);
  250. SC ScGetAboutFromSnapinCLSID(LPCTSTR szClsidSnapin, CLSID& clsidAbout);
  251. SC ScGetAboutFromSnapinCLSID(const CLSID& clsidSnapin, CLSID& clsidAbout);
  252. bool IsIndirectStringSpecifier (LPCTSTR psz);
  253. template<class StringType> SC ScGetSnapinNameFromRegistry (const CLSID& clsid, StringType& str);
  254. template<class StringType> SC ScGetSnapinNameFromRegistry (LPCTSTR pszClsid, StringType& str);
  255. template<class StringType> SC ScGetSnapinNameFromRegistry (CRegKeyEx& key, StringType& str);
  256. inline BOOL HasNameSpaceExtensions(GUID& rguidNodeType)
  257. {
  258. return ExtendsNodeNameSpace(rguidNodeType, NULL);
  259. }
  260. #include "regutil.inl"
  261. #endif // _REGUTIL_H_