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.

496 lines
12 KiB

  1. #ifndef HOTFIX_MANAGER
  2. #define HOTFIX_MANAGER
  3. #include "resource.h"
  4. #include <atlsnap.h>
  5. static _TCHAR gszComputerName[255];
  6. static BOOL ComputerNameSent = FALSE;
  7. static IDispatch* gszManagerCtlDispatch = NULL;
  8. inline LPOLESTR CoTaskDupString( LPOLESTR pszInput )
  9. {
  10. USES_CONVERSION;
  11. LPOLESTR pszOut = NULL;
  12. //
  13. // We throw an exception if the following allocation fails.
  14. //
  15. pszOut = (LPOLESTR) CoTaskMemAlloc( ( wcslen( pszInput ) + 1 ) * sizeof( OLECHAR ) );
  16. if ( pszOut == NULL )
  17. throw;
  18. wcscpy( pszOut, pszInput );
  19. return( pszOut );
  20. };
  21. template <class T>
  22. class ATL_NO_VTABLE ISnapinHelpImpl : public ISnapinHelp
  23. {
  24. public:
  25. // get the dkms help file location and returns it
  26. STDMETHOD( GetHelpTopic )( LPOLESTR* lpCompiledHelpFile )
  27. {
  28. _ASSERT( lpCompiledHelpFile != NULL );
  29. USES_CONVERSION;
  30. HRESULT hr = E_FAIL;
  31. TCHAR szPath[ _MAX_PATH * 2 ];
  32. // this is where the dkms help file is stored
  33. wcscpy(szPath,L"C:\\mmc-samples\\Hotfix_Snapin\\snapsamp.chm");
  34. // MessageBox(NULL,szPath,_T("Help File Path"),MB_OK);
  35. // expand out the %systemroot% variable
  36. // ExpandEnvVars(szPath);
  37. // MessageBox(NULL,szPath,_T("Help File Path"),MB_OK);
  38. // Allocate the string and return it.
  39. *lpCompiledHelpFile = CoTaskDupString( T2W( szPath ) );
  40. hr = S_OK;
  41. return( hr );
  42. }
  43. };
  44. class CHotfix_ManagerComponent;
  45. class CHotfix_ManagerData : public CSnapInItemImpl<CHotfix_ManagerData>
  46. {
  47. public:
  48. static const GUID* m_NODETYPE;
  49. static const OLECHAR* m_SZNODETYPE;
  50. static const OLECHAR* m_SZDISPLAY_NAME;
  51. static const CLSID* m_SNAPIN_CLASSID;
  52. _TCHAR m_szComputerName[255];
  53. _TCHAR m_szCreation[255];
  54. bool m_bChild;
  55. bool b_Expanded;
  56. DWORD m_dwCurrentView;
  57. _TCHAR m_ProductName[255];
  58. CHotfix_ManagerComponent* m_pComponent;
  59. static BSTR m_bstrColumnType;
  60. static BSTR m_bstrColumnDesc;
  61. CComPtr<IControlbar> m_spControlBar;
  62. BEGIN_SNAPINCOMMAND_MAP(CHotfix_ManagerData, FALSE)
  63. END_SNAPINCOMMAND_MAP()
  64. // SNAPINMENUID(IDR_HOTFIXMANAGER_MENU)
  65. BEGIN_SNAPINTOOLBARID_MAP(CHotfix_ManagerData)
  66. // Create toolbar resources with button dimensions 16x16
  67. // and add an entry to the MAP. You can add multiple toolbars
  68. // SNAPINTOOLBARID_ENTRY(Toolbar ID)
  69. END_SNAPINTOOLBARID_MAP()
  70. CHotfix_ManagerData(_TCHAR * ProductName,_TCHAR * new_ComputerName, bool Child)
  71. {
  72. _TCHAR Messg[255];
  73. m_dwCurrentView = IDC_VIEW_BY_HOTFIX;
  74. m_bChild = Child;
  75. _tcscpy (m_szComputerName, new_ComputerName);
  76. b_Expanded = false;
  77. // Image indexes may need to be modified depending on the images specific to
  78. // the snapin.
  79. // Image indexes may need to be modified depending on the images specific to
  80. // the snapin.
  81. memset(&m_scopeDataItem, 0, sizeof(SCOPEDATAITEM));
  82. m_scopeDataItem.mask = SDI_STR | SDI_IMAGE | SDI_OPENIMAGE | SDI_PARAM;
  83. m_scopeDataItem.displayname = MMC_CALLBACK;
  84. m_scopeDataItem.nImage = 4; // May need modification
  85. m_scopeDataItem.nOpenImage = 5; // May need modification
  86. m_scopeDataItem.lParam = (LPARAM) this;
  87. memset(&m_resultDataItem, 4, sizeof(RESULTDATAITEM));
  88. m_resultDataItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  89. m_resultDataItem.str = MMC_CALLBACK;
  90. m_resultDataItem.nImage = 4; // May need modification
  91. m_resultDataItem.lParam = (LPARAM) this;
  92. if (ProductName == NULL)
  93. {
  94. LoadString(_Module.GetResourceInstance(),IDS_DISPLAY_NAME,Messg,255);
  95. _tcscpy(m_ProductName,_T("\0"));
  96. }
  97. else
  98. {
  99. _tcscpy(Messg,ProductName);
  100. _tcscpy(m_ProductName,ProductName);
  101. }
  102. m_bstrDisplayName = SysAllocString(Messg);
  103. LoadString(_Module.GetResourceInstance(),IDS_COLUMN_TYPE,Messg,255);
  104. m_bstrColumnType = SysAllocString(Messg);
  105. LoadString(_Module.GetResourceInstance(),IDS_COLUMN_DESC,Messg,255);
  106. m_bstrColumnDesc = SysAllocString( Messg );
  107. }
  108. ~CHotfix_ManagerData()
  109. {
  110. }
  111. STDMETHOD(GetScopePaneInfo)(SCOPEDATAITEM *pScopeDataItem);
  112. STDMETHOD( GetResultViewType )( LPOLESTR* ppViewType, long* pViewOptions );
  113. STDMETHOD(GetResultPaneInfo)(RESULTDATAITEM *pResultDataItem);
  114. STDMETHOD(Notify)( MMC_NOTIFY_TYPE event,
  115. long arg,
  116. long param,
  117. IComponentData* pComponentData,
  118. IComponent* pComponent,
  119. DATA_OBJECT_TYPES type);
  120. LPOLESTR GetResultPaneColInfo(int nCol);
  121. BOOL SendProductName(_TCHAR *szPoductName, IDispatch * pDisp);
  122. BOOL SendComputerName(_TCHAR *szDataMachineName,IDispatch * pDisp);
  123. BOOL SendCommand( LPARAM lparamCommand );
  124. STDMETHOD( Command )(long lCommandID,
  125. CSnapInObjectRootBase* pObj,
  126. DATA_OBJECT_TYPES type);
  127. STDMETHOD(AddMenuItems)(
  128. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  129. long *pInsertionAllowed,
  130. DATA_OBJECT_TYPES type);
  131. };
  132. DWORD GetCtrlStatus();
  133. class CHotfix_ManagerExtData : public CSnapInItemImpl<CHotfix_ManagerExtData, TRUE>
  134. {
  135. public:
  136. static const GUID* m_NODETYPE;
  137. static const OLECHAR* m_SZNODETYPE;
  138. static const OLECHAR* m_SZDISPLAY_NAME;
  139. static const CLSID* m_SNAPIN_CLASSID;
  140. BEGIN_SNAPINCOMMAND_MAP(CHotfix_ManagerExtData, FALSE)
  141. END_SNAPINCOMMAND_MAP()
  142. // SNAPINMENUID(IDR_HOTFIXMANAGER_MENU)
  143. BEGIN_SNAPINTOOLBARID_MAP(CHotfix_ManagerExtData)
  144. // Create toolbar resources with button dimensions 16x16
  145. // and add an entry to the MAP. You can add multiple toolbars
  146. // SNAPINTOOLBARID_ENTRY(Toolbar ID)
  147. END_SNAPINTOOLBARID_MAP()
  148. CHotfix_ManagerExtData()
  149. {
  150. m_pNode = NULL;
  151. memset(&m_scopeDataItem, 0, sizeof(SCOPEDATAITEM));
  152. memset(&m_resultDataItem, 0, sizeof(RESULTDATAITEM));
  153. }
  154. ~CHotfix_ManagerExtData()
  155. {
  156. if ( m_pNode != NULL )
  157. delete m_pNode;
  158. }
  159. IDataObject* m_pDataObject;
  160. virtual void InitDataClass(IDataObject* pDataObject, CSnapInItem* pDefault)
  161. {
  162. m_pDataObject = pDataObject;
  163. // The default code stores off the pointer to the Dataobject the class is wrapping
  164. // at the time.
  165. // Alternatively you could convert the dataobject to the internal format
  166. // it represents and store that information
  167. }
  168. CSnapInItem* GetExtNodeObject(IDataObject* pDataObject, CSnapInItem* pDefault)
  169. {
  170. // Modify to return a different CSnapInItem* pointer.
  171. return pDefault;
  172. }
  173. STDMETHOD(Notify)( MMC_NOTIFY_TYPE event,
  174. long arg,
  175. long param,
  176. IComponentData* pComponentData,
  177. IComponent* pComponent,
  178. DATA_OBJECT_TYPES type);
  179. STDMETHOD(GetDisplayInfo)(SCOPEDATAITEM *pScopeDataItem)
  180. {
  181. return( S_OK );
  182. }
  183. protected:
  184. CSnapInItem* m_pNode;
  185. };
  186. class CHotfix_Manager;
  187. class CHotfix_ManagerComponent : public CComObjectRootEx<CComSingleThreadModel>,
  188. public CSnapInObjectRoot<2, CHotfix_Manager >,
  189. public IExtendContextMenuImpl<CHotfix_Manager>,
  190. // public IExtendControlbarImpl<CHotfix_ManagerComponent>,
  191. public IPersistStreamInit,
  192. public IComponentImpl<CHotfix_ManagerComponent>
  193. {
  194. public:
  195. BEGIN_COM_MAP(CHotfix_ManagerComponent)
  196. COM_INTERFACE_ENTRY(IComponent)
  197. COM_INTERFACE_ENTRY(IExtendContextMenu)
  198. // COM_INTERFACE_ENTRY(IExtendControlbar)
  199. COM_INTERFACE_ENTRY(IPersistStreamInit)
  200. END_COM_MAP()
  201. // SNAPINMENUID(IDR_HOTFIXMANAGER_MENU)
  202. public:
  203. CHotfix_ManagerComponent()
  204. {
  205. }
  206. STDMETHOD(Notify)(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, long arg, long param)
  207. {
  208. //
  209. // Check for a special data object being sent.
  210. // Might be able to extract the computer name here....
  211. if ( IS_SPECIAL_DATAOBJECT( lpDataObject ) )
  212. return( S_OK );
  213. if (lpDataObject != NULL)
  214. return IComponentImpl<CHotfix_ManagerComponent>::Notify(lpDataObject, event, arg, param);
  215. // TODO : Add code to handle notifications that set lpDataObject == NULL.
  216. return E_NOTIMPL;
  217. }
  218. STDMETHOD(GetClassID)(CLSID *pClassID)
  219. {
  220. ATLTRACENOTIMPL(_T("CHotfix_ManagerComponent::GetClassID"));
  221. }
  222. STDMETHOD(IsDirty)()
  223. {
  224. ATLTRACENOTIMPL(_T("CHotfix_ManagerComponent::IsDirty"));
  225. }
  226. STDMETHOD(Load)(IStream *pStm)
  227. {
  228. ATLTRACENOTIMPL(_T("CHotfix_ManagerComponent::Load"));
  229. }
  230. STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty)
  231. {
  232. ATLTRACENOTIMPL(_T("CHotfix_ManagerComponent::Save"));
  233. }
  234. STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize)
  235. {
  236. ATLTRACENOTIMPL(_T("CHotfix_ManagerComponent::GetSizeMax"));
  237. }
  238. STDMETHOD(Command)(long lCommandID,
  239. LPDATAOBJECT pDataObject);
  240. STDMETHOD(InitNew)()
  241. {
  242. ATLTRACE(_T("CHotfix_ManagerComponent::InitNew\n"));
  243. return S_OK;
  244. }
  245. STDMETHOD (AddMenuItems) (LPDATAOBJECT pDataObject, LPCONTEXTMENUCALLBACK piCallback,long *pInsertionAllowed);
  246. };
  247. class CHotfix_Manager : public CComObjectRootEx<CComSingleThreadModel>,
  248. public CSnapInObjectRoot<1, CHotfix_Manager>,
  249. public IComponentDataImpl<CHotfix_Manager, CHotfix_ManagerComponent>,
  250. public IExtendControlbarImpl<CHotfix_Manager>,
  251. public IExtendContextMenuImpl<CHotfix_Manager>,
  252. public IPersistStreamInit,
  253. public ISnapinHelpImpl<CHotfix_Manager>,
  254. public CComCoClass<CHotfix_Manager, &CLSID_Hotfix_Manager>
  255. {
  256. public:
  257. CHotfix_Manager();
  258. bool IsRemoted()
  259. {
  260. return( m_fRemoted );
  261. }
  262. ~CHotfix_Manager()
  263. {
  264. delete m_pNode;
  265. m_pNode = NULL;
  266. }
  267. EXTENSION_SNAPIN_DATACLASS(CHotfix_ManagerExtData)
  268. BEGIN_EXTENSION_SNAPIN_NODEINFO_MAP(CHotfix_Manager)
  269. EXTENSION_SNAPIN_NODEINFO_ENTRY(CHotfix_ManagerExtData)
  270. END_EXTENSION_SNAPIN_NODEINFO_MAP()
  271. BEGIN_COM_MAP(CHotfix_Manager)
  272. COM_INTERFACE_ENTRY(IComponentData)
  273. COM_INTERFACE_ENTRY(IExtendControlbar)
  274. COM_INTERFACE_ENTRY(IExtendContextMenu)
  275. COM_INTERFACE_ENTRY(IPersistStreamInit)
  276. COM_INTERFACE_ENTRY(ISnapinHelp)
  277. END_COM_MAP()
  278. DECLARE_REGISTRY_RESOURCEID(IDR_HOTFIXMANAGER)
  279. DECLARE_NOT_AGGREGATABLE(CHotfix_Manager)
  280. STDMETHOD(GetClassID)(CLSID *pClassID)
  281. {
  282. ATLTRACENOTIMPL(_T("CHotfix_Manager::GetClassID"));
  283. }
  284. STDMETHOD(IsDirty)()
  285. {
  286. ATLTRACENOTIMPL(_T("CHotfix_Manager::IsDirty"));
  287. }
  288. STDMETHOD(Load)(IStream *pStm)
  289. {
  290. ATLTRACENOTIMPL(_T("CHotfix_Manager::Load"));
  291. }
  292. STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty)
  293. {
  294. ATLTRACENOTIMPL(_T("CHotfix_Manager::Save"));
  295. }
  296. STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize)
  297. {
  298. ATLTRACENOTIMPL(_T("CHotfix_Manager::GetSizeMax"));
  299. }
  300. STDMETHOD(InitNew)()
  301. {
  302. ATLTRACE(_T("CHotfix_Manager::InitNew\n"));
  303. return S_OK;
  304. }
  305. STDMETHOD(Initialize)(LPUNKNOWN pUnknown);
  306. static void WINAPI ObjectMain(bool bStarting)
  307. {
  308. if (bStarting)
  309. CSnapInItem::Init();
  310. }
  311. STDMETHOD(Notify)( LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  312. protected:
  313. _TCHAR m_szComputerName[255];
  314. bool ExtractString( IDataObject* pDataObject, unsigned int cfClipFormat, LPTSTR pBuf, DWORD dwMaxLength );
  315. //
  316. // Register the clipboard format and get the value to query on.
  317. //
  318. void RegisterRemotedClass()
  319. {
  320. m_ccfRemotedFormat = RegisterClipboardFormat( _T( "MMC_SNAPIN_MACHINE_NAME" ) );
  321. _ASSERTE( m_ccfRemotedFormat > 0 );
  322. }
  323. //
  324. // Determine if we're monitoring a local or remote machine based on the given data object.
  325. //
  326. bool IsDataObjectRemoted( IDataObject* pDataObject );
  327. //
  328. // Used to track whether we're remoted or not.
  329. //
  330. bool m_fRemoted;
  331. //
  332. // Initialized by RegisterRemoteClass(). Contains the clipboard ID
  333. // of MMC_SNAPIN_MACHINE_NAME after registered with the clipboard.
  334. //
  335. UINT m_ccfRemotedFormat;
  336. };
  337. class ATL_NO_VTABLE CHotfix_ManagerAbout : public ISnapinAbout,
  338. public CComObjectRoot,
  339. public CComCoClass< CHotfix_ManagerAbout, &CLSID_Hotfix_ManagerAbout>
  340. {
  341. public:
  342. DECLARE_REGISTRY(CHotfixManagerAbout, _T("Hotfix_ManagerAbout.1"), _T("Hotfix_ManagerAbout.1"), IDS_HOTFIXMANAGER_DESC, THREADFLAGS_BOTH);
  343. BEGIN_COM_MAP(CHotfix_ManagerAbout)
  344. COM_INTERFACE_ENTRY(ISnapinAbout)
  345. END_COM_MAP()
  346. STDMETHOD(GetSnapinDescription)(LPOLESTR *lpDescription)
  347. {
  348. USES_CONVERSION;
  349. TCHAR szBuf[256];
  350. if (::LoadString(_Module.GetResourceInstance(), IDS_HOTFIXMANAGER_DESC, szBuf, 256) == 0)
  351. return E_FAIL;
  352. *lpDescription = (LPOLESTR)CoTaskMemAlloc((lstrlen(szBuf) + 1) * sizeof(OLECHAR));
  353. if (*lpDescription == NULL)
  354. return E_OUTOFMEMORY;
  355. ocscpy(*lpDescription, T2OLE(szBuf));
  356. return S_OK;
  357. }
  358. STDMETHOD(GetProvider)(LPOLESTR *lpName)
  359. {
  360. USES_CONVERSION;
  361. TCHAR szBuf[256];
  362. if (::LoadString(_Module.GetResourceInstance(), IDS_HOTFIXMANAGER_PROVIDER, szBuf, 256) == 0)
  363. return E_FAIL;
  364. *lpName = (LPOLESTR)CoTaskMemAlloc((lstrlen(szBuf) + 1) * sizeof(OLECHAR));
  365. if (*lpName == NULL)
  366. return E_OUTOFMEMORY;
  367. ocscpy(*lpName, T2OLE(szBuf));
  368. return S_OK;
  369. }
  370. STDMETHOD(GetSnapinVersion)(LPOLESTR *lpVersion)
  371. {
  372. USES_CONVERSION;
  373. TCHAR szBuf[256];
  374. if (::LoadString(_Module.GetResourceInstance(), IDS_HOTFIXMANAGER_VERSION, szBuf, 256) == 0)
  375. return E_FAIL;
  376. *lpVersion = (LPOLESTR)CoTaskMemAlloc((lstrlen(szBuf) + 1) * sizeof(OLECHAR));
  377. if (*lpVersion == NULL)
  378. return E_OUTOFMEMORY;
  379. ocscpy(*lpVersion, T2OLE(szBuf));
  380. return S_OK;
  381. }
  382. STDMETHOD(GetSnapinImage)(HICON *hAppIcon)
  383. {
  384. *hAppIcon = NULL;
  385. return S_OK;
  386. }
  387. STDMETHOD(GetStaticFolderImage)(HBITMAP *hSmallImage,
  388. HBITMAP *hSmallImageOpen,
  389. HBITMAP *hLargeImage,
  390. COLORREF *cMask)
  391. {
  392. *hSmallImageOpen = *hLargeImage = *hLargeImage = 0;
  393. return S_OK;
  394. }
  395. };
  396. #endif