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.

360 lines
10 KiB

  1. //==============================================================;
  2. //
  3. // This source code is only intended as a supplement to existing Microsoft documentation.
  4. //
  5. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  6. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  7. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  8. // PURPOSE.
  9. //
  10. // Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  11. //
  12. //==============================================================;
  13. // CCompData.cpp : Implementation of CCCompData
  14. #include "stdafx.h"
  15. #include "EvtVwr.h"
  16. #include "CompData.h"
  17. #include "Comp.h"
  18. #include "DataObj.h"
  19. #include "resource.h"
  20. #include <crtdbg.h>
  21. HBITMAP CCompData::m_pBMapSm = NULL;
  22. HBITMAP CCompData::m_pBMapLg = NULL;
  23. CCompData::CCompData()
  24. : m_cref(0), m_ipConsoleNameSpace2(NULL), m_ipConsole(NULL)
  25. {
  26. m_pStaticNode = new CStaticNode();
  27. }
  28. CCompData::~CCompData()
  29. {
  30. if (m_pStaticNode) {
  31. delete m_pStaticNode;
  32. }
  33. }
  34. ///////////////////////////////
  35. // Interface IComponentData
  36. ///////////////////////////////
  37. HRESULT CCompData::Initialize(
  38. /* [in] */ LPUNKNOWN pUnknown)
  39. {
  40. HRESULT hr = S_OK;
  41. //
  42. // Get pointer to name space interface
  43. //
  44. hr = pUnknown->QueryInterface(IID_IConsoleNameSpace2, (void **)&m_ipConsoleNameSpace2);
  45. _ASSERT( S_OK == hr );
  46. //
  47. // Get pointer to console interface
  48. //
  49. hr = pUnknown->QueryInterface(IID_IConsole, (void **)&m_ipConsole);
  50. _ASSERT( S_OK == hr );
  51. if (NULL == m_pBMapSm || NULL == m_pBMapLg)
  52. {
  53. m_pBMapSm = LoadBitmap(g_hinst, MAKEINTRESOURCE(IDR_SMICONS));
  54. m_pBMapLg = LoadBitmap(g_hinst, MAKEINTRESOURCE(IDR_LGICONS));
  55. }
  56. IImageList *pImageList;
  57. hr = m_ipConsole->QueryScopeImageList(&pImageList);
  58. _ASSERT( S_OK == hr );
  59. //ImageListSetStrip can return a failure code. If it does, that's ok.
  60. hr = pImageList->ImageListSetStrip( (long *)m_pBMapSm, // pointer to a handle
  61. (long *)m_pBMapLg, // pointer to a handle
  62. 0, // index of the first image in the strip
  63. RGB(0, 128, 128) // color of the icon mask
  64. );
  65. pImageList->Release();
  66. return S_OK;
  67. }
  68. HRESULT CCompData::CreateComponent(
  69. /* [out] */ LPCOMPONENT __RPC_FAR *ppComponent)
  70. {
  71. *ppComponent = NULL;
  72. CComponent *pComponent = new CComponent(this);
  73. if (NULL == pComponent)
  74. return E_OUTOFMEMORY;
  75. return pComponent->QueryInterface(IID_IComponent, (void **)ppComponent);
  76. return S_FALSE;
  77. }
  78. HRESULT CCompData::Notify(
  79. /* [in] */ LPDATAOBJECT lpDataObject,
  80. /* [in] */ MMC_NOTIFY_TYPE event,
  81. /* [in] */ LPARAM arg,
  82. /* [in] */ LPARAM param)
  83. {
  84. MMCN_Crack(TRUE, lpDataObject, this, NULL, event, arg, param);
  85. HRESULT hr = S_FALSE;
  86. //Get our data object. If it is NULL, we return with S_FALSE.
  87. //See implementation of GetOurDataObject() to see how to
  88. //handle special data objects.
  89. CDataObject *pDataObject = GetOurDataObject(lpDataObject);
  90. if (NULL == pDataObject)
  91. return S_FALSE;
  92. CDelegationBase *base = pDataObject->GetBaseNodeObject();
  93. switch (event)
  94. {
  95. case MMCN_PRELOAD:
  96. //The arg value passed into Notify holds the HSCOPEITEM of
  97. //the static node. Cache it for future use.
  98. m_pStaticNode->SetHandle((HANDLE)arg);
  99. //The static node's display name includes the name of the
  100. //currently targetted machine. MMC stores a static node's
  101. //display name in the .msc file. When loading a snap-in
  102. //from a .msc file, MMC uses the stored display name again
  103. //The only way for the snap-in to change the display name
  104. //is to support the CCF_SNAPINS_PRELOADS clipboard format
  105. //and to handle MMCN_PRELOAD.
  106. OnPreLoad(lpDataObject, arg, param);
  107. break;
  108. case MMCN_EXPAND:
  109. hr = base->OnExpand(m_ipConsoleNameSpace2, m_ipConsole, (HSCOPEITEM)param);
  110. break;
  111. case MMCN_ADD_IMAGES:
  112. hr = base->OnAddImages((IImageList *)arg, (HSCOPEITEM)param);
  113. break;
  114. case MMCN_REMOVE_CHILDREN:
  115. hr = base->OnRemoveChildren();
  116. break;
  117. }
  118. return hr;
  119. }
  120. HRESULT CCompData::OnPreLoad(LPDATAOBJECT lpDataObject, LPARAM arg, LPARAM param)
  121. {
  122. HRESULT hr = S_FALSE;
  123. USES_CONVERSION;
  124. SCOPEDATAITEM sdi;
  125. LPOLESTR wszName = NULL;
  126. const _TCHAR *pszName = m_pStaticNode->GetDisplayName();
  127. wszName = (LPOLESTR)T2COLE(pszName);
  128. ZeroMemory (&sdi, sizeof(SCOPEDATAITEM));
  129. sdi.mask = SDI_STR;
  130. sdi.displayname = wszName;
  131. sdi.ID = arg;
  132. hr = m_ipConsoleNameSpace2->SetItem(&sdi);
  133. if (S_OK != hr)
  134. return E_FAIL;
  135. return hr;
  136. }
  137. HRESULT CCompData::Destroy( void)
  138. {
  139. //Release handles to bitmaps created in CCompData::Initialize
  140. if (m_pBMapSm != NULL)
  141. DeleteObject(m_pBMapSm);
  142. if (m_pBMapLg != NULL)
  143. DeleteObject(m_pBMapLg);
  144. // Free interfaces
  145. if (m_ipConsoleNameSpace2) {
  146. m_ipConsoleNameSpace2->Release();
  147. m_ipConsoleNameSpace2 = NULL;
  148. }
  149. if (m_ipConsole) {
  150. m_ipConsole->Release();
  151. m_ipConsole = NULL;
  152. }
  153. return S_OK;
  154. }
  155. HRESULT CCompData::QueryDataObject(
  156. /* [in] */ MMC_COOKIE cookie,
  157. /* [in] */ DATA_OBJECT_TYPES type,
  158. /* [out] */ LPDATAOBJECT *ppDataObject)
  159. {
  160. CDataObject *pObj = NULL;
  161. if (cookie == 0)
  162. pObj = new CDataObject((MMC_COOKIE)m_pStaticNode, type);
  163. else
  164. pObj = new CDataObject(cookie, type);
  165. if (!pObj)
  166. return E_OUTOFMEMORY;
  167. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  168. return S_OK;
  169. }
  170. HRESULT CCompData::GetDisplayInfo(
  171. /* [out][in] */ SCOPEDATAITEM *pScopeDataItem)
  172. {
  173. LPOLESTR pszW = NULL;
  174. HRESULT hr = S_FALSE;
  175. // if they are asking for the SDI_STR we have one of those to give
  176. if (pScopeDataItem->lParam) {
  177. CDelegationBase *base = (CDelegationBase *)pScopeDataItem->lParam;
  178. if (pScopeDataItem->mask & SDI_STR) {
  179. LPCTSTR pszT = base->GetDisplayName();
  180. AllocOleStr(&pszW, (LPTSTR)pszT);
  181. pScopeDataItem->displayname = pszW;
  182. }
  183. if (pScopeDataItem->mask & SDI_IMAGE) {
  184. pScopeDataItem->nImage = base->GetBitmapIndex();
  185. }
  186. }
  187. return hr;
  188. }
  189. HRESULT CCompData::CompareObjects(
  190. /* [in] */ LPDATAOBJECT lpDataObjectA,
  191. /* [in] */ LPDATAOBJECT lpDataObjectB)
  192. {
  193. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  194. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  195. // compare the object pointers
  196. if (baseA->GetCookie() == baseB->GetCookie())
  197. return S_OK;
  198. return S_FALSE;
  199. }
  200. ///////////////////////////////////
  201. // Interface IExtendPropertySheet2
  202. ///////////////////////////////////
  203. HRESULT CCompData::CreatePropertyPages(
  204. /* [in] */ LPPROPERTYSHEETCALLBACK lpProvider,
  205. /* [in] */ LONG_PTR handle,
  206. /* [in] */ LPDATAOBJECT lpIDataObject)
  207. {
  208. return m_pStaticNode->CreatePropertyPages(lpProvider, handle);
  209. }
  210. HRESULT CCompData::QueryPagesFor(
  211. /* [in] */ LPDATAOBJECT lpDataObject)
  212. {
  213. return m_pStaticNode->HasPropertySheets();
  214. }
  215. HRESULT CCompData::GetWatermarks(
  216. /* [in] */ LPDATAOBJECT lpIDataObject,
  217. /* [out] */ HBITMAP __RPC_FAR *lphWatermark,
  218. /* [out] */ HBITMAP __RPC_FAR *lphHeader,
  219. /* [out] */ HPALETTE __RPC_FAR *lphPalette,
  220. /* [out] */ BOOL __RPC_FAR *bStretch)
  221. {
  222. return m_pStaticNode->GetWatermarks(lphWatermark, lphHeader, lphPalette, bStretch);
  223. }
  224. ///////////////////////////////
  225. // Interface IExtendContextMenu
  226. ///////////////////////////////
  227. HRESULT CCompData::AddMenuItems(
  228. /* [in] */ LPDATAOBJECT piDataObject,
  229. /* [in] */ LPCONTEXTMENUCALLBACK piCallback,
  230. /* [out][in] */ long __RPC_FAR *pInsertionAllowed)
  231. {
  232. CDelegationBase *base = GetOurDataObject(piDataObject)->GetBaseNodeObject();
  233. return base->OnAddMenuItems(piCallback, pInsertionAllowed);
  234. }
  235. HRESULT CCompData::Command(
  236. /* [in] */ long lCommandID,
  237. /* [in] */ LPDATAOBJECT piDataObject)
  238. {
  239. CDelegationBase *base = GetOurDataObject(piDataObject)->GetBaseNodeObject();
  240. return base->OnMenuCommand(m_ipConsole, m_ipConsoleNameSpace2, lCommandID, piDataObject);
  241. }
  242. ///////////////////////////////
  243. // Interface IPersistStream
  244. ///////////////////////////////
  245. HRESULT CCompData::GetClassID(
  246. /* [out] */ CLSID __RPC_FAR *pClassID)
  247. {
  248. *pClassID = m_pStaticNode->getNodeType();
  249. return S_OK;
  250. }
  251. HRESULT CCompData::IsDirty( void)
  252. {
  253. return m_pStaticNode->isDirty() == true ? S_OK : S_FALSE;
  254. }
  255. HRESULT CCompData::Load(
  256. /* [unique][in] */ IStream __RPC_FAR *pStm)
  257. {
  258. void *snapInData = m_pStaticNode->getData();
  259. ULONG dataSize = m_pStaticNode->getDataSize();
  260. return pStm->Read(snapInData, dataSize, NULL);
  261. }
  262. HRESULT CCompData::Save(
  263. /* [unique][in] */ IStream __RPC_FAR *pStm,
  264. /* [in] */ BOOL fClearDirty)
  265. {
  266. void *snapInData = m_pStaticNode->getData();
  267. ULONG dataSize = m_pStaticNode->getDataSize();
  268. if (fClearDirty)
  269. m_pStaticNode->clearDirty();
  270. return pStm->Write(snapInData, dataSize, NULL);
  271. }
  272. HRESULT CCompData::GetSizeMax(
  273. /* [out] */ ULARGE_INTEGER __RPC_FAR *pcbSize)
  274. {
  275. return m_pStaticNode->getDataSize();
  276. }