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.

460 lines
12 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1999
  5. //
  6. // File: SnapIn.h
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 09/09/1996 RaviR Created
  15. //
  16. //____________________________________________________________________________
  17. //
  18. // A sample SnapIn registry entry
  19. //
  20. // SnapIns
  21. // {d84a45bb-d390-11cf-b607-00c04fd8d565}
  22. // = REG_SZ "Logs snap-in"
  23. // Name = REG_SZ "logvwr.dll, 101"
  24. // NameString = REG_SZ "Logs"
  25. // Status = REG_SZ "logvwr.dll, 102"
  26. // StatusString = REG_SZ "Container enumerating all logs on a machine."
  27. // ImageOpen = REG_SZ "logvwr.dll, 103"
  28. // ImageClosed = REG_SZ "logvwr.dll, 104"
  29. // ResultPane = REG_SZ "{....}" / "Html path" / "url"
  30. //
  31. #ifndef _SNAPIN_H_
  32. #define _SNAPIN_H_
  33. class CExtSI;
  34. class CSnapIn;
  35. class CSnapInsCache;
  36. // forward decl
  37. class CPersistor;
  38. #define BOOLVAL(x) ((x) ? TRUE : FALSE)
  39. //____________________________________________________________________________
  40. //
  41. // Class: CSnapIn
  42. //____________________________________________________________________________
  43. //
  44. extern const GUID IID_CSnapIn;
  45. #if _MSC_VER < 1100
  46. class CSnapIn : public IUnknown, public CComObjectRoot
  47. #else
  48. class __declspec(uuid("E6DFFF74-6FE7-11d0-B509-00C04FD9080A")) CSnapIn :
  49. public IUnknown, public CComObjectRoot, public CXMLObject
  50. #endif
  51. {
  52. private:
  53. enum SNAPIN_FLAGS
  54. {
  55. SNAPIN_NAMESPACE_CHANGED = 0x0001,
  56. SNAPIN_REQ_EXTS_LOADED = 0x0002,
  57. SNAPIN_ENABLE_ALL_EXTS = 0x0004,
  58. SNAPIN_SNAPIN_ENABLES_ALL = 0x0008,
  59. };
  60. public:
  61. BEGIN_COM_MAP(CSnapIn)
  62. COM_INTERFACE_ENTRY(CSnapIn)
  63. END_COM_MAP()
  64. DECLARE_NOT_AGGREGATABLE(CSnapIn)
  65. // Attributes
  66. const CLSID& GetSnapInCLSID() const
  67. {
  68. return m_clsidSnapIn;
  69. }
  70. void SetSnapInCLSID(const CLSID& id)
  71. {
  72. m_clsidSnapIn = id;
  73. }
  74. CExtSI* GetExtensionSnapIn() const
  75. {
  76. return m_pExtSI;
  77. }
  78. BOOL RequiredExtensionsLoaded() const
  79. {
  80. return (m_dwFlags & SNAPIN_REQ_EXTS_LOADED) != 0;
  81. }
  82. BOOL AreAllExtensionsEnabled() const
  83. {
  84. return (m_dwFlags & SNAPIN_ENABLE_ALL_EXTS) != 0;
  85. }
  86. BOOL DoesSnapInEnableAll() const
  87. {
  88. return (m_dwFlags & SNAPIN_SNAPIN_ENABLES_ALL) != 0;
  89. }
  90. void SetAllExtensionsEnabled(BOOL bState = TRUE)
  91. {
  92. if (bState)
  93. m_dwFlags |= SNAPIN_ENABLE_ALL_EXTS;
  94. else
  95. m_dwFlags &= ~SNAPIN_ENABLE_ALL_EXTS;
  96. }
  97. void SetRequiredExtensionsLoaded(BOOL bState = TRUE)
  98. {
  99. if (bState)
  100. m_dwFlags |= SNAPIN_REQ_EXTS_LOADED;
  101. else
  102. m_dwFlags &= ~SNAPIN_REQ_EXTS_LOADED;
  103. }
  104. void SetSnapInEnablesAll(BOOL bState = TRUE)
  105. {
  106. if (bState)
  107. m_dwFlags |= SNAPIN_SNAPIN_ENABLES_ALL;
  108. else
  109. m_dwFlags &= ~SNAPIN_SNAPIN_ENABLES_ALL;
  110. }
  111. BOOL HasNameSpaceChanged() const
  112. {
  113. return (m_dwFlags & SNAPIN_NAMESPACE_CHANGED) != 0;
  114. }
  115. void SetNameSpaceChanged(BOOL bState = TRUE)
  116. {
  117. if (bState)
  118. m_dwFlags |= SNAPIN_NAMESPACE_CHANGED;
  119. else
  120. m_dwFlags &= ~SNAPIN_NAMESPACE_CHANGED;
  121. }
  122. DWORD GetSnapInModule(TCHAR* szBuffer, DWORD cchBuffer) const;
  123. bool IsStandAlone() const;
  124. HRESULT Dump (LPCTSTR pszDumpFile, CSnapInsCache* pCache);
  125. SC ScGetSnapInName(WTL::CString& strSnapinName) const;
  126. CExtSI* AddExtension(CSnapIn* pSI);
  127. CExtSI* FindExtension(const CLSID& id);
  128. void MarkExtensionDeleted(CSnapIn* pSI);
  129. void PurgeExtensions();
  130. // destroys list of extensions. extension list needs to be destroyed
  131. // this will break snapin's circular references if such exist.
  132. // (it happens when snapins extends itself or own extension)
  133. SC ScDestroyExtensionList();
  134. // Operations
  135. BOOL ExtendsNameSpace(GUID guidNodeType);
  136. // Loads/Saves this node and its extensions to the provided stream
  137. HRESULT Load(CSnapInsCache* pCache, IStream* pStream);
  138. HRESULT Load(CSnapInsCache* pCache, IStream* pStream, CExtSI*& pExtSI);
  139. HRESULT Save(IStream* pStream, BOOL bClearDirty);
  140. virtual void Persist(CPersistor &persistor);
  141. void PersistLoad(CPersistor& persistor,CSnapInsCache* pCache);
  142. DEFINE_XML_TYPE(XML_TAG_SNAPIN);
  143. public:
  144. #ifdef DBG
  145. int dbg_cRef;
  146. ULONG InternalAddRef()
  147. {
  148. ++dbg_cRef;
  149. return CComObjectRoot::InternalAddRef();
  150. }
  151. ULONG InternalRelease()
  152. {
  153. --dbg_cRef;
  154. return CComObjectRoot::InternalRelease();
  155. }
  156. int dbg_InstID;
  157. #endif // DBG
  158. // Implementation
  159. protected:
  160. // Constructor & Destructor
  161. CSnapIn();
  162. virtual ~CSnapIn(); // Called only by Release
  163. HKEY OpenKey (REGSAM samDesired = KEY_ALL_ACCESS) const;
  164. // Following methods/member variables manage/contains temporary state
  165. // used for finding used/unused snapins.
  166. // despite it is not really a property of the snapin and is not valid all the time,
  167. // having the state on the snapin is very convenient for the operation.
  168. // Else it would require temporary storage and frequent lookup for information.
  169. // begin temporary state
  170. public:
  171. SC ScTempState_ResetReferenceCalculationData( );
  172. SC ScTempState_UpdateInternalReferenceCounts( );
  173. SC ScTempState_MarkIfExternallyReferenced( );
  174. SC ScTempState_IsExternallyReferenced( bool& bReferenced ) const;
  175. private:
  176. SC ScTempState_SetHasStrongReference( );
  177. DWORD m_dwTempState_InternalRef;
  178. bool m_bTempState_HasStrongRef;
  179. // end temporary state
  180. private:
  181. DWORD m_dwFlags;
  182. CLSID m_clsidSnapIn;
  183. CExtSI* m_pExtSI; // Extensions
  184. //____________________________________________________________________________
  185. //
  186. // Class: CExtPersistor
  187. //
  188. // Purpose: implements persisting the collection - snapin extensions
  189. //____________________________________________________________________________
  190. //
  191. class CExtPersistor : public XMLListCollectionBase
  192. {
  193. public:
  194. CExtPersistor(CSnapIn& Parent) : m_Parent(Parent),m_pCache(NULL) {}
  195. virtual void OnNewElement(CPersistor& persistor);
  196. virtual void Persist(CPersistor& persistor);
  197. void SetCache(CSnapInsCache* pCache) { m_pCache = pCache; }
  198. DEFINE_XML_TYPE(XML_TAG_SNAPIN_EXTENSIONS);
  199. private:
  200. CSnapIn& GetParent() { return m_Parent; }
  201. CSnapIn& m_Parent;
  202. CSnapInsCache* m_pCache;
  203. };
  204. friend class CExtPersistor;
  205. CExtPersistor m_ExtPersistor;
  206. // Not implemented.
  207. CSnapIn(const CSnapIn &rhs);
  208. CSnapIn& operator=(const CSnapIn &rhs);
  209. }; // class CSnapIn
  210. DEFINE_COM_SMARTPTR(CSnapIn); // CSnapInPtr
  211. //____________________________________________________________________________
  212. //
  213. // Class: CExtSI
  214. //____________________________________________________________________________
  215. //
  216. class CExtSI
  217. {
  218. public:
  219. enum EXTSI_FLAGS
  220. {
  221. EXT_TYPES_MASK = 0x000FFFFF,
  222. EXT_TYPE_NAMESPACE = 0x00000001,
  223. EXT_TYPE_CONTEXTMENU = 0x00000002,
  224. EXT_TYPE_TOOLBAR = 0x00000004,
  225. EXT_TYPE_PROPERTYSHEET = 0x00000008,
  226. EXT_TYPE_TASK = 0x00000010,
  227. EXT_TYPE_VIEW = 0x00000020,
  228. EXT_TYPE_STATIC = 0x00010000,
  229. EXT_TYPE_DYNAMIC = 0x00020000,
  230. EXT_TYPE_REQUIRED = 0x00040000,
  231. EXT_NEW = 0x80000000,
  232. EXT_DELETED = 0x40000000,
  233. };
  234. public:
  235. // Constructor & Destructor
  236. CExtSI(CSnapIn* pSnapIn);
  237. ~CExtSI(void);
  238. // Attributes
  239. const CLSID& GetCLSID();
  240. CExtSI*& Next()
  241. {
  242. return m_pNext;
  243. }
  244. CSnapIn* GetSnapIn(void) const
  245. {
  246. return m_pSnapIn;
  247. }
  248. void SetNext(CExtSI* pNext)
  249. {
  250. m_pNext = pNext;
  251. }
  252. void SetNew(BOOL bState = TRUE)
  253. {
  254. if (bState)
  255. m_dwFlags |= EXT_NEW;
  256. else
  257. m_dwFlags &= ~EXT_NEW;
  258. }
  259. void SetRequired(BOOL bState = TRUE)
  260. {
  261. if (bState)
  262. m_dwFlags |= EXT_TYPE_REQUIRED;
  263. else
  264. m_dwFlags &= ~EXT_TYPE_REQUIRED;
  265. }
  266. void MarkDeleted(BOOL bState = TRUE)
  267. {
  268. if (bState)
  269. m_dwFlags |= EXT_DELETED;
  270. else
  271. m_dwFlags &= ~EXT_DELETED;
  272. }
  273. BOOL IsNew()
  274. {
  275. return BOOLVAL(m_dwFlags & EXT_NEW);
  276. }
  277. BOOL IsRequired()
  278. {
  279. return BOOLVAL(m_dwFlags & EXT_TYPE_REQUIRED);
  280. }
  281. BOOL IsMarkedForDeletion()
  282. {
  283. return BOOLVAL(m_dwFlags & EXT_DELETED);
  284. }
  285. BOOL ExtendsNameSpace()
  286. {
  287. return BOOLVAL(m_dwFlags & EXT_TYPE_NAMESPACE);
  288. }
  289. BOOL ExtendsContextMenu()
  290. {
  291. return BOOLVAL(m_dwFlags & EXT_TYPE_CONTEXTMENU);
  292. }
  293. BOOL ExtendsToolBar()
  294. {
  295. return BOOLVAL(m_dwFlags & EXT_TYPE_TOOLBAR);
  296. }
  297. BOOL ExtendsPropertySheet()
  298. {
  299. return BOOLVAL(m_dwFlags & EXT_TYPE_PROPERTYSHEET);
  300. }
  301. BOOL ExtendsView()
  302. {
  303. return BOOLVAL(m_dwFlags & EXT_TYPE_VIEW);
  304. }
  305. BOOL ExtendsTask()
  306. {
  307. return BOOLVAL(m_dwFlags & EXT_TYPE_TASK);
  308. }
  309. UINT GetExtensionTypes()
  310. {
  311. return (m_dwFlags & EXT_TYPES_MASK);
  312. }
  313. void SetExtensionTypes(UINT uiExtTypes)
  314. {
  315. ASSERT((uiExtTypes & ~EXT_TYPES_MASK) == 0);
  316. m_dwFlags = (m_dwFlags & ~EXT_TYPES_MASK) | uiExtTypes;
  317. }
  318. // Operations
  319. // Saves this extension, and all of the nexts.
  320. HRESULT Save(IStream* pStream, BOOL bClearDirty);
  321. void Persist(CPersistor &persistor);
  322. static void PersistNew(CPersistor &persistor, CSnapIn& snapParent, CSnapInsCache& snapCache);
  323. // Implementation
  324. private:
  325. DWORD m_dwFlags;
  326. CSnapIn* m_pSnapIn;
  327. CExtSI* m_pNext;
  328. }; // class CExtSI
  329. //____________________________________________________________________________
  330. //
  331. // Class: CSnapInsCache
  332. //____________________________________________________________________________
  333. //
  334. class CSnapInsCache : public XMLListCollectionBase
  335. {
  336. typedef std::map<CLSID, CSnapInPtr> map_t;
  337. public:
  338. CSnapInsCache();
  339. ~CSnapInsCache();
  340. // Operations
  341. SC ScGetSnapIn(const REFCLSID riid, CSnapIn* * ppSnapIn);
  342. SC ScFindSnapIn(const REFCLSID riid, CSnapIn** ppSnapIn);
  343. // iteration
  344. typedef map_t::iterator iterator;
  345. iterator begin() { return m_snapins.begin(); }
  346. iterator end() { return m_snapins.end(); }
  347. // CXMLObject methods
  348. DEFINE_XML_TYPE(XML_TAG_SNAPIN_CACHE);
  349. virtual void Persist(CPersistor &persistor);
  350. virtual void OnNewElement(CPersistor& persistor);
  351. // Load Save the snapins cache
  352. SC ScSave(IStream* pStream, BOOL bClearDirty);
  353. SC ScLoad(IStream* pStream);
  354. SC ScIsDirty() ;
  355. void SetDirty(BOOL bIsDirty = TRUE);
  356. void Purge(BOOL bExtensionsOnly = FALSE);
  357. void SetHelpCollectionDirty (bool bState = true) { m_bUpdateHelpColl = bState;}
  358. bool IsHelpCollectionDirty (void) { return m_bUpdateHelpColl; }
  359. HRESULT Dump (LPCTSTR pszDumpFile);
  360. SC ScCheckSnapinAvailability (CAvailableSnapinInfo& asi);
  361. SC ScMarkExternallyReferencedSnapins();
  362. #ifdef DBG
  363. void DebugDump();
  364. #endif
  365. private:
  366. // Implementation
  367. BOOL m_bIsDirty;
  368. map_t m_snapins;
  369. bool m_bUpdateHelpColl : 1;
  370. #ifdef TEMP_SNAPIN_MGRS_WORK
  371. void GetAllExtensions(CSnapIn* pSI);
  372. #endif // TEMP_SNAPIN_MGRS_WORK
  373. }; // class CSnapInsCache
  374. #endif // _SNAPIN_H_