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.

513 lines
13 KiB

  1. #include "main.h"
  2. ///////////////////////////////////////////////////////////////////////////////
  3. // //
  4. // CRSOPSnapIn object implementation //
  5. // //
  6. ///////////////////////////////////////////////////////////////////////////////
  7. CRSOPSnapIn::CRSOPSnapIn(CRSOPComponentData *pComponent)
  8. {
  9. m_cRef = 1;
  10. InterlockedIncrement(&g_cRefThisDll);
  11. m_pcd = pComponent;
  12. m_pConsole = NULL;
  13. m_pResult = NULL;
  14. m_pHeader = NULL;
  15. m_pConsoleVerb = NULL;
  16. m_pDisplayHelp = NULL;
  17. m_nColumnSize = 180;
  18. m_lViewMode = LVS_REPORT;
  19. m_bExpand = TRUE;
  20. LoadString(g_hInstance, IDS_NAME, m_column1, ARRAYSIZE(m_column1));
  21. }
  22. CRSOPSnapIn::~CRSOPSnapIn()
  23. {
  24. InterlockedDecrement(&g_cRefThisDll);
  25. }
  26. ///////////////////////////////////////////////////////////////////////////////
  27. // //
  28. // CRSOPSnapIn object implementation (IUnknown) //
  29. // //
  30. ///////////////////////////////////////////////////////////////////////////////
  31. HRESULT CRSOPSnapIn::QueryInterface (REFIID riid, void **ppv)
  32. {
  33. if (IsEqualIID(riid, IID_IComponent) || IsEqualIID(riid, IID_IUnknown))
  34. {
  35. *ppv = (LPCOMPONENT)this;
  36. m_cRef++;
  37. return S_OK;
  38. }
  39. else if (IsEqualIID(riid, IID_IExtendContextMenu))
  40. {
  41. *ppv = (LPEXTENDCONTEXTMENU)this;
  42. m_cRef++;
  43. return S_OK;
  44. }
  45. else
  46. {
  47. *ppv = NULL;
  48. return E_NOINTERFACE;
  49. }
  50. }
  51. ULONG CRSOPSnapIn::AddRef (void)
  52. {
  53. return ++m_cRef;
  54. }
  55. ULONG CRSOPSnapIn::Release (void)
  56. {
  57. if (--m_cRef == 0) {
  58. delete this;
  59. return 0;
  60. }
  61. return m_cRef;
  62. }
  63. ///////////////////////////////////////////////////////////////////////////////
  64. // //
  65. // CRSOPSnapIn object implementation (IComponent) //
  66. // //
  67. ///////////////////////////////////////////////////////////////////////////////
  68. STDMETHODIMP CRSOPSnapIn::Initialize(LPCONSOLE lpConsole)
  69. {
  70. HRESULT hr;
  71. // Save the IConsole pointer
  72. m_pConsole = lpConsole;
  73. m_pConsole->AddRef();
  74. hr = m_pConsole->QueryInterface(IID_IHeaderCtrl,
  75. reinterpret_cast<void**>(&m_pHeader));
  76. // Give the console the header control interface pointer
  77. if (SUCCEEDED(hr))
  78. m_pConsole->SetHeader(m_pHeader);
  79. m_pConsole->QueryInterface(IID_IResultData,
  80. reinterpret_cast<void**>(&m_pResult));
  81. hr = m_pConsole->QueryConsoleVerb(&m_pConsoleVerb);
  82. hr = m_pConsole->QueryInterface(IID_IDisplayHelp,
  83. reinterpret_cast<void**>(&m_pDisplayHelp));
  84. return S_OK;
  85. }
  86. STDMETHODIMP CRSOPSnapIn::Destroy(MMC_COOKIE cookie)
  87. {
  88. if (m_pConsole != NULL)
  89. {
  90. m_pConsole->SetHeader(NULL);
  91. m_pConsole->Release();
  92. m_pConsole = NULL;
  93. }
  94. if (m_pHeader != NULL)
  95. {
  96. m_pHeader->Release();
  97. m_pHeader = NULL;
  98. }
  99. if (m_pResult != NULL)
  100. {
  101. m_pResult->Release();
  102. m_pResult = NULL;
  103. }
  104. if (m_pConsoleVerb != NULL)
  105. {
  106. m_pConsoleVerb->Release();
  107. m_pConsoleVerb = NULL;
  108. }
  109. if (m_pDisplayHelp != NULL)
  110. {
  111. m_pDisplayHelp->Release();
  112. m_pDisplayHelp = NULL;
  113. }
  114. return S_OK;
  115. }
  116. STDMETHODIMP CRSOPSnapIn::Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  117. {
  118. HRESULT hr = S_OK;
  119. switch(event)
  120. {
  121. case MMCN_COLUMNS_CHANGED:
  122. hr = S_OK;
  123. break;
  124. case MMCN_DBLCLICK:
  125. hr = S_FALSE;
  126. break;
  127. case MMCN_ADD_IMAGES:
  128. HBITMAP hbmp16x16;
  129. HBITMAP hbmp32x32;
  130. hbmp16x16 = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_16x16));
  131. if (hbmp16x16)
  132. {
  133. hbmp32x32 = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_32x32));
  134. if (hbmp32x32)
  135. {
  136. LPIMAGELIST pImageList = (LPIMAGELIST) arg;
  137. // Set the images
  138. pImageList->ImageListSetStrip(reinterpret_cast<LONG_PTR *>(hbmp16x16),
  139. reinterpret_cast<LONG_PTR *>(hbmp32x32),
  140. 0, RGB(255, 0, 255));
  141. DeleteObject(hbmp32x32);
  142. }
  143. DeleteObject(hbmp16x16);
  144. }
  145. break;
  146. case MMCN_SHOW:
  147. if (arg == TRUE)
  148. {
  149. RESULTDATAITEM resultItem;
  150. LPRSOPDATAOBJECT pRSOPDataObject;
  151. MMC_COOKIE cookie;
  152. INT i;
  153. LPCONSOLE2 lpConsole2;
  154. //
  155. // Get the cookie of the scope pane item
  156. //
  157. hr = lpDataObject->QueryInterface(IID_IRSOPDataObject, (LPVOID *)&pRSOPDataObject);
  158. if (FAILED(hr))
  159. return S_OK;
  160. hr = pRSOPDataObject->GetCookie(&cookie);
  161. pRSOPDataObject->Release(); // release initial ref
  162. if (FAILED(hr))
  163. return S_OK;
  164. //
  165. // Prepare the view
  166. //
  167. m_pHeader->InsertColumn(0, m_column1, LVCFMT_LEFT, m_nColumnSize);
  168. m_pResult->SetViewMode(m_lViewMode);
  169. //
  170. // Add result pane items for this node
  171. //
  172. for (i = 0; i < g_RsopNameSpace[cookie].cResultItems; i++)
  173. {
  174. resultItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  175. resultItem.str = MMC_CALLBACK;
  176. resultItem.nImage = g_RsopNameSpace[cookie].pResultItems[i].iImage;
  177. resultItem.lParam = (LPARAM) &g_RsopNameSpace[cookie].pResultItems[i];
  178. m_pResult->InsertItem(&resultItem);
  179. }
  180. m_pResult->Sort(0, 0, -1);
  181. if (m_bExpand)
  182. {
  183. hr = m_pConsole->QueryInterface(IID_IConsole2,
  184. reinterpret_cast<void**>(&lpConsole2));
  185. if (SUCCEEDED(hr))
  186. {
  187. if (m_pcd->m_hMachine)
  188. {
  189. lpConsole2->Expand(m_pcd->m_hMachine, TRUE);
  190. }
  191. if (m_pcd->m_hUser)
  192. {
  193. lpConsole2->Expand(m_pcd->m_hUser, TRUE);
  194. }
  195. lpConsole2->Release();
  196. }
  197. m_bExpand = FALSE;
  198. }
  199. }
  200. else
  201. {
  202. m_pHeader->GetColumnWidth(0, &m_nColumnSize);
  203. m_pResult->GetViewMode(&m_lViewMode);
  204. }
  205. break;
  206. case MMCN_SELECT:
  207. if (m_pConsoleVerb)
  208. {
  209. LPRESULTITEM pItem;
  210. LPRSOPDATAOBJECT pRSOPDataObject;
  211. DATA_OBJECT_TYPES type;
  212. MMC_COOKIE cookie;
  213. //
  214. // Set the default verb to open
  215. //
  216. m_pConsoleVerb->SetDefaultVerb(MMC_VERB_OPEN);
  217. //
  218. // See if this is one of our items.
  219. //
  220. hr = lpDataObject->QueryInterface(IID_IRSOPDataObject, (LPVOID *)&pRSOPDataObject);
  221. if (FAILED(hr))
  222. break;
  223. pRSOPDataObject->GetType(&type);
  224. pRSOPDataObject->GetCookie(&cookie);
  225. pRSOPDataObject->Release();
  226. //
  227. // If this is a result pane item or the root of the namespace
  228. // nodes, enable the Properties menu item
  229. //
  230. if ((type == CCT_RESULT) ||
  231. ((type == CCT_SCOPE) && ((cookie == 0) || (cookie == 1) || (cookie == 2))))
  232. {
  233. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, TRUE);
  234. //
  235. // If this is a result pane item, then change the default
  236. // verb to Properties.
  237. //
  238. if (type == CCT_RESULT)
  239. m_pConsoleVerb->SetDefaultVerb(MMC_VERB_PROPERTIES);
  240. }
  241. }
  242. break;
  243. case MMCN_CONTEXTHELP:
  244. {
  245. if (m_pDisplayHelp)
  246. {
  247. LPOLESTR pszHelpTopic;
  248. LPRSOPDATAOBJECT pRSOPDataObject;
  249. MMC_COOKIE cookie;
  250. //
  251. // Get the cookie of the scope pane item
  252. //
  253. hr = lpDataObject->QueryInterface(IID_IRSOPDataObject, (LPVOID *)&pRSOPDataObject);
  254. if (FAILED(hr))
  255. return S_OK;
  256. hr = pRSOPDataObject->GetCookie(&cookie);
  257. pRSOPDataObject->Release(); // release initial ref
  258. if (FAILED(hr))
  259. return S_OK;
  260. pszHelpTopic = (LPOLESTR) CoTaskMemAlloc (50 * sizeof(WCHAR));
  261. if (pszHelpTopic)
  262. {
  263. lstrcpy (pszHelpTopic, g_RsopNameSpace[cookie].lpHelpTopic);
  264. m_pDisplayHelp->ShowTopic (pszHelpTopic);
  265. }
  266. }
  267. }
  268. break;
  269. default:
  270. hr = E_UNEXPECTED;
  271. break;
  272. }
  273. return hr;
  274. }
  275. STDMETHODIMP CRSOPSnapIn::GetDisplayInfo(LPRESULTDATAITEM pResult)
  276. {
  277. if (pResult)
  278. {
  279. if (pResult->bScopeItem == TRUE)
  280. {
  281. if (pResult->mask & RDI_STR)
  282. {
  283. if (pResult->nCol == 0)
  284. {
  285. pResult->str = g_RsopNameSpace[pResult->lParam].szDisplayName;
  286. }
  287. else
  288. {
  289. pResult->str = L"";
  290. }
  291. }
  292. if (pResult->mask & RDI_IMAGE)
  293. {
  294. if (m_pcd->m_bInitialized)
  295. {
  296. INT iIcon;
  297. iIcon = g_RsopNameSpace[pResult->lParam].iIcon;
  298. if ((pResult->lParam == 1) && m_pcd->m_bComputerGPCoreError)
  299. {
  300. iIcon = 12;
  301. }
  302. else if ((pResult->lParam == 1) && m_pcd->m_bComputerCSEError)
  303. {
  304. iIcon = 14;
  305. }
  306. else if ((pResult->lParam == 2) && m_pcd->m_bUserGPCoreError)
  307. {
  308. iIcon = 13;
  309. }
  310. else if ((pResult->lParam == 2) && m_pcd->m_bUserCSEError)
  311. {
  312. iIcon = 15;
  313. }
  314. pResult->nImage = iIcon;
  315. }
  316. else
  317. pResult->nImage = 3;
  318. }
  319. }
  320. else
  321. {
  322. if (pResult->mask & RDI_STR)
  323. {
  324. if (pResult->nCol == 0)
  325. {
  326. LPRESULTITEM lpResultItem = (LPRESULTITEM)pResult->lParam;
  327. if (lpResultItem->szDisplayName[0] == TEXT('\0'))
  328. {
  329. LoadString (g_hInstance, lpResultItem->iStringID,
  330. lpResultItem->szDisplayName,
  331. MAX_DISPLAYNAME_SIZE);
  332. }
  333. pResult->str = lpResultItem->szDisplayName;
  334. }
  335. if (pResult->str == NULL)
  336. pResult->str = (LPOLESTR)L"";
  337. }
  338. }
  339. }
  340. return S_OK;
  341. }
  342. STDMETHODIMP CRSOPSnapIn::QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT *ppDataObject)
  343. {
  344. return m_pcd->QueryDataObject(cookie, type, ppDataObject);
  345. }
  346. STDMETHODIMP CRSOPSnapIn::GetResultViewType(MMC_COOKIE cookie, LPOLESTR *ppViewType,
  347. long *pViewOptions)
  348. {
  349. return S_FALSE;
  350. }
  351. STDMETHODIMP CRSOPSnapIn::CompareObjects(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB)
  352. {
  353. HRESULT hr = S_FALSE;
  354. LPRSOPDATAOBJECT pRSOPDataObjectA, pRSOPDataObjectB;
  355. MMC_COOKIE cookie1, cookie2;
  356. if (lpDataObjectA == NULL || lpDataObjectB == NULL)
  357. return E_POINTER;
  358. //
  359. // QI for the private GPODataObject interface
  360. //
  361. if (FAILED(lpDataObjectA->QueryInterface(IID_IRSOPDataObject,
  362. (LPVOID *)&pRSOPDataObjectA)))
  363. {
  364. return S_FALSE;
  365. }
  366. if (FAILED(lpDataObjectB->QueryInterface(IID_IRSOPDataObject,
  367. (LPVOID *)&pRSOPDataObjectB)))
  368. {
  369. pRSOPDataObjectA->Release();
  370. return S_FALSE;
  371. }
  372. pRSOPDataObjectA->GetCookie(&cookie1);
  373. pRSOPDataObjectB->GetCookie(&cookie2);
  374. if (cookie1 == cookie2)
  375. {
  376. hr = S_OK;
  377. }
  378. pRSOPDataObjectA->Release();
  379. pRSOPDataObjectB->Release();
  380. return hr;
  381. }
  382. ///////////////////////////////////////////////////////////////////////////////
  383. // //
  384. // CRSOPSnapIn object implementation (IExtendContextMenu) //
  385. // //
  386. ///////////////////////////////////////////////////////////////////////////////
  387. STDMETHODIMP CRSOPSnapIn::AddMenuItems(LPDATAOBJECT piDataObject,
  388. LPCONTEXTMENUCALLBACK pCallback,
  389. LONG *pInsertionAllowed)
  390. {
  391. return m_pcd->AddMenuItems (piDataObject, pCallback, pInsertionAllowed);
  392. }
  393. STDMETHODIMP CRSOPSnapIn::Command(LONG lCommandID, LPDATAOBJECT piDataObject)
  394. {
  395. return m_pcd->Command (lCommandID, piDataObject);
  396. }