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.

822 lines
22 KiB

  1. // Copyright (c) 1997-1999 Microsoft Corporation
  2. #include "precomp.h"
  3. #include "WMICntl.h"
  4. #include "WMISnapin.h"
  5. #include "..\common\util.h"
  6. #include "..\GenPage.h"
  7. #include "..\LogPage.h"
  8. #include "..\BackupPage.h"
  9. #include "..\NSPage.h"
  10. #include "..\AdvPage.h"
  11. #include "..\chklist.h"
  12. #include "..\DataSrc.h"
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CWMISnapinComponentData
  15. static const GUID CWMISnapinGUID_NODETYPE =
  16. { 0x5c659259, 0xe236, 0x11d2, { 0x88, 0x99, 0x0, 0x10, 0x4b, 0x2a, 0xfb, 0x46 } };
  17. const GUID* CWMISnapinData::m_NODETYPE = &CWMISnapinGUID_NODETYPE;
  18. const OLECHAR* CWMISnapinData::m_SZNODETYPE = OLESTR("5C659259-E236-11D2-8899-00104B2AFB46");
  19. const OLECHAR* CWMISnapinData::m_SZDISPLAY_NAME = OLESTR("WMISnapin2222");
  20. const CLSID* CWMISnapinData::m_SNAPIN_CLASSID = &CLSID_WMISnapin;
  21. static const GUID CWMISnapinExtGUID_NODETYPE =
  22. { 0x476e6449, 0xaaff, 0x11d0, { 0xb9, 0x44, 0x0, 0xc0, 0x4f, 0xd8, 0xd5, 0xb0 } };
  23. const GUID* CWMISnapinExtData::m_NODETYPE = &CWMISnapinExtGUID_NODETYPE;
  24. const OLECHAR* CWMISnapinExtData::m_SZNODETYPE = OLESTR("476e6449-aaff-11d0-b944-00c04fd8d5b0");
  25. const OLECHAR* CWMISnapinExtData::m_SZDISPLAY_NAME = OLESTR("WMISnapin33333");
  26. const CLSID* CWMISnapinExtData::m_SNAPIN_CLASSID = &CLSID_WMISnapin;
  27. //-------------------------------------------------------------
  28. CWMISnapinData::CWMISnapinData(bool extension)
  29. : m_extension(extension),
  30. m_parent(0)
  31. {
  32. // Image indexes may need to be modified depending on the images specific to
  33. // the snapin.
  34. // SetMenuID(IDR_MENU_MENU);
  35. memset(m_MachineName, 0, (MAXCOMPUTER_NAME + 1) * sizeof(TCHAR));
  36. memset(&m_scopeDataItem, 0, sizeof(SCOPEDATAITEM));
  37. m_scopeDataItem.mask = SDI_STR | SDI_IMAGE | SDI_OPENIMAGE | SDI_PARAM|SDI_CHILDREN;
  38. m_scopeDataItem.displayname = MMC_CALLBACK;
  39. m_scopeDataItem.nImage = IDI_WMICNTL; // May need modification
  40. m_scopeDataItem.nOpenImage = IDI_WMICNTL; // May need modification
  41. m_scopeDataItem.cChildren = 0; // May need modification
  42. m_scopeDataItem.lParam = (LPARAM) this;
  43. memset(&m_resultDataItem, 0, sizeof(RESULTDATAITEM));
  44. m_resultDataItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  45. m_resultDataItem.str = MMC_CALLBACK;
  46. m_resultDataItem.nImage = IDI_WMICNTL; // May need modification
  47. m_resultDataItem.lParam = (LPARAM) this;
  48. memset(m_nodeType, 0, 50 * sizeof(wchar_t));
  49. if(::LoadString(_Module.GetModuleInstance(), IDS_SNAPIN_TYPE, m_nodeType, 50) == 0)
  50. {
  51. wcscpy(m_nodeType, L"Snapin Extension");
  52. }
  53. memset(m_nodeDesc, 0, 100 * sizeof(wchar_t));
  54. if(::LoadString(_Module.GetModuleInstance(), IDS_DESCRIPTION, m_nodeDesc, 100) == 0)
  55. {
  56. wcscpy(m_nodeDesc, L"<unavailable>");
  57. }
  58. memset(m_descBar, 0, 100 * sizeof(wchar_t));
  59. if(::LoadString(_Module.GetModuleInstance(), IDS_PROJNAME, m_descBar, 100) == 0)
  60. {
  61. wcscpy(m_descBar, L"WMI Control");
  62. }
  63. m_spConsole = NULL;
  64. m_lpProvider = NULL;
  65. m_myID = 0;
  66. g_DS = NULL;
  67. memset(m_initMachineName, 0, (MAXCOMPUTER_NAME + 1) * sizeof(wchar_t));
  68. }
  69. //-------------------------------------------------------------
  70. HRESULT CWMISnapinData::GetScopePaneInfo(SCOPEDATAITEM *pScopeDataItem)
  71. {
  72. if (pScopeDataItem->mask & SDI_STR)
  73. pScopeDataItem->displayname = m_bstrDisplayName;
  74. if (pScopeDataItem->mask & SDI_IMAGE)
  75. pScopeDataItem->nImage = m_scopeDataItem.nImage;
  76. if (pScopeDataItem->mask & SDI_OPENIMAGE)
  77. pScopeDataItem->nOpenImage = m_scopeDataItem.nOpenImage;
  78. if (pScopeDataItem->mask & SDI_PARAM)
  79. pScopeDataItem->lParam = m_scopeDataItem.lParam;
  80. if (pScopeDataItem->mask & SDI_STATE )
  81. pScopeDataItem->nState = m_scopeDataItem.nState;
  82. // TODO : Add code for SDI_CHILDREN
  83. return S_OK;
  84. }
  85. //-------------------------------------------------------------
  86. HRESULT CWMISnapinData::GetResultPaneInfo(RESULTDATAITEM *pResultDataItem)
  87. {
  88. if (pResultDataItem->bScopeItem)
  89. {
  90. if (pResultDataItem->mask & RDI_STR)
  91. {
  92. pResultDataItem->str = GetResultPaneColInfo(pResultDataItem->nCol);
  93. }
  94. if (pResultDataItem->mask & RDI_IMAGE)
  95. {
  96. pResultDataItem->nImage = m_scopeDataItem.nImage;
  97. }
  98. if (pResultDataItem->mask & RDI_PARAM)
  99. {
  100. pResultDataItem->lParam = m_scopeDataItem.lParam;
  101. }
  102. return S_OK;
  103. }
  104. if (pResultDataItem->mask & RDI_STR)
  105. {
  106. pResultDataItem->str = GetResultPaneColInfo(pResultDataItem->nCol);
  107. }
  108. if (pResultDataItem->mask & RDI_IMAGE)
  109. {
  110. pResultDataItem->nImage = m_resultDataItem.nImage;
  111. }
  112. if (pResultDataItem->mask & RDI_PARAM)
  113. {
  114. pResultDataItem->lParam = m_resultDataItem.lParam;
  115. }
  116. if (pResultDataItem->mask & RDI_INDEX)
  117. {
  118. pResultDataItem->nIndex = m_resultDataItem.nIndex;
  119. }
  120. return S_OK;
  121. }
  122. //------------------------------------------------------------------
  123. LPOLESTR CWMISnapinData::GetResultPaneColInfo(int nCol)
  124. {
  125. switch(nCol)
  126. {
  127. case 0:
  128. return m_bstrDisplayName;
  129. break;
  130. case 1:
  131. return m_nodeType;
  132. break;
  133. case 2:
  134. return m_nodeDesc;
  135. break;
  136. } //endswitch nCol
  137. return OLESTR("missed one in CWMISnapinData::GetResultPaneColInfo");
  138. }
  139. //------------------------------------------------------------------
  140. HRESULT CWMISnapinData::Notify( MMC_NOTIFY_TYPE event,
  141. LPARAM arg,
  142. LPARAM param,
  143. IComponentData* pComponentData,
  144. IComponent* pComponent,
  145. DATA_OBJECT_TYPES type)
  146. {
  147. // Add code to handle the different notifications.
  148. // Handle MMCN_SHOW and MMCN_EXPAND to enumerate children items.
  149. // In response to MMCN_SHOW you have to enumerate both the scope
  150. // and result pane items.
  151. // For MMCN_EXPAND you only need to enumerate the scope items
  152. // Use IConsoleNameSpace::InsertItem to insert scope pane items
  153. // Use IResultData::InsertItem to insert result pane item.
  154. HRESULT hr = E_NOTIMPL;
  155. _ASSERTE(pComponentData != NULL || pComponent != NULL);
  156. CComQIPtr<IHeaderCtrl, &IID_IHeaderCtrl> spHeader;
  157. if (pComponentData != NULL)
  158. m_spConsole = ((CWMISnapin*)pComponentData)->m_spConsole;
  159. else
  160. {
  161. m_spConsole = ((CWMISnapinComponent*)pComponent)->m_spConsole;
  162. spHeader = m_spConsole;
  163. }
  164. switch(event)
  165. {
  166. case MMCN_CONTEXTHELP:
  167. {
  168. WCHAR topic[128] = L"newfeat1.chm::wmi_control_overview.htm";
  169. CComQIPtr<IDisplayHelp, &IID_IDisplayHelp> displayHelp(m_spConsole);
  170. LPOLESTR lpCompiledHelpFile = reinterpret_cast<LPOLESTR>(
  171. CoTaskMemAlloc((wcslen(topic) + 1) *
  172. sizeof(wchar_t)));
  173. if(lpCompiledHelpFile == NULL)
  174. {
  175. hr = E_OUTOFMEMORY;
  176. }
  177. else
  178. {
  179. USES_CONVERSION;
  180. wcscpy(lpCompiledHelpFile, T2OLE((LPTSTR)(LPCTSTR)topic));
  181. hr = displayHelp->ShowTopic(lpCompiledHelpFile);
  182. }
  183. }
  184. break;
  185. case MMCN_SHOW:
  186. {
  187. // if we are showing
  188. if (arg)
  189. {
  190. CComQIPtr<IResultData, &IID_IResultData> spResultData(m_spConsole);
  191. LPUNKNOWN pUnk = 0;
  192. if(SUCCEEDED(m_spConsole->QueryResultView(&pUnk)))
  193. {
  194. CComQIPtr<IMessageView, &IID_IMessageView> spMsg(pUnk);
  195. if(spMsg)
  196. {
  197. TCHAR title[100] = {0}, desc[256] = {0};
  198. ::LoadString(_Module.GetResourceInstance(), IDS_PROJNAME,
  199. title, 100);
  200. ::LoadString(_Module.GetResourceInstance(), IDS_DESCRIPTION,
  201. desc, 256);
  202. spMsg->SetTitleText(title);
  203. spMsg->SetBodyText(desc);
  204. spMsg->SetIcon(Icon_Information);
  205. }
  206. pUnk->Release();
  207. }
  208. }
  209. else // else we are hiding. Clean up...
  210. {
  211. HWND hMainWin;
  212. if (SUCCEEDED(m_spConsole->GetMainWindow(&hMainWin)))
  213. {
  214. // if we've got a property sheet up, we want to close it
  215. }
  216. }
  217. hr = S_OK;
  218. break;
  219. }
  220. case MMCN_EXPAND:
  221. {
  222. m_myID = (HSCOPEITEM)param;
  223. hr = S_OK;
  224. break;
  225. }
  226. case MMCN_SELECT:
  227. {
  228. CComQIPtr<IResultData, &IID_IResultData> spResultData(m_spConsole);
  229. spResultData->SetDescBarText(m_descBar);
  230. if(g_DS && wcslen(m_initMachineName) != 0)
  231. {
  232. g_DS->SetMachineName(CHString1(m_initMachineName));
  233. memset(m_initMachineName, 0, (MAXCOMPUTER_NAME + 1) * sizeof(wchar_t));
  234. }
  235. IConsoleVerb *menu = NULL;
  236. if(SUCCEEDED(m_spConsole->QueryConsoleVerb(&menu)))
  237. {
  238. menu->SetVerbState(MMC_VERB_REFRESH, ENABLED, TRUE);
  239. menu->SetVerbState(MMC_VERB_REFRESH, HIDDEN, TRUE);
  240. if(m_myID)
  241. {
  242. menu->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, TRUE);
  243. menu->SetVerbState(MMC_VERB_PROPERTIES, HIDDEN, FALSE);
  244. }
  245. else
  246. {
  247. menu->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, FALSE);
  248. menu->SetVerbState(MMC_VERB_PROPERTIES, HIDDEN, TRUE);
  249. }
  250. menu->Release();
  251. }
  252. hr = S_OK;
  253. }
  254. break;
  255. case MMCN_DBLCLICK:
  256. hr = S_FALSE; // do the default verb. (Properties)
  257. break;
  258. case MMCN_ADD_IMAGES:
  259. {
  260. // Add Images
  261. IImageList* pImageList = (IImageList*) arg;
  262. hr = E_FAIL;
  263. // Load bitmaps associated with the scope pane
  264. // and add them to the image list
  265. // Loads the default bitmaps generated by the wizard
  266. // Change as required
  267. if(g_DS == 0)
  268. {
  269. g_DS = new DataSource;
  270. if(g_DS == NULL)
  271. {
  272. return E_OUTOFMEMORY;
  273. }
  274. WCHAR CompName[MAX_COMPUTERNAME_LENGTH + 1 ];
  275. WCHAR * pCompName;
  276. if (NULL == m_parent)
  277. {
  278. DWORD dwSize = sizeof(CompName)/sizeof(TCHAR);
  279. GetComputerNameEx(ComputerNamePhysicalNetBIOS,CompName,&dwSize);
  280. pCompName = CompName;
  281. }
  282. else
  283. {
  284. pCompName = m_parent->m_MachineName;
  285. }
  286. g_DS->SetMachineName(CHString1(pCompName));
  287. }
  288. HICON icon = LoadIcon(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_WMICNTL));
  289. if(icon != NULL)
  290. {
  291. hr = pImageList->ImageListSetIcon((LONG_PTR*)icon, IDI_WMICNTL);
  292. if(FAILED(hr))
  293. ATLTRACE(_T("CLogDriveScopeNode::ImageListSetIcon failed\n"));
  294. }
  295. break;
  296. }
  297. }
  298. return hr;
  299. }
  300. //-----------------------------------------------------------------------------
  301. HRESULT CWMISnapinData::CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  302. LONG_PTR handle,
  303. IUnknown* pUnk,
  304. DATA_OBJECT_TYPES type)
  305. {
  306. HRESULT hr = E_UNEXPECTED;
  307. bool htmlSupport = false;
  308. switch(type)
  309. {
  310. case CCT_SCOPE:
  311. {
  312. bstr_t temp;
  313. HPROPSHEETPAGE hPage;
  314. BOOL bResult = FALSE;
  315. if(g_DS == 0)
  316. {
  317. g_DS = new DataSource;
  318. if(g_DS == NULL)
  319. {
  320. return E_OUTOFMEMORY;
  321. }
  322. g_DS->SetMachineName(CHString1(L""));
  323. }
  324. // General tab.
  325. CGenPage *pPage = new CGenPage(g_DS, htmlSupport);
  326. if(pPage)
  327. {
  328. hPage = pPage->CreatePropSheetPage(MAKEINTRESOURCE(IDD_GENERAL));
  329. lpProvider->AddPage(hPage);
  330. }
  331. // Logging Tab.
  332. CLogPage *pPage1 = new CLogPage(g_DS, htmlSupport);
  333. if(pPage1)
  334. {
  335. hPage = pPage1->CreatePropSheetPage(MAKEINTRESOURCE(IDD_LOGGING));
  336. lpProvider->AddPage(hPage);
  337. }
  338. // Backup Tab.
  339. CBackupPage *pPage2 = new CBackupPage(g_DS, htmlSupport);
  340. if(pPage2)
  341. {
  342. hPage = pPage2->CreatePropSheetPage(MAKEINTRESOURCE(IDD_BACKUP));
  343. lpProvider->AddPage(hPage);
  344. }
  345. // Security Tab.
  346. CNamespacePage *pPage3 = new CNamespacePage(g_DS, htmlSupport);
  347. if(pPage3)
  348. {
  349. hPage = pPage3->CreatePropSheetPage(MAKEINTRESOURCE(IDD_NAMESPACE));
  350. lpProvider->AddPage(hPage);
  351. }
  352. CAdvancedPage *pPage4 = new CAdvancedPage(g_DS, htmlSupport);
  353. if(pPage4)
  354. {
  355. hPage = pPage4->CreatePropSheetPage(MAKEINTRESOURCE(IDD_ADVANCED_9X));
  356. lpProvider->AddPage(hPage);
  357. }
  358. hr = S_OK;
  359. }
  360. break;
  361. case CCT_SNAPIN_MANAGER:
  362. {
  363. HPROPSHEETPAGE hPage;
  364. if(g_DS == 0)
  365. {
  366. g_DS = new DataSource;
  367. }
  368. if(g_DS == NULL)
  369. {
  370. return E_OUTOFMEMORY;
  371. }
  372. ConnectPage *connPg = new ConnectPage(g_DS, htmlSupport);
  373. if(connPg)
  374. {
  375. hPage = connPg->CreatePropSheetPage(MAKEINTRESOURCE(IDD_CONNECT_WIZ));
  376. lpProvider->AddPage(hPage);
  377. }
  378. hr = S_OK;
  379. }
  380. break;
  381. default: break;
  382. } //endswitch
  383. return hr;
  384. }
  385. //==============================================================
  386. //=================== SERVER NODE being extended===============
  387. HRESULT CWMISnapinExtData::Notify(MMC_NOTIFY_TYPE event,
  388. LPARAM arg,
  389. LPARAM param,
  390. IComponentData* pComponentData,
  391. IComponent* pComponent,
  392. DATA_OBJECT_TYPES type)
  393. {
  394. // Add code to handle the different notifications.
  395. // Handle MMCN_SHOW and MMCN_EXPAND to enumerate children items.
  396. // In response to MMCN_SHOW you have to enumerate both the scope
  397. // and result pane items.
  398. // For MMCN_EXPAND you only need to enumerate the scope items
  399. // Use IConsoleNameSpace::InsertItem to insert scope pane items
  400. // Use IResultData::InsertItem to insert result pane item.
  401. HRESULT hr = E_NOTIMPL;
  402. _ASSERTE(pComponentData != NULL || pComponent != NULL);
  403. CComPtr<IConsole> spConsole;
  404. CComQIPtr<IHeaderCtrl, &IID_IHeaderCtrl> spHeader;
  405. if (pComponentData != NULL)
  406. spConsole = ((CWMISnapin*)pComponentData)->m_spConsole;
  407. else
  408. {
  409. spConsole = ((CWMISnapinComponent*)pComponent)->m_spConsole;
  410. spHeader = spConsole;
  411. }
  412. // Snitch(L"Storage", event);
  413. switch(event)
  414. {
  415. case MMCN_REFRESH:
  416. hr = S_OK;
  417. break;
  418. case MMCN_EXPAND:
  419. {
  420. // NOTE: I dont enum in the scope.
  421. CComQIPtr<IConsoleNameSpace, &IID_IConsoleNameSpace> spConsoleNameSpace(spConsole);
  422. if(m_pScopeItem == NULL)
  423. {
  424. CWMISnapinData* p = new CWMISnapinData(true);
  425. p->m_scopeDataItem.relativeID = param;
  426. p->m_scopeDataItem.lParam = (LPARAM)p;
  427. p->m_bstrDisplayName = m_nodeName;
  428. p->m_parent = this;
  429. hr = spConsoleNameSpace->InsertItem(&p->m_scopeDataItem);
  430. ATLTRACE(L"!!!!!!!!!!!!!!!!!!!!!scope using %x\n", this);
  431. MachineName();
  432. if(p->g_DS)
  433. p->g_DS->SetMachineName(CHString1(MachineName()));
  434. m_pScopeItem = p;
  435. }
  436. hr = S_OK;
  437. break;
  438. }
  439. case MMCN_REMOVE_CHILDREN:
  440. {
  441. // we're changing shopes,
  442. // if the prop sheet is open now, we want to close it.
  443. if (m_pScopeItem && m_pScopeItem->g_DS)
  444. m_pScopeItem->g_DS->ClosePropSheet();
  445. CComQIPtr<IConsoleNameSpace, &IID_IConsoleNameSpace> spConsoleNameSpace(spConsole);
  446. delete m_pScopeItem;
  447. m_pScopeItem = NULL;
  448. hr = spConsoleNameSpace->DeleteItem(arg, false);
  449. }
  450. break;
  451. case MMCN_ADD_IMAGES:
  452. {
  453. // Add Images
  454. IImageList* pImageList = (IImageList*) arg;
  455. hr = E_FAIL;
  456. CComQIPtr<IResultData, &IID_IResultData> spResultData(spConsole);
  457. spResultData->DeleteAllRsltItems();
  458. HICON icon = LoadIcon(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_WMICNTL));
  459. if(icon != NULL)
  460. {
  461. hr = pImageList->ImageListSetIcon((LONG_PTR*)icon, IDI_WMICNTL);
  462. if(FAILED(hr))
  463. ATLTRACE(_T("CLogDriveScopeNode::ImageListSetIcon failed\n"));
  464. }
  465. break;
  466. }
  467. }
  468. return hr;
  469. }
  470. //----------------------------------------------------------------
  471. HRESULT CWMISnapinExtData::GetDataHere(FORMATETC* pformatetc, STGMEDIUM* pmedium)
  472. {
  473. ATLTRACE(_T("SnapInDataObjectImpl::GetDataHere\n"));
  474. if (pmedium == NULL)
  475. return E_POINTER;
  476. CLIPFORMAT MACHINE_NAME = (CLIPFORMAT) RegisterClipboardFormat(L"MMC_SNAPIN_MACHINE_NAME");
  477. ULONG uWritten = 0;
  478. HRESULT hr = DV_E_TYMED;
  479. // Make sure the type medium is HGLOBAL
  480. if (pmedium->tymed == TYMED_HGLOBAL)
  481. {
  482. // Create the stream on the hGlobal passed in
  483. CComPtr<IStream> spStream;
  484. hr = CreateStreamOnHGlobal(pmedium->hGlobal, FALSE, &spStream);
  485. if(SUCCEEDED(hr))
  486. {
  487. if (pformatetc->cfFormat == CSnapInItem::m_CCF_SNAPIN_GETOBJECTDATA)
  488. {
  489. hr = DV_E_CLIPFORMAT;
  490. ULONG uWritten;
  491. hr = spStream->Write(&m_objectData, sizeof(CObjectData), &uWritten);
  492. }
  493. else if (pformatetc->cfFormat == MACHINE_NAME)
  494. {
  495. hr = spStream->Write(m_MachineName, (wcslen(m_MachineName) + 1) * sizeof(OLECHAR), &uWritten);
  496. }
  497. else
  498. {
  499. hr = m_objectData.m_pItem->FillData(pformatetc->cfFormat, spStream);
  500. }
  501. }
  502. }
  503. return hr;
  504. }
  505. //--------------------------------------------------------------------------------
  506. wchar_t* CWMISnapinExtData::MachineName()
  507. {
  508. Extract(m_pDataObject, L"MMC_SNAPIN_MACHINE_NAME", m_MachineName);
  509. return m_MachineName;
  510. }
  511. //==============================================================
  512. //=================== STATIC NODE ==============================
  513. HRESULT CWMISnapin::LoadIcon(CComPtr<IImageList> &spImageList,
  514. UINT resID)
  515. {
  516. HRESULT hr = 0;
  517. HICON icon = ::LoadIcon(_Module.GetResourceInstance(), MAKEINTRESOURCE(resID));
  518. if(icon != NULL)
  519. {
  520. hr = spImageList->ImageListSetIcon((LONG_PTR*)icon, resID);
  521. if(FAILED(hr))
  522. ATLTRACE(_T("CLogDriveScopeNode::ImageListSetIcon failed\n"));
  523. }
  524. return hr;
  525. }
  526. //----------------------------------------------------------------
  527. HRESULT CWMISnapin::Initialize(LPUNKNOWN pUnknown)
  528. {
  529. #if (_WIN32_IE >= 0x0300)
  530. INITCOMMONCONTROLSEX iccx;
  531. iccx.dwSize = sizeof(iccx);
  532. iccx.dwICC = ICC_BAR_CLASSES | ICC_USEREX_CLASSES|ICC_LISTVIEW_CLASSES;
  533. ::InitCommonControlsEx(&iccx);
  534. #else
  535. ::InitCommonControls();
  536. #endif
  537. RegisterCheckListWndClass();
  538. HRESULT hr = IComponentDataImpl<CWMISnapin, CWMISnapinComponent>::Initialize(pUnknown);
  539. if (FAILED(hr))
  540. return hr;
  541. CComPtr<IImageList> spImageList;
  542. if(m_spConsole->QueryScopeImageList(&spImageList) != S_OK)
  543. {
  544. ATLTRACE(_T("IConsole::QueryScopeImageList failed\n"));
  545. return E_UNEXPECTED;
  546. }
  547. // Load bitmaps associated with the scope pane
  548. // and add them to the image list
  549. // Loads the default bitmaps generated by the wizard
  550. // Change as required
  551. HBITMAP hBitmap16 = LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_WMISNAPIN_16));
  552. if (hBitmap16 == NULL)
  553. return S_OK;
  554. HBITMAP hBitmap32 = LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_WMISNAPIN_32));
  555. if(hBitmap32 == NULL)
  556. return S_OK;
  557. if(spImageList->ImageListSetStrip((LONG_PTR*)hBitmap16,
  558. (LONG_PTR*)hBitmap32, IDI_WMICNTL, RGB(0, 128, 128)) != S_OK)
  559. {
  560. ATLTRACE(_T("IImageList::ImageListSetStrip failed\n"));
  561. return E_UNEXPECTED;
  562. }
  563. return S_OK;
  564. }
  565. //----------------------------------------------------------------
  566. HRESULT CWMISnapin::GetClassID(CLSID *pClassID)
  567. {
  568. HRESULT hr = E_POINTER;
  569. ATLTRACE(_T("ClassID******\n"));
  570. if(NULL != pClassID)
  571. {
  572. // Use overloaded '=' operator to copy the Class ID.
  573. *pClassID = CLSID_WMISnapin;
  574. hr = S_OK;
  575. }
  576. return hr;
  577. }
  578. //----------------------------------------------------------------
  579. HRESULT CWMISnapin::IsDirty()
  580. {
  581. ATLTRACE(_T("Dirty******\n"));
  582. return (m_bDirty == true)? S_OK : S_FALSE;
  583. // return S_OK;
  584. }
  585. //----------------------------------------------------------------
  586. HRESULT CWMISnapin::ReadStream(IStream *pStm, void *data, ULONG *size)
  587. {
  588. HRESULT hr = E_FAIL;
  589. ULONG ulToRead = *size, ulReadIn = 0;
  590. // read the version nbr like a good boy.
  591. hr = pStm->Read((void *)data, ulToRead, &ulReadIn);
  592. if(SUCCEEDED(hr))
  593. {
  594. if(ulReadIn <= *size)
  595. {
  596. *size = ulReadIn;
  597. }
  598. else
  599. {
  600. hr = E_OUTOFMEMORY;
  601. }
  602. }
  603. return hr;
  604. }
  605. //----------------------------------------------------------------
  606. HRESULT CWMISnapin::Load(IStream *pStm)
  607. {
  608. HRESULT hr = E_POINTER;
  609. ULONG size = 0;
  610. BYTE version = 0;
  611. short machineLength = 0;
  612. ATLTRACE(_T("Load******\n"));
  613. if(NULL != pStm)
  614. {
  615. size = 1;
  616. if(SUCCEEDED(hr = ReadStream(pStm, (void *)&version, &size)))
  617. {
  618. // Deal with the differentversions.
  619. switch (version)
  620. {
  621. case 1:
  622. size = sizeof(short);
  623. if(SUCCEEDED(hr = ReadStream(pStm, (void *)&machineLength, &size)))
  624. {
  625. size = (ULONG)machineLength;
  626. if (size > MAXCOMPUTER_NAME+1) //validate size
  627. {
  628. hr = E_FAIL;
  629. break;
  630. }
  631. hr = ReadStream(pStm,
  632. (void *)((CWMISnapinData *)m_pNode)->m_initMachineName,
  633. &size);
  634. }
  635. break;
  636. default:
  637. hr = E_FAIL; // Bad version.
  638. break;
  639. } //endswitch
  640. } //endif ReadStream(version)
  641. }
  642. return hr;
  643. }
  644. //----------------------------------------------------------------
  645. HRESULT CWMISnapin::Save(IStream *pStm, BOOL fClearDirty)
  646. {
  647. HRESULT hr = E_POINTER;
  648. ULONG ulToWrite, ulWritten;
  649. short data = 1;
  650. ATLTRACE(_T("Save******\n"));
  651. if(NULL != pStm)
  652. {
  653. ulToWrite = 1;
  654. hr = pStm->Write(&data, ulToWrite, &ulWritten);
  655. if(SUCCEEDED(hr) && ulToWrite != ulWritten)
  656. {
  657. hr = STG_E_CANTSAVE;
  658. }
  659. // NOTE: g_DS == 0 when we're an extension and we dont need to save the machine name anyway.
  660. else if(SUCCEEDED(hr) && ((CWMISnapinData *)m_pNode)->g_DS)
  661. {
  662. ulToWrite = sizeof(short);
  663. ulWritten = 0;
  664. data = (short)sizeof(wchar_t) * (((CWMISnapinData *)m_pNode)->g_DS->m_whackedMachineName.GetLength() + 1);
  665. hr = pStm->Write(&data, ulToWrite, &ulWritten);
  666. if(SUCCEEDED(hr) && ulToWrite != ulWritten)
  667. {
  668. hr = STG_E_CANTSAVE;
  669. }
  670. else if(SUCCEEDED(hr))
  671. {
  672. LPBYTE str = new BYTE[data * sizeof(wchar_t)];
  673. if (!str)
  674. return E_OUTOFMEMORY;
  675. memset(str, 0, data * sizeof(wchar_t));
  676. ulToWrite = (ULONG)data;
  677. ulWritten = 0;
  678. wcscpy((wchar_t *)str, (LPCTSTR)((CWMISnapinData *)m_pNode)->g_DS->m_whackedMachineName);
  679. hr = pStm->Write((void *)str, ulToWrite, &ulWritten);
  680. delete[] str;
  681. if(SUCCEEDED(hr) && ulToWrite != ulWritten)
  682. {
  683. hr = STG_E_CANTSAVE;
  684. }
  685. else if(SUCCEEDED(hr))
  686. {
  687. // Clear this COM object's dirty flag if instructed. Otherwise,
  688. // preserve its content.
  689. if(fClearDirty)
  690. m_bDirty = false;
  691. }
  692. }
  693. }
  694. }
  695. return hr;
  696. }
  697. //----------------------------------------------------------------
  698. HRESULT CWMISnapin::GetSizeMax(ULARGE_INTEGER *pcbSize)
  699. {
  700. HRESULT hr = E_POINTER;
  701. ATLTRACE(_T("GetSizeMax******\n"));
  702. if(NULL != pcbSize)
  703. {
  704. ULISet32(*pcbSize, (256 * sizeof(wchar_t)) + sizeof(short) + 1);
  705. hr = S_OK;
  706. }
  707. return hr;
  708. }