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.

799 lines
25 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: dummysi.cpp
  8. //
  9. // Contents: If a snapin creation fails a Dummy snapin is created,
  10. // this file contains the dummy snapin implementation.
  11. //
  12. //--------------------------------------------------------------------------
  13. #include "stdafx.h"
  14. #include "dummysi.h"
  15. #include "regutil.h"
  16. const CLSID CLSID_Dummy = {0x82c37898,0x7808,0x11d1,{0xa1,0x90,0x00,0x00,0xf8,0x75,0xb1,0x32}};
  17. const GUID IID_CDummySnapinCD = {0xe683b257, 0x3ca9, 0x454a, {0xae, 0xb9, 0x7, 0x64, 0xdd, 0x31, 0xb1, 0xe8}};
  18. //+-------------------------------------------------------------------
  19. //
  20. // Class: CDummySnapinCD
  21. //
  22. // Purpose: Dummy snapin's ComponentData.
  23. //
  24. // Notes: Dummy snapin should implement all 3 persist interfaces
  25. // or None. So let us implement none.
  26. //
  27. //--------------------------------------------------------------------
  28. class CDummySnapinCD :
  29. public IComponentData,
  30. public CComObjectRoot
  31. {
  32. public:
  33. // ATL Maps
  34. DECLARE_NOT_AGGREGATABLE(CDummySnapinCD)
  35. BEGIN_COM_MAP(CDummySnapinCD)
  36. COM_INTERFACE_ENTRY(IComponentData)
  37. COM_INTERFACE_ENTRY_IID(IID_CDummySnapinCD, CDummySnapinCD)
  38. END_COM_MAP()
  39. CDummySnapinCD() : m_eReason(eNoReason) {}
  40. ~CDummySnapinCD() {}
  41. // IComponentData interface members
  42. STDMETHOD(Initialize)(LPUNKNOWN pUnknown);
  43. STDMETHOD(CreateComponent)(LPCOMPONENT* ppComponent);
  44. STDMETHOD(Notify)(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  45. STDMETHOD(Destroy)();
  46. STDMETHOD(QueryDataObject)(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT* ppDataObject);
  47. STDMETHOD(GetDisplayInfo)(SCOPEDATAITEM* pScopeDataItem);
  48. STDMETHOD(CompareObjects)(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  49. void SetDummyCreateReason(EDummyCreateReason eReason) { m_eReason = eReason; }
  50. EDummyCreateReason GetDummyCreateReason() const { return m_eReason;}
  51. const CLSID& GetFailedSnapinCLSID() { return m_clsid;}
  52. void SetFailedSnapinCLSID(const CLSID& clsid) { m_clsid = clsid; }
  53. private:
  54. EDummyCreateReason m_eReason; // Reason for dummy creation.
  55. CLSID m_clsid; // Class ID of the snapin that could not be created.
  56. };
  57. DEFINE_COM_SMARTPTR(CDummySnapinCD); // CDummySnapinCDPtr
  58. //+-------------------------------------------------------------------
  59. //
  60. // Class: CDataObject
  61. //
  62. // Purpose: Dummy snapin's IDataObject implementation.
  63. //
  64. //--------------------------------------------------------------------
  65. class CDataObject:
  66. public IDataObject,
  67. public CComObjectRoot
  68. {
  69. public:
  70. // ATL Maps
  71. DECLARE_NOT_AGGREGATABLE(CDataObject)
  72. BEGIN_COM_MAP(CDataObject)
  73. COM_INTERFACE_ENTRY(IDataObject)
  74. END_COM_MAP()
  75. CDataObject();
  76. ~CDataObject() {}
  77. // IDataObject overrides
  78. STDMETHOD(GetDataHere) (FORMATETC *pformatetc, STGMEDIUM *pmedium);
  79. // Not Implemented
  80. private:
  81. STDMETHOD(GetData)(LPFORMATETC lpFormatetcIn, LPSTGMEDIUM lpMedium)
  82. { return E_NOTIMPL; };
  83. STDMETHOD(EnumFormatEtc)(DWORD dwDirection, LPENUMFORMATETC* ppEnumFormatEtc)
  84. { return E_NOTIMPL; };
  85. STDMETHOD(QueryGetData)(LPFORMATETC lpFormatetc)
  86. { return E_NOTIMPL; };
  87. STDMETHOD(GetCanonicalFormatEtc)(LPFORMATETC lpFormatetcIn, LPFORMATETC lpFormatetcOut)
  88. { return E_NOTIMPL; };
  89. STDMETHOD(SetData)(LPFORMATETC lpFormatetc, LPSTGMEDIUM lpMedium, BOOL bRelease)
  90. { return E_NOTIMPL; };
  91. STDMETHOD(DAdvise)(LPFORMATETC lpFormatetc, DWORD advf, LPADVISESINK pAdvSink, LPDWORD pdwConnection)
  92. { return E_NOTIMPL; };
  93. STDMETHOD(DUnadvise)(DWORD dwConnection)
  94. { return E_NOTIMPL; };
  95. STDMETHOD(EnumDAdvise)(LPENUMSTATDATA* ppEnumAdvise)
  96. { return E_NOTIMPL; };
  97. public:
  98. static UINT s_cfInternal; // Our custom clipboard format
  99. static UINT s_cfDisplayName; // Our test for a node
  100. static UINT s_cfNodeType;
  101. static UINT s_cfSnapinClsid;
  102. };
  103. //+-------------------------------------------------------------------
  104. //
  105. // Class: CDummySnapinC
  106. //
  107. // Purpose: Dummy snapin's IComponent implementation.
  108. //
  109. //--------------------------------------------------------------------
  110. class CDummySnapinC:
  111. public IComponent,
  112. public CComObjectRoot
  113. {
  114. private:
  115. LPCONSOLE m_pConsole;
  116. CDummySnapinCD* m_pComponentData;
  117. public:
  118. void SetComponentData(CDummySnapinCD* pCompData)
  119. {
  120. m_pComponentData = pCompData;
  121. }
  122. public:
  123. // ATL Maps
  124. DECLARE_NOT_AGGREGATABLE(CDummySnapinC)
  125. BEGIN_COM_MAP(CDummySnapinC)
  126. COM_INTERFACE_ENTRY(IComponent)
  127. END_COM_MAP()
  128. CDummySnapinC() :m_pConsole(NULL), m_pComponentData(NULL) {}
  129. ~CDummySnapinC() {}
  130. //
  131. // IComponent interface members
  132. //
  133. STDMETHOD(Initialize) (LPCONSOLE lpConsole);
  134. STDMETHOD(Notify) (LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  135. STDMETHOD(Destroy) (MMC_COOKIE cookie);
  136. STDMETHOD(GetResultViewType) (MMC_COOKIE cookie, LPOLESTR* ppViewType, long* pViewOptions);
  137. STDMETHOD(QueryDataObject) (MMC_COOKIE cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT* ppDataObject);
  138. STDMETHOD(GetDisplayInfo) (RESULTDATAITEM* pResultDataItem);
  139. STDMETHOD(CompareObjects) (LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  140. };
  141. //+-------------------------------------------------------------------
  142. //
  143. // Member: ScCreateDummySnapin
  144. //
  145. // Synopsis: Create a dummy snapin.
  146. //
  147. // Arguments: [ppICD] - Ptr to dummy snapins IComponentData.
  148. // [eReason] - Reason for creating dummy snapin.
  149. // [clsid] - Class ID of the snapin that could not be created.
  150. //
  151. //--------------------------------------------------------------------
  152. SC ScCreateDummySnapin (IComponentData ** ppICD, EDummyCreateReason eReason, const CLSID& clsid)
  153. {
  154. DECLARE_SC(sc, TEXT("ScCreateDummySnapin"));
  155. sc = ScCheckPointers(ppICD);
  156. if(sc)
  157. return sc;
  158. ASSERT(eNoReason != eReason);
  159. *ppICD = NULL;
  160. CComObject<CDummySnapinCD>* pDummySnapinCD;
  161. sc = CComObject<CDummySnapinCD>::CreateInstance (&pDummySnapinCD);
  162. if (sc)
  163. return sc;
  164. if (NULL == pDummySnapinCD)
  165. return (sc = E_UNEXPECTED);
  166. pDummySnapinCD->SetDummyCreateReason(eReason);
  167. pDummySnapinCD->SetFailedSnapinCLSID(clsid);
  168. IComponentDataPtr spComponentData = pDummySnapinCD;
  169. if(spComponentData == NULL)
  170. {
  171. delete pDummySnapinCD;
  172. return (sc = E_UNEXPECTED);
  173. }
  174. *ppICD = spComponentData;
  175. if(NULL == *ppICD)
  176. {
  177. delete pDummySnapinCD;
  178. return (sc = E_UNEXPECTED);
  179. }
  180. (*ppICD)->AddRef(); //addref for client
  181. return sc;
  182. }
  183. //+-------------------------------------------------------------------
  184. //
  185. // Member: ReportSnapinInitFailure
  186. //
  187. // Synopsis: Get the name of the snapin provided class id.
  188. //
  189. // Arguments: [strClsid] - Class id of the snapin.
  190. // [szName] - Name of the snapin.
  191. //
  192. //--------------------------------------------------------------------
  193. void ReportSnapinInitFailure(const CLSID& clsid)
  194. {
  195. DECLARE_SC(sc, _T("ReportSnapinInitFailure"));
  196. // snapin name
  197. CStr strMessage;
  198. strMessage.LoadString(GetStringModule(), IDS_SNAPIN_FAILED_INIT_NAME);
  199. CCoTaskMemPtr<WCHAR> spszClsid;
  200. sc = StringFromCLSID(clsid, &spszClsid);
  201. if (sc)
  202. return;
  203. USES_CONVERSION;
  204. tstring strSnapName;
  205. bool bSuccess = GetSnapinNameFromCLSID(clsid, strSnapName);
  206. if (false == bSuccess)
  207. {
  208. TraceError(_T("GetSnapinName call in ReportSnapinInitFailure failed."), sc);
  209. // signal unknown name of snapin and continue
  210. if ( !strSnapName.LoadString( GetStringModule(), IDS_UnknownSnapinName ) )
  211. strSnapName = _T("<unknown>");
  212. }
  213. strMessage += strSnapName.data();
  214. // clsid
  215. CStr strClsid2;
  216. strClsid2.LoadString(GetStringModule(), IDS_SNAPIN_FAILED_INIT_CLSID);
  217. strClsid2 += OLE2T(spszClsid);
  218. // construct the error message
  219. CStr strError;
  220. strError.LoadString(GetStringModule(), IDS_SNAPIN_FAILED_INIT);
  221. strError += strMessage;
  222. strError += strClsid2;
  223. MMCErrorBox(strError, MB_OK|MB_TASKMODAL);
  224. return;
  225. }
  226. //+-------------------------------------------------------------------
  227. //
  228. // Member: CDummySnapinCD::Initialize
  229. //
  230. // Synopsis: Does nothing.
  231. //
  232. // Arguments: [pUnknown] - IConsole2 ptr.
  233. //
  234. //--------------------------------------------------------------------
  235. HRESULT CDummySnapinCD::Initialize (LPUNKNOWN pUnknown)
  236. { return S_OK; }
  237. //+-------------------------------------------------------------------
  238. //
  239. // Member: CDummySnapinCD::CreateComponent
  240. //
  241. // Synopsis: Creates a CDummySnapinC object.
  242. //
  243. // Arguments: [ppComponent] - Ptr to created component.
  244. //
  245. //--------------------------------------------------------------------
  246. HRESULT CDummySnapinCD::CreateComponent (LPCOMPONENT* ppComponent)
  247. {
  248. SC sc = E_FAIL;
  249. CComObject<CDummySnapinC>* pDummySnapinC;
  250. sc = CComObject<CDummySnapinC>::CreateInstance (&pDummySnapinC);
  251. if (sc)
  252. goto Error;
  253. if (NULL == pDummySnapinC)
  254. goto Error;
  255. pDummySnapinC->SetComponentData(this);
  256. sc = pDummySnapinC->QueryInterface(IID_IComponent, reinterpret_cast<void**>(ppComponent));
  257. Cleanup:
  258. return HrFromSc(sc);
  259. Error:
  260. TraceError(TEXT("CDummySnapinCD::CreateComponent"), sc);
  261. goto Cleanup;
  262. }
  263. //+-------------------------------------------------------------------
  264. //
  265. // Member: CDummySnapinCD::Notify
  266. //
  267. // Synopsis: Right now does not handle any events.
  268. //
  269. // Arguments: [lpDataObject] - Ptr to created component.
  270. // [event] - Event type.
  271. // [arg, param) - event specific data.
  272. //
  273. //--------------------------------------------------------------------
  274. HRESULT CDummySnapinCD::Notify (LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  275. {
  276. return S_OK;
  277. }
  278. //+-------------------------------------------------------------------
  279. //
  280. // Member: CDummySnapinCD::Destroy
  281. //
  282. // Synopsis: Right now does nothing to destroy.
  283. //
  284. // Arguments: None
  285. //
  286. //--------------------------------------------------------------------
  287. HRESULT CDummySnapinCD::Destroy ()
  288. { return S_OK; }
  289. //+-------------------------------------------------------------------
  290. //
  291. // Member: CDummySnapinCD::QuertDataObject
  292. //
  293. // Synopsis: Get IDataObject.
  294. //
  295. // Arguments: [cookie] - Snapin specific data.
  296. // [type] - data obj type, Scope/Result/Snapin mgr...
  297. // [ppDataObject] - IDataObject ptr.
  298. //
  299. //--------------------------------------------------------------------
  300. HRESULT CDummySnapinCD::QueryDataObject (MMC_COOKIE cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT* ppDataObject)
  301. {
  302. SC sc = E_FAIL;
  303. CComObject<CDataObject>* pDataObject;
  304. sc = CComObject<CDataObject>::CreateInstance (&pDataObject);
  305. if (sc)
  306. goto Error;
  307. if (NULL == pDataObject)
  308. goto Error;
  309. sc = pDataObject->QueryInterface(IID_IDataObject, reinterpret_cast<void**>(ppDataObject));
  310. Cleanup:
  311. return HrFromSc(sc);
  312. Error:
  313. TraceError(TEXT("CDummySnapinCD::QueryDataObject"), sc);
  314. goto Cleanup;
  315. }
  316. //+-------------------------------------------------------------------
  317. //
  318. // Member: CDummySnapinCD::GetDisplayInfo
  319. //
  320. // Synopsis: Display info call back.
  321. // (Right now there is nothing to display, no enumerated item).
  322. //
  323. // Arguments: [pScopeDataItem] - Snapin should fill this struct for Display info.
  324. //
  325. //--------------------------------------------------------------------
  326. HRESULT CDummySnapinCD::GetDisplayInfo (SCOPEDATAITEM* pScopeDataItem)
  327. { return S_OK; }
  328. //+-------------------------------------------------------------------
  329. //
  330. // Member: CDummySnapinCD::CompareObjects
  331. //
  332. // Synopsis: Used for sort / find prop sheet...
  333. // (Right now do nothing as we have only one item).
  334. //
  335. // Arguments: [lpDataObjectA] - IDataObject of first item.
  336. // [lpDataObjectB] - IDataObject of second item.
  337. //
  338. //--------------------------------------------------------------------
  339. HRESULT CDummySnapinCD::CompareObjects (LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB)
  340. { return S_OK; }
  341. #define MY_CF_SNAPIN_INTERNAL L"DUMMY SNAPIN"
  342. // global(s)
  343. const GUID GUID_DummyNode = {
  344. 0x82c37899,
  345. 0x7808,
  346. 0x11d1,
  347. {0xa1, 0x90, 0x00, 0x00, 0xf8, 0x75, 0xb1, 0x32}
  348. };
  349. // statics
  350. UINT CDataObject::s_cfInternal = 0;
  351. UINT CDataObject::s_cfDisplayName = 0;
  352. UINT CDataObject::s_cfNodeType = 0;
  353. UINT CDataObject::s_cfSnapinClsid = 0;
  354. CDataObject::CDataObject()
  355. {
  356. USES_CONVERSION;
  357. s_cfInternal = RegisterClipboardFormat (W2T(MY_CF_SNAPIN_INTERNAL));
  358. s_cfDisplayName = RegisterClipboardFormat (W2T(CCF_DISPLAY_NAME));
  359. s_cfNodeType = RegisterClipboardFormat (W2T(CCF_NODETYPE));
  360. s_cfSnapinClsid = RegisterClipboardFormat (W2T(CCF_SNAPIN_CLASSID));
  361. }
  362. //+-------------------------------------------------------------------
  363. //
  364. // Member: CDataObject::GetDataHere
  365. //
  366. // Synopsis: IDataObject::GetDataHere.
  367. //
  368. // Arguments: [pformatetc]
  369. // [pmedium]
  370. //
  371. //--------------------------------------------------------------------
  372. HRESULT CDataObject::GetDataHere (FORMATETC *pformatetc, STGMEDIUM *pmedium)
  373. {
  374. SC sc = DV_E_FORMATETC;
  375. IStream * pstm = NULL;
  376. sc = CreateStreamOnHGlobal (pmedium->hGlobal, FALSE, &pstm);
  377. if (pstm) {
  378. const CLIPFORMAT cf = pformatetc->cfFormat;
  379. if (cf == s_cfDisplayName) {
  380. LPTSTR pszName = _T("Display Manager (Version 2)");
  381. sc = pstm->Write (pszName, sizeof(TCHAR)*(1+_tcslen (pszName)), NULL);
  382. } else
  383. if (cf == s_cfInternal) {
  384. CDataObject * pThis = this;
  385. sc = pstm->Write (pThis, sizeof(CDataObject *), NULL);
  386. } else
  387. if (cf == s_cfNodeType) {
  388. const GUID * pguid;
  389. pguid = &GUID_DummyNode;
  390. sc = pstm->Write ((PVOID)pguid, sizeof(GUID), NULL);
  391. } else
  392. if (cf == s_cfSnapinClsid) {
  393. sc = pstm->Write (&CLSID_Dummy, sizeof(CLSID_Dummy), NULL);
  394. } else {
  395. sc = DV_E_FORMATETC;
  396. // don't ASSERT
  397. // _ASSERT(hresult == S_OK);
  398. }
  399. pstm->Release();
  400. }
  401. return HrFromSc(sc);
  402. }
  403. //+-------------------------------------------------------------------
  404. //
  405. // Member: CDummySnapinC::Initialize
  406. //
  407. // Synopsis: Just store given ICOnsole2.
  408. //
  409. // Arguments: [lpConsole] - IConsole2 ptr.
  410. //
  411. //--------------------------------------------------------------------
  412. HRESULT CDummySnapinC::Initialize (LPCONSOLE lpConsole)
  413. {
  414. m_pConsole = lpConsole;
  415. if (m_pConsole)
  416. m_pConsole->AddRef();
  417. return S_OK;
  418. }
  419. //+-------------------------------------------------------------------
  420. //
  421. // Member: CDummySnapinC::Notify
  422. //
  423. // Synopsis: Right now handle only MMCN_SHOW to display
  424. // IMessageView with failure message.
  425. //
  426. // Arguments: [lpDataObject] - Ptr to created component.
  427. // [event] - Event type.
  428. // [arg, param) - event specific data.
  429. //
  430. //--------------------------------------------------------------------
  431. HRESULT CDummySnapinC::Notify (LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  432. {
  433. DECLARE_SC(sc, _T("CDummySnapinC::Notify"));
  434. sc = S_FALSE; // Default ret val.
  435. switch(event)
  436. {
  437. case MMCN_SHOW: // Display error message during MMCN_SHOW, TRUE.
  438. {
  439. if (FALSE == arg)
  440. break;
  441. // First get the IUnknown of Result Pane.
  442. LPUNKNOWN lpUnkn = NULL;
  443. sc = m_pConsole->QueryResultView(&lpUnkn);
  444. if (sc)
  445. return sc.ToHr();
  446. // Now get the message view.
  447. IMessageViewPtr spMessageView;
  448. sc = lpUnkn->QueryInterface(IID_IMessageView, reinterpret_cast<void**>(&spMessageView));
  449. lpUnkn->Release();
  450. if (sc)
  451. return sc.ToHr();
  452. // Got the message view, not set the title and text.
  453. CStr strTempForLoading; // Temp object for loading string from resources.
  454. sc = spMessageView->Clear();
  455. if (sc)
  456. return sc.ToHr();
  457. strTempForLoading.LoadString(GetStringModule(), IDS_SNAPIN_CREATE_FAILED);
  458. USES_CONVERSION;
  459. sc = spMessageView->SetTitleText( T2OLE((LPTSTR)(LPCTSTR)strTempForLoading));
  460. if (sc)
  461. return sc.ToHr();
  462. sc = spMessageView->SetIcon(Icon_Error);
  463. if (sc)
  464. return sc.ToHr();
  465. //////////////////////////////////
  466. // The body text is as follows //
  467. // Reason. //
  468. // Snapin Name. //
  469. // Snapin Class ID. //
  470. //////////////////////////////////
  471. tstring szBodyText; // Body text for message view.
  472. if (m_pComponentData->GetDummyCreateReason() == eSnapPolicyFailed)
  473. strTempForLoading.LoadString(GetStringModule(), IDS_SNAPIN_POLICYFAILURE);
  474. else
  475. strTempForLoading.LoadString(GetStringModule(), IDS_SNAPIN_FAILED);
  476. // Reason for failure.
  477. szBodyText = strTempForLoading + _T('\n');
  478. // Snapin name.
  479. CStr strSnapName;
  480. strTempForLoading.LoadString(GetStringModule(), IDS_SNAPIN_FAILED_INIT_NAME);
  481. szBodyText += strTempForLoading;
  482. CCoTaskMemPtr<WCHAR> spszClsid;
  483. sc = StringFromCLSID(m_pComponentData->GetFailedSnapinCLSID(), &spszClsid);
  484. if (sc)
  485. return sc.ToHr();
  486. // Get the snapin name.
  487. tstring szSnapinName;
  488. bool bSucc = GetSnapinNameFromCLSID(m_pComponentData->GetFailedSnapinCLSID(), szSnapinName);
  489. if (false == bSucc)
  490. {
  491. sc = E_FAIL;
  492. TraceError(_T("GetSnapinName call in CDummySnapinC::Notify failed."), sc);
  493. return sc.ToHr();
  494. }
  495. szBodyText += szSnapinName;
  496. szBodyText += _T("\n");
  497. // Now add the snapin class id.
  498. strTempForLoading.LoadString(GetStringModule(), IDS_SNAPIN_FAILED_INIT_CLSID);
  499. szBodyText += strTempForLoading;
  500. szBodyText += OLE2T(spszClsid);
  501. sc = spMessageView->SetBodyText( T2COLE(szBodyText.data()));
  502. }
  503. break;
  504. default:
  505. break;
  506. }
  507. return sc.ToHr();
  508. }
  509. //+-------------------------------------------------------------------
  510. //
  511. // Member: CDummySnapinC::Destroy
  512. //
  513. // Synopsis: Release the cached IConsole2 ptr.
  514. //
  515. // Arguments: None
  516. //
  517. //--------------------------------------------------------------------
  518. HRESULT CDummySnapinC::Destroy (MMC_COOKIE cookie)
  519. {
  520. if (m_pConsole)
  521. m_pConsole->Release();
  522. return S_OK;
  523. }
  524. //+-------------------------------------------------------------------
  525. //
  526. // Member: CDummySnapinC::GetResultViewType
  527. //
  528. // Synopsis: Specify the message view as result view type.
  529. //
  530. // Arguments: [cookie] - Snapin supplied param.
  531. // [ppViewType] - View Name (OCX - GUID, WEB - URL name).
  532. // [pViewOptions] - View options
  533. //
  534. //--------------------------------------------------------------------
  535. HRESULT CDummySnapinC::GetResultViewType (MMC_COOKIE cookie, LPOLESTR* ppViewType, long* pViewOptions)
  536. {
  537. SC sc;
  538. TCHAR szBuffer[MAX_PATH * 2];
  539. int cchBuffer = MAX_PATH * 2;
  540. // We want to display the error message using the message view.
  541. LPOLESTR lpClsid = NULL;
  542. sc = StringFromCLSID(CLSID_MessageView, &lpClsid);
  543. USES_CONVERSION;
  544. if (!sc.IsError())
  545. {
  546. // Use the message view to display error message.
  547. sc = StringCchCopy(szBuffer, cchBuffer, OLE2T(lpClsid));
  548. if(sc)
  549. goto Error;
  550. ::CoTaskMemFree(lpClsid);
  551. }
  552. else
  553. {
  554. // Conversion failed, display default error page.
  555. sc = StringCchCopy (szBuffer, cchBuffer, _T("res://"));
  556. if(sc)
  557. goto Error;
  558. ::GetModuleFileName (NULL, szBuffer + _tcslen(szBuffer), cchBuffer - _tcslen(szBuffer));
  559. sc = StringCchCat (szBuffer, cchBuffer, _T("/error.htm"));
  560. if(sc)
  561. goto Error;
  562. }
  563. int cchViewType = 1+_tcslen(szBuffer);
  564. *ppViewType = (OLECHAR *)::CoTaskMemAlloc (sizeof(OLECHAR)*cchViewType);
  565. if (!*ppViewType)
  566. {
  567. sc = E_OUTOFMEMORY;
  568. goto Error;
  569. }
  570. sc = StringCchCopyW (*ppViewType, cchViewType, T2OLE(szBuffer));
  571. if(sc)
  572. goto Error;
  573. Cleanup:
  574. return HrFromSc(sc);
  575. Error:
  576. TraceError(TEXT("CDummySnapinC::GetResultViewType"), sc);
  577. goto Cleanup;
  578. }
  579. //+-------------------------------------------------------------------
  580. //
  581. // Member: CDummySnapinC::QuertDataObject
  582. //
  583. // Synopsis: Get IDataObject.
  584. //
  585. // Arguments: [cookie] - Snapin specific data.
  586. // [type] - data obj type, Scope/Result/Snapin mgr...
  587. // [ppDataObject] - IDataObject ptr.
  588. //
  589. //--------------------------------------------------------------------
  590. HRESULT CDummySnapinC::QueryDataObject (MMC_COOKIE cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT* ppDataObject)
  591. {
  592. SC sc = E_FAIL;
  593. CComObject<CDataObject>* pDataObject;
  594. sc = CComObject<CDataObject>::CreateInstance (&pDataObject);
  595. if (sc)
  596. goto Error;
  597. if (NULL == pDataObject)
  598. goto Error;
  599. sc = pDataObject->QueryInterface(IID_IDataObject, reinterpret_cast<void**>(ppDataObject));
  600. Cleanup:
  601. return HrFromSc(sc);
  602. Error:
  603. TraceError(TEXT("CDummySnapinC::QueryDataObject"), sc);
  604. goto Cleanup;
  605. }
  606. //+-------------------------------------------------------------------
  607. //
  608. // Member: CDummySnapinC::GetDisplayInfo
  609. //
  610. // Synopsis: Display info call back.
  611. // (Right now there is nothing to display, no result items).
  612. //
  613. // Arguments: [pResultDataItem] - Snapin should fill this struct for Display info.
  614. //
  615. //--------------------------------------------------------------------
  616. HRESULT CDummySnapinC::GetDisplayInfo (RESULTDATAITEM* pResultDataItem)
  617. { return S_OK; }
  618. //+-------------------------------------------------------------------
  619. //
  620. // Member: CDummySnapinC::CompareObjects
  621. //
  622. // Synopsis: Used for sort / find prop sheet...
  623. // (Right now do nothing as we dont have any result items).
  624. //
  625. // Arguments: [lpDataObjectA] - IDataObject of first item.
  626. // [lpDataObjectB] - IDataObject of second item.
  627. //
  628. //--------------------------------------------------------------------
  629. HRESULT CDummySnapinC::CompareObjects (LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB)
  630. { return S_OK; }
  631. #include "scopndcb.h"
  632. //+-------------------------------------------------------------------
  633. //
  634. // Member: CNodeCallback::IsDummySnapin
  635. //
  636. // Synopsis: Given the node see if it is dummy snapin.
  637. //
  638. // Arguments: [hNode] - [in] Node selection context.
  639. // [bDummySnapin] - [out] Is this dummy snapin?
  640. //
  641. // Returns: SC
  642. //
  643. //--------------------------------------------------------------------
  644. HRESULT CNodeCallback::IsDummySnapin (/*[in]*/HNODE hNode, /*[out]*/bool& bDummySnapin)
  645. {
  646. DECLARE_SC(sc, _T("CNodeCallback::IsDummySnapin"));
  647. sc = ScCheckPointers( (void*) hNode);
  648. if (sc)
  649. return sc.ToHr();
  650. bDummySnapin = false;
  651. CNode *pNode = CNode::FromHandle(hNode);
  652. sc = ScCheckPointers(pNode, E_UNEXPECTED);
  653. if (sc)
  654. return sc.ToHr();
  655. CMTNode *pMTNode = pNode->GetMTNode();
  656. sc = ScCheckPointers(pMTNode, E_UNEXPECTED);
  657. if (sc)
  658. return sc.ToHr();
  659. CComponentData *pComponentData = pMTNode->GetPrimaryComponentData();
  660. sc = ScCheckPointers(pComponentData, E_UNEXPECTED);
  661. if (sc)
  662. return sc.ToHr();
  663. IComponentData* pIComponentData = pComponentData->GetIComponentData();
  664. sc = ScCheckPointers(pIComponentData, E_UNEXPECTED);
  665. if (sc)
  666. return sc.ToHr();
  667. CDummySnapinCDPtr spDummyCD = pIComponentData;
  668. if (spDummyCD)
  669. bDummySnapin = true;
  670. return (sc.ToHr());
  671. }