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.

235 lines
6.3 KiB

  1. //==============================================================;
  2. //
  3. // This source code is only intended as a supplement to existing Microsoft documentation.
  4. //
  5. //
  6. //
  7. //
  8. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  9. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  10. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  11. // PURPOSE.
  12. //
  13. // Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  14. //
  15. //
  16. //
  17. //==============================================================;
  18. #include "Comp.h"
  19. #include "CompData.h"
  20. #include "DataObj.h"
  21. #include "resource.h"
  22. #include <crtdbg.h>
  23. CComponentData::CComponentData()
  24. : m_cref(0), m_ipConsoleNameSpace(NULL), m_ipConsole(NULL)
  25. {
  26. OBJECT_CREATED
  27. m_pStaticNode = new CStaticNode;
  28. }
  29. CComponentData::~CComponentData()
  30. {
  31. if (m_pStaticNode) {
  32. delete m_pStaticNode;
  33. }
  34. OBJECT_DESTROYED
  35. }
  36. ///////////////////////
  37. // IUnknown implementation
  38. ///////////////////////
  39. STDMETHODIMP CComponentData::QueryInterface(REFIID riid, LPVOID *ppv)
  40. {
  41. if (!ppv)
  42. return E_FAIL;
  43. *ppv = NULL;
  44. if (IsEqualIID(riid, IID_IUnknown))
  45. *ppv = static_cast<IComponentData *>(this);
  46. else if (IsEqualIID(riid, IID_IComponentData))
  47. *ppv = static_cast<IComponentData *>(this);
  48. if (*ppv)
  49. {
  50. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  51. return S_OK;
  52. }
  53. return E_NOINTERFACE;
  54. }
  55. STDMETHODIMP_(ULONG) CComponentData::AddRef()
  56. {
  57. return InterlockedIncrement((LONG *)&m_cref);
  58. }
  59. STDMETHODIMP_(ULONG) CComponentData::Release()
  60. {
  61. if (InterlockedDecrement((LONG *)&m_cref) == 0)
  62. {
  63. // we need to decrement our object count in the DLL
  64. delete this;
  65. return 0;
  66. }
  67. return m_cref;
  68. }
  69. ///////////////////////////////
  70. // Interface IComponentData
  71. ///////////////////////////////
  72. HRESULT CComponentData::Initialize(
  73. /* [in] */ LPUNKNOWN pUnknown)
  74. {
  75. HRESULT hr;
  76. //
  77. // Get pointer to name space interface
  78. //
  79. hr = pUnknown->QueryInterface(IID_IConsoleNameSpace, (void **)&m_ipConsoleNameSpace);
  80. _ASSERT( S_OK == hr );
  81. //
  82. // Get pointer to console interface
  83. //
  84. hr = pUnknown->QueryInterface(IID_IConsole, (void **)&m_ipConsole);
  85. _ASSERT( S_OK == hr );
  86. IImageList *pImageList;
  87. m_ipConsole->QueryScopeImageList(&pImageList);
  88. _ASSERT( S_OK == hr );
  89. hr = pImageList->ImageListSetStrip( (long *)m_pStaticNode->m_pBMapSm, // pointer to a handle
  90. (long *)m_pStaticNode->m_pBMapLg, // pointer to a handle
  91. 0, // index of the first image in the strip
  92. RGB(0, 128, 128) // color of the icon mask
  93. );
  94. pImageList->Release();
  95. return S_OK;
  96. }
  97. HRESULT CComponentData::CreateComponent(
  98. /* [out] */ LPCOMPONENT __RPC_FAR *ppComponent)
  99. {
  100. *ppComponent = NULL;
  101. CComponent *pComponent = new CComponent(this);
  102. if (NULL == pComponent)
  103. return E_OUTOFMEMORY;
  104. return pComponent->QueryInterface(IID_IComponent, (void **)ppComponent);
  105. }
  106. HRESULT CComponentData::Notify(
  107. /* [in] */ LPDATAOBJECT lpDataObject,
  108. /* [in] */ MMC_NOTIFY_TYPE event,
  109. /* [in] */ LPARAM arg,
  110. /* [in] */ LPARAM param)
  111. {
  112. MMCN_Crack(TRUE, lpDataObject, this, NULL, event, arg, param);
  113. HRESULT hr = S_FALSE;
  114. //Get our data object. If it is NULL, we return with S_FALSE.
  115. //See implementation of GetOurDataObject() to see how to
  116. //handle special data objects.
  117. CDataObject *pDataObject = GetOurDataObject(lpDataObject);
  118. if (NULL == pDataObject)
  119. return S_FALSE;
  120. CDelegationBase *base = pDataObject->GetBaseNodeObject();
  121. switch (event)
  122. {
  123. case MMCN_EXPAND:
  124. hr = base->OnExpand(m_ipConsoleNameSpace, m_ipConsole, (HSCOPEITEM)param);
  125. break;
  126. case MMCN_ADD_IMAGES:
  127. hr = base->OnAddImages((IImageList *)arg, (HSCOPEITEM)param);
  128. break;
  129. }
  130. return hr;
  131. }
  132. HRESULT CComponentData::Destroy( void)
  133. {
  134. // Free interfaces
  135. if (m_ipConsoleNameSpace) {
  136. m_ipConsoleNameSpace->Release();
  137. m_ipConsoleNameSpace = NULL;
  138. }
  139. if (m_ipConsole) {
  140. m_ipConsole->Release();
  141. m_ipConsole = NULL;
  142. }
  143. return S_OK;
  144. }
  145. HRESULT CComponentData::QueryDataObject(
  146. /* [in] */ MMC_COOKIE cookie,
  147. /* [in] */ DATA_OBJECT_TYPES type,
  148. /* [out] */ LPDATAOBJECT *ppDataObject)
  149. {
  150. CDataObject *pObj = NULL;
  151. if (cookie == 0)
  152. pObj = new CDataObject((MMC_COOKIE)m_pStaticNode, type);
  153. else
  154. pObj = new CDataObject(cookie, type);
  155. if (!pObj)
  156. return E_OUTOFMEMORY;
  157. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  158. return S_OK;
  159. }
  160. HRESULT CComponentData::GetDisplayInfo(
  161. /* [out][in] */ SCOPEDATAITEM *pScopeDataItem)
  162. {
  163. HRESULT hr = S_FALSE;
  164. // if they are asking for the SDI_STR we have one of those to give
  165. if (pScopeDataItem->lParam) {
  166. CDelegationBase *base = (CDelegationBase *)pScopeDataItem->lParam;
  167. if (pScopeDataItem->mask & SDI_STR) {
  168. LPCTSTR pszT = base->GetDisplayName();
  169. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  170. pScopeDataItem->displayname = pszW;
  171. }
  172. if (pScopeDataItem->mask & SDI_IMAGE) {
  173. pScopeDataItem->nImage = base->GetBitmapIndex();
  174. }
  175. }
  176. return hr;
  177. }
  178. HRESULT CComponentData::CompareObjects(
  179. /* [in] */ LPDATAOBJECT lpDataObjectA,
  180. /* [in] */ LPDATAOBJECT lpDataObjectB)
  181. {
  182. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  183. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  184. // compare the object pointers
  185. if (baseA->GetCookie() == baseB->GetCookie())
  186. return S_OK;
  187. return S_FALSE;
  188. }