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.

231 lines
6.1 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. }
  127. return hr;
  128. }
  129. HRESULT CComponentData::Destroy( void)
  130. {
  131. // Free interfaces
  132. if (m_ipConsoleNameSpace) {
  133. m_ipConsoleNameSpace->Release();
  134. m_ipConsoleNameSpace = NULL;
  135. }
  136. if (m_ipConsole) {
  137. m_ipConsole->Release();
  138. m_ipConsole = NULL;
  139. }
  140. return S_OK;
  141. }
  142. HRESULT CComponentData::QueryDataObject(
  143. /* [in] */ MMC_COOKIE cookie,
  144. /* [in] */ DATA_OBJECT_TYPES type,
  145. /* [out] */ LPDATAOBJECT *ppDataObject)
  146. {
  147. CDataObject *pObj = NULL;
  148. if (cookie == 0)
  149. pObj = new CDataObject((MMC_COOKIE)m_pStaticNode, type);
  150. else
  151. pObj = new CDataObject(cookie, type);
  152. if (!pObj)
  153. return E_OUTOFMEMORY;
  154. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  155. return S_OK;
  156. }
  157. HRESULT CComponentData::GetDisplayInfo(
  158. /* [out][in] */ SCOPEDATAITEM *pScopeDataItem)
  159. {
  160. HRESULT hr = S_FALSE;
  161. // if they are asking for the SDI_STR we have one of those to give
  162. if (pScopeDataItem->lParam) {
  163. CDelegationBase *base = (CDelegationBase *)pScopeDataItem->lParam;
  164. if (pScopeDataItem->mask & SDI_STR) {
  165. LPCTSTR pszT = base->GetDisplayName();
  166. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  167. pScopeDataItem->displayname = pszW;
  168. }
  169. if (pScopeDataItem->mask & SDI_IMAGE) {
  170. pScopeDataItem->nImage = base->GetBitmapIndex();
  171. }
  172. }
  173. return hr;
  174. }
  175. HRESULT CComponentData::CompareObjects(
  176. /* [in] */ LPDATAOBJECT lpDataObjectA,
  177. /* [in] */ LPDATAOBJECT lpDataObjectB)
  178. {
  179. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  180. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  181. // compare the object pointers
  182. if (baseA->GetCookie() == baseB->GetCookie())
  183. return S_OK;
  184. return S_FALSE;
  185. }