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.

574 lines
14 KiB

  1. #include "main.h"
  2. ///////////////////////////////////////////////////////////////////////////////
  3. // //
  4. // CComponentData object implementation //
  5. // //
  6. ///////////////////////////////////////////////////////////////////////////////
  7. CComponentData::CComponentData()
  8. {
  9. m_cRef = 1;
  10. InterlockedIncrement(&g_cRefThisDll);
  11. m_hwndFrame = NULL;
  12. m_pScope = NULL;
  13. m_pConsole = NULL;
  14. m_hRoot = NULL;
  15. m_pGPTInformation = NULL;
  16. }
  17. CComponentData::~CComponentData()
  18. {
  19. if (m_pScope)
  20. {
  21. m_pScope->Release();
  22. }
  23. if (m_pConsole)
  24. {
  25. m_pConsole->Release();
  26. }
  27. if (m_pGPTInformation)
  28. {
  29. m_pGPTInformation->Release();
  30. }
  31. InterlockedDecrement(&g_cRefThisDll);
  32. }
  33. ///////////////////////////////////////////////////////////////////////////////
  34. // //
  35. // CComponentData object implementation (IUnknown) //
  36. // //
  37. ///////////////////////////////////////////////////////////////////////////////
  38. HRESULT CComponentData::QueryInterface (REFIID riid, void **ppv)
  39. {
  40. if (IsEqualIID(riid, IID_IComponentData) || IsEqualIID(riid, IID_IUnknown))
  41. {
  42. *ppv = (LPCOMPONENT)this;
  43. m_cRef++;
  44. return S_OK;
  45. }
  46. else if (IsEqualIID(riid, IID_IPersistStreamInit))
  47. {
  48. *ppv = (LPPERSISTSTREAMINIT)this;
  49. m_cRef++;
  50. return S_OK;
  51. }
  52. else
  53. {
  54. *ppv = NULL;
  55. return E_NOINTERFACE;
  56. }
  57. }
  58. ULONG CComponentData::AddRef (void)
  59. {
  60. return ++m_cRef;
  61. }
  62. ULONG CComponentData::Release (void)
  63. {
  64. if (--m_cRef == 0) {
  65. delete this;
  66. return 0;
  67. }
  68. return m_cRef;
  69. }
  70. ///////////////////////////////////////////////////////////////////////////////
  71. // //
  72. // CComponentData object implementation (IComponentData) //
  73. // //
  74. ///////////////////////////////////////////////////////////////////////////////
  75. STDMETHODIMP CComponentData::Initialize(LPUNKNOWN pUnknown)
  76. {
  77. HRESULT hr;
  78. HBITMAP bmp16x16;
  79. LPIMAGELIST lpScopeImage;
  80. //
  81. // QI for IConsoleNameSpace
  82. //
  83. hr = pUnknown->QueryInterface(IID_IConsoleNameSpace, (LPVOID *)&m_pScope);
  84. if (FAILED(hr))
  85. {
  86. DebugMsg((DM_WARNING, TEXT("CComponentData::Initialize: Failed to QI for IConsoleNameSpace.")));
  87. return hr;
  88. }
  89. //
  90. // QI for IConsole
  91. //
  92. hr = pUnknown->QueryInterface(IID_IConsole, (LPVOID *)&m_pConsole);
  93. if (FAILED(hr))
  94. {
  95. DebugMsg((DM_WARNING, TEXT("CComponentData::Initialize: Failed to QI for IConsole.")));
  96. m_pScope->Release();
  97. m_pScope = NULL;
  98. return hr;
  99. }
  100. m_pConsole->GetMainWindow (&m_hwndFrame);
  101. //
  102. // Query for the scope imagelist interface
  103. //
  104. hr = m_pConsole->QueryScopeImageList(&lpScopeImage);
  105. if (FAILED(hr))
  106. {
  107. DebugMsg((DM_WARNING, TEXT("CComponentData::Initialize: Failed to QI for scope imagelist.")));
  108. m_pScope->Release();
  109. m_pScope = NULL;
  110. m_pConsole->Release();
  111. m_pConsole=NULL;
  112. return hr;
  113. }
  114. // Load the bitmaps from the dll
  115. bmp16x16=LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_16x16));
  116. // Set the images
  117. lpScopeImage->ImageListSetStrip(reinterpret_cast<long*>(bmp16x16),
  118. reinterpret_cast<long*>(bmp16x16),
  119. 0, RGB(255, 0, 255));
  120. lpScopeImage->Release();
  121. return S_OK;
  122. }
  123. STDMETHODIMP CComponentData::Destroy(VOID)
  124. {
  125. return S_OK;
  126. }
  127. STDMETHODIMP CComponentData::CreateComponent(LPCOMPONENT *ppComponent)
  128. {
  129. HRESULT hr;
  130. CSnapIn *pSnapIn;
  131. DebugMsg((DM_VERBOSE, TEXT("CComponentData::CreateComponent: Entering.")));
  132. //
  133. // Initialize
  134. //
  135. *ppComponent = NULL;
  136. //
  137. // Create the snapin view
  138. //
  139. pSnapIn = new CSnapIn(this);
  140. if (!pSnapIn)
  141. {
  142. DebugMsg((DM_WARNING, TEXT("CComponentData::CreateComponent: Failed to create CSnapIn.")));
  143. return E_OUTOFMEMORY;
  144. }
  145. //
  146. // QI for IComponent
  147. //
  148. hr = pSnapIn->QueryInterface(IID_IComponent, (LPVOID *)ppComponent);
  149. pSnapIn->Release(); // release QI
  150. return hr;
  151. }
  152. STDMETHODIMP CComponentData::QueryDataObject(long cookie, DATA_OBJECT_TYPES type,
  153. LPDATAOBJECT* ppDataObject)
  154. {
  155. HRESULT hr = E_NOINTERFACE;
  156. CDataObject *pDataObject;
  157. LPGPTDATAOBJECT pGPTDataObject;
  158. //
  159. // Create a new DataObject
  160. //
  161. pDataObject = new CDataObject(this); // ref == 1
  162. if (!pDataObject)
  163. return E_OUTOFMEMORY;
  164. //
  165. // QI for the private GPTDataObject interface so we can set the cookie
  166. // and type information.
  167. //
  168. hr = pDataObject->QueryInterface(IID_IGPTDataObject, (LPVOID *)&pGPTDataObject);
  169. if (FAILED(hr))
  170. {
  171. pDataObject->Release();
  172. return (hr);
  173. }
  174. pGPTDataObject->SetType(type);
  175. pGPTDataObject->SetCookie(cookie);
  176. pGPTDataObject->Release();
  177. //
  178. // QI for a normal IDataObject to return.
  179. //
  180. hr = pDataObject->QueryInterface(IID_IDataObject, (LPVOID *)ppDataObject);
  181. pDataObject->Release(); // release initial ref
  182. return hr;
  183. }
  184. STDMETHODIMP CComponentData::Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, long arg, long param)
  185. {
  186. HRESULT hr = S_OK;
  187. switch(event)
  188. {
  189. case MMCN_EXPAND:
  190. if (arg == TRUE)
  191. if (!m_pGPTInformation)
  192. {
  193. lpDataObject->QueryInterface(IID_IGPEInformation, (LPVOID *)&m_pGPTInformation);
  194. }
  195. if (m_pGPTInformation)
  196. {
  197. hr = EnumerateScopePane(lpDataObject, (HSCOPEITEM)param);
  198. }
  199. break;
  200. default:
  201. break;
  202. }
  203. return hr;
  204. }
  205. STDMETHODIMP CComponentData::GetDisplayInfo(LPSCOPEDATAITEM pItem)
  206. {
  207. DWORD dwIndex;
  208. if (pItem == NULL)
  209. return E_POINTER;
  210. for (dwIndex = 0; dwIndex < NUM_NAMESPACE_ITEMS; dwIndex++)
  211. {
  212. if (g_NameSpace[dwIndex].dwID == (DWORD) pItem->lParam)
  213. break;
  214. }
  215. if (dwIndex == NUM_NAMESPACE_ITEMS)
  216. pItem->displayname = NULL;
  217. else
  218. {
  219. pItem->displayname = g_NameSpace[dwIndex].szDisplayName;
  220. }
  221. return S_OK;
  222. }
  223. STDMETHODIMP CComponentData::CompareObjects(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB)
  224. {
  225. HRESULT hr = S_FALSE;
  226. LPGPTDATAOBJECT pGPTDataObjectA, pGPTDataObjectB;
  227. LONG cookie1, cookie2;
  228. if (lpDataObjectA == NULL || lpDataObjectB == NULL)
  229. return E_POINTER;
  230. //
  231. // QI for the private GPTDataObject interface
  232. //
  233. if (FAILED(lpDataObjectA->QueryInterface(IID_IGPTDataObject,
  234. (LPVOID *)&pGPTDataObjectA)))
  235. {
  236. return S_FALSE;
  237. }
  238. if (FAILED(lpDataObjectB->QueryInterface(IID_IGPTDataObject,
  239. (LPVOID *)&pGPTDataObjectB)))
  240. {
  241. pGPTDataObjectA->Release();
  242. return S_FALSE;
  243. }
  244. pGPTDataObjectA->GetCookie(&cookie1);
  245. pGPTDataObjectB->GetCookie(&cookie2);
  246. if (cookie1 == cookie2)
  247. {
  248. hr = S_OK;
  249. }
  250. pGPTDataObjectA->Release();
  251. pGPTDataObjectB->Release();
  252. return hr;
  253. }
  254. ///////////////////////////////////////////////////////////////////////////////
  255. // //
  256. // CComponentData object implementation (IPersistStreamInit) //
  257. // //
  258. ///////////////////////////////////////////////////////////////////////////////
  259. STDMETHODIMP CComponentData::GetClassID(CLSID *pClassID)
  260. {
  261. if (!pClassID)
  262. {
  263. return E_FAIL;
  264. }
  265. *pClassID = CLSID_GPTDemoSnapIn;
  266. return S_OK;
  267. }
  268. STDMETHODIMP CComponentData::IsDirty(VOID)
  269. {
  270. return S_FALSE;
  271. }
  272. STDMETHODIMP CComponentData::Load(IStream *pStm)
  273. {
  274. return S_OK;
  275. }
  276. STDMETHODIMP CComponentData::Save(IStream *pStm, BOOL fClearDirty)
  277. {
  278. return S_OK;
  279. }
  280. STDMETHODIMP CComponentData::GetSizeMax(ULARGE_INTEGER *pcbSize)
  281. {
  282. DWORD dwSize = 0;
  283. if (!pcbSize)
  284. {
  285. return E_FAIL;
  286. }
  287. ULISet32(*pcbSize, dwSize);
  288. return S_OK;
  289. }
  290. STDMETHODIMP CComponentData::InitNew(void)
  291. {
  292. return S_OK;
  293. }
  294. ///////////////////////////////////////////////////////////////////////////////
  295. // //
  296. // CComponentData object implementation (Internal functions) //
  297. // //
  298. ///////////////////////////////////////////////////////////////////////////////
  299. HRESULT CComponentData::EnumerateScopePane (LPDATAOBJECT lpDataObject, HSCOPEITEM hParent)
  300. {
  301. SCOPEDATAITEM item;
  302. HRESULT hr;
  303. DWORD dwIndex, i;
  304. if (!m_hRoot)
  305. m_hRoot = hParent;
  306. if (m_hRoot == hParent)
  307. dwIndex = 0;
  308. else
  309. {
  310. item.mask = SDI_PARAM;
  311. item.ID = hParent;
  312. hr = m_pScope->GetItem (&item);
  313. if (FAILED(hr))
  314. return hr;
  315. dwIndex = item.lParam;
  316. }
  317. for (i = 0; i < NUM_NAMESPACE_ITEMS; i++)
  318. {
  319. if (g_NameSpace[i].dwParent == dwIndex)
  320. {
  321. item.mask = SDI_STR | SDI_STATE | SDI_IMAGE | SDI_OPENIMAGE | SDI_PARAM | SDI_CHILDREN;
  322. item.displayname = MMC_CALLBACK;
  323. item.nImage = 0;
  324. item.nOpenImage = 1;
  325. item.nState = 0;
  326. item.cChildren = g_NameSpace[i].cChildren;
  327. item.lParam = g_NameSpace[i].dwID;
  328. item.relativeID = hParent;
  329. m_pScope->InsertItem (&item);
  330. }
  331. }
  332. return S_OK;
  333. }
  334. ///////////////////////////////////////////////////////////////////////////////
  335. // //
  336. // Class factory object implementation //
  337. // //
  338. ///////////////////////////////////////////////////////////////////////////////
  339. CComponentDataCF::CComponentDataCF()
  340. {
  341. m_cRef = 1;
  342. InterlockedIncrement(&g_cRefThisDll);
  343. }
  344. CComponentDataCF::~CComponentDataCF()
  345. {
  346. InterlockedDecrement(&g_cRefThisDll);
  347. }
  348. ///////////////////////////////////////////////////////////////////////////////
  349. // //
  350. // Class factory object implementation (IUnknown) //
  351. // //
  352. ///////////////////////////////////////////////////////////////////////////////
  353. STDMETHODIMP_(ULONG)
  354. CComponentDataCF::AddRef()
  355. {
  356. return ++m_cRef;
  357. }
  358. STDMETHODIMP_(ULONG)
  359. CComponentDataCF::Release()
  360. {
  361. if (--m_cRef == 0)
  362. {
  363. delete this;
  364. return 0;
  365. }
  366. return m_cRef;
  367. }
  368. STDMETHODIMP
  369. CComponentDataCF::QueryInterface(REFIID riid, LPVOID FAR* ppv)
  370. {
  371. if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))
  372. {
  373. *ppv = (LPCLASSFACTORY)this;
  374. m_cRef++;
  375. return S_OK;
  376. }
  377. else
  378. {
  379. *ppv = NULL;
  380. return E_NOINTERFACE;
  381. }
  382. }
  383. ///////////////////////////////////////////////////////////////////////////////
  384. // //
  385. // Class factory object implementation (IClassFactory) //
  386. // //
  387. ///////////////////////////////////////////////////////////////////////////////
  388. STDMETHODIMP
  389. CComponentDataCF::CreateInstance(LPUNKNOWN pUnkOuter,
  390. REFIID riid,
  391. LPVOID FAR* ppvObj)
  392. {
  393. *ppvObj = NULL;
  394. if (pUnkOuter)
  395. return CLASS_E_NOAGGREGATION;
  396. CComponentData *pComponentData = new CComponentData(); // ref count == 1
  397. if (!pComponentData)
  398. return E_OUTOFMEMORY;
  399. HRESULT hr = pComponentData->QueryInterface(riid, ppvObj);
  400. pComponentData->Release(); // release initial ref
  401. return hr;
  402. }
  403. STDMETHODIMP
  404. CComponentDataCF::LockServer(BOOL fLock)
  405. {
  406. return E_NOTIMPL;
  407. }
  408. ///////////////////////////////////////////////////////////////////////////////
  409. // //
  410. // Class factory object creation (IClassFactory) //
  411. // //
  412. ///////////////////////////////////////////////////////////////////////////////
  413. HRESULT CreateComponentDataClassFactory (REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  414. {
  415. HRESULT hr;
  416. if (IsEqualCLSID (rclsid, CLSID_GPTDemoSnapIn)) {
  417. CComponentDataCF *pComponentDataCF = new CComponentDataCF(); // ref == 1
  418. if (!pComponentDataCF)
  419. return E_OUTOFMEMORY;
  420. hr = pComponentDataCF->QueryInterface(riid, ppv);
  421. pComponentDataCF->Release(); // release initial ref
  422. return hr;
  423. }
  424. return CLASS_E_CLASSNOTAVAILABLE;
  425. }