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.

197 lines
5.2 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. // Get pointer to name space interface
  77. hr = pUnknown->QueryInterface(IID_IConsoleNameSpace, (void **)&m_ipConsoleNameSpace);
  78. _ASSERT( S_OK == hr );
  79. // Get pointer to console interface
  80. hr = pUnknown->QueryInterface(IID_IConsole, (void **)&m_ipConsole);
  81. _ASSERT( S_OK == hr );
  82. return S_OK;
  83. }
  84. HRESULT CComponentData::CreateComponent(
  85. /* [out] */ LPCOMPONENT __RPC_FAR *ppComponent)
  86. {
  87. *ppComponent = NULL;
  88. CComponent *pComponent = new CComponent(this);
  89. if (NULL == pComponent)
  90. return E_OUTOFMEMORY;
  91. return pComponent->QueryInterface(IID_IComponent, (void **)ppComponent);
  92. }
  93. HRESULT CComponentData::Notify(
  94. /* [in] */ LPDATAOBJECT lpDataObject,
  95. /* [in] */ MMC_NOTIFY_TYPE event,
  96. /* [in] */ LPARAM arg,
  97. /* [in] */ LPARAM param)
  98. {
  99. MMCN_Crack(TRUE, lpDataObject, this, NULL, event, arg, param);
  100. return S_FALSE;
  101. }
  102. HRESULT CComponentData::Destroy( void)
  103. {
  104. // Free interfaces
  105. if (m_ipConsoleNameSpace) {
  106. m_ipConsoleNameSpace->Release();
  107. m_ipConsoleNameSpace = NULL;
  108. }
  109. if (m_ipConsole) {
  110. m_ipConsole->Release();
  111. m_ipConsole = NULL;
  112. }
  113. return S_OK;
  114. }
  115. HRESULT CComponentData::QueryDataObject(
  116. /* [in] */ MMC_COOKIE cookie,
  117. /* [in] */ DATA_OBJECT_TYPES type,
  118. /* [out] */ LPDATAOBJECT *ppDataObject)
  119. {
  120. CDataObject *pObj = NULL;
  121. if (cookie == 0)
  122. pObj = new CDataObject((MMC_COOKIE)m_pStaticNode, type);
  123. else
  124. pObj = new CDataObject(cookie, type);
  125. if (!pObj)
  126. return E_OUTOFMEMORY;
  127. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  128. return S_OK;
  129. }
  130. HRESULT CComponentData::GetDisplayInfo(
  131. /* [out][in] */ SCOPEDATAITEM *pScopeDataItem)
  132. {
  133. HRESULT hr = S_FALSE;
  134. // if they are asking for the SDI_STR we have one of those to give
  135. if (pScopeDataItem->lParam) {
  136. CDelegationBase *base = (CDelegationBase *)pScopeDataItem->lParam;
  137. if (pScopeDataItem->mask & SDI_STR) {
  138. LPCTSTR pszT = base->GetDisplayName();
  139. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  140. pScopeDataItem->displayname = pszW;
  141. }
  142. if (pScopeDataItem->mask & SDI_IMAGE) {
  143. pScopeDataItem->nImage = base->GetBitmapIndex();
  144. }
  145. }
  146. return hr;
  147. }
  148. HRESULT CComponentData::CompareObjects(
  149. /* [in] */ LPDATAOBJECT lpDataObjectA,
  150. /* [in] */ LPDATAOBJECT lpDataObjectB)
  151. {
  152. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  153. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  154. // compare the object pointers
  155. if (baseA->GetCookie() == baseB->GetCookie())
  156. return S_OK;
  157. return S_FALSE;
  158. }