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.

258 lines
7.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. else if (IsEqualIID(riid, IID_IPersistStream))
  49. *ppv = static_cast<IPersistStream *>(this);
  50. if (*ppv)
  51. {
  52. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  53. return S_OK;
  54. }
  55. return E_NOINTERFACE;
  56. }
  57. STDMETHODIMP_(ULONG) CComponentData::AddRef()
  58. {
  59. return InterlockedIncrement((LONG *)&m_cref);
  60. }
  61. STDMETHODIMP_(ULONG) CComponentData::Release()
  62. {
  63. if (InterlockedDecrement((LONG *)&m_cref) == 0)
  64. {
  65. // we need to decrement our object count in the DLL
  66. delete this;
  67. return 0;
  68. }
  69. return m_cref;
  70. }
  71. ///////////////////////////////
  72. // Interface IComponentData
  73. ///////////////////////////////
  74. HRESULT CComponentData::Initialize(
  75. /* [in] */ LPUNKNOWN pUnknown)
  76. {
  77. HRESULT hr = S_FALSE;
  78. //
  79. // Get pointer to namespace interface
  80. // First try to get pointer to IConsoleNameSpace2. If that fails, we are in
  81. // MMC1.0, so get pointer to IConsoleNameSpace instead
  82. //
  83. hr = pUnknown->QueryInterface(IID_IConsoleNameSpace2, (void **)&m_ipConsoleNameSpace);
  84. if (S_OK == hr)
  85. {
  86. //We are in MMC 1.1 or higher. QI for IConsole2
  87. hr = pUnknown->QueryInterface(IID_IConsole2, (void **)&m_ipConsole);
  88. }
  89. else //We are in MMC 1.0
  90. {
  91. hr = pUnknown->QueryInterface(IID_IConsoleNameSpace, (void **)&m_ipConsoleNameSpace);
  92. if (FAILED(hr))
  93. return hr;
  94. hr = pUnknown->QueryInterface(IID_IConsole, (void **)&m_ipConsole);
  95. }
  96. return hr;
  97. }
  98. HRESULT CComponentData::CreateComponent(
  99. /* [out] */ LPCOMPONENT __RPC_FAR *ppComponent)
  100. {
  101. *ppComponent = NULL;
  102. CComponent *pComponent = new CComponent(this);
  103. if (NULL == pComponent)
  104. return E_OUTOFMEMORY;
  105. return pComponent->QueryInterface(IID_IComponent, (void **)ppComponent);
  106. }
  107. HRESULT CComponentData::Notify(
  108. /* [in] */ LPDATAOBJECT lpDataObject,
  109. /* [in] */ MMC_NOTIFY_TYPE event,
  110. /* [in] */ LPARAM arg,
  111. /* [in] */ LPARAM param)
  112. {
  113. MMCN_Crack(TRUE, lpDataObject, this, NULL, event, arg, param);
  114. //Notify doesn't handle any notifications from MMC, so return E_NOTIMPL
  115. return E_NOTIMPL;
  116. }
  117. HRESULT CComponentData::Destroy( void)
  118. {
  119. // Free interfaces
  120. if (m_ipConsoleNameSpace) {
  121. m_ipConsoleNameSpace->Release();
  122. m_ipConsoleNameSpace = NULL;
  123. }
  124. if (m_ipConsole) {
  125. m_ipConsole->Release();
  126. m_ipConsole = NULL;
  127. }
  128. return S_OK;
  129. }
  130. HRESULT CComponentData::QueryDataObject(
  131. /* [in] */ MMC_COOKIE cookie,
  132. /* [in] */ DATA_OBJECT_TYPES type,
  133. /* [out] */ LPDATAOBJECT *ppDataObject)
  134. {
  135. CDataObject *pObj = NULL;
  136. if (cookie == 0)
  137. pObj = new CDataObject((MMC_COOKIE)m_pStaticNode, type);
  138. else
  139. pObj = new CDataObject(cookie, type);
  140. if (!pObj)
  141. return E_OUTOFMEMORY;
  142. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  143. return S_OK;
  144. }
  145. HRESULT CComponentData::GetDisplayInfo(
  146. /* [out][in] */ SCOPEDATAITEM *pScopeDataItem)
  147. {
  148. HRESULT hr = S_FALSE;
  149. // if they are asking for the SDI_STR we have one of those to give
  150. if (pScopeDataItem->lParam) {
  151. CDelegationBase *base = (CDelegationBase *)pScopeDataItem->lParam;
  152. if (pScopeDataItem->mask & SDI_STR) {
  153. LPCTSTR pszT = base->GetDisplayName();
  154. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  155. pScopeDataItem->displayname = pszW;
  156. }
  157. if (pScopeDataItem->mask & SDI_IMAGE) {
  158. pScopeDataItem->nImage = base->GetBitmapIndex();
  159. }
  160. }
  161. return hr;
  162. }
  163. HRESULT CComponentData::CompareObjects(
  164. /* [in] */ LPDATAOBJECT lpDataObjectA,
  165. /* [in] */ LPDATAOBJECT lpDataObjectB)
  166. {
  167. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  168. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  169. // compare the object pointers
  170. if (baseA->GetCookie() == baseB->GetCookie())
  171. return S_OK;
  172. return S_FALSE;
  173. }
  174. ///////////////////////////////
  175. // Interface IPersistStream
  176. ///////////////////////////////
  177. HRESULT CComponentData::GetClassID(
  178. /* [out] */ CLSID __RPC_FAR *pClassID)
  179. {
  180. *pClassID = m_pStaticNode->getNodeType();
  181. return S_OK;
  182. }
  183. HRESULT CComponentData::IsDirty( void)
  184. {
  185. return m_pStaticNode->isDirty() == true ? S_OK : S_FALSE;
  186. }
  187. HRESULT CComponentData::Load(
  188. /* [unique][in] */ IStream __RPC_FAR *pStm)
  189. {
  190. void *snapInData = m_pStaticNode->getData();
  191. ULONG dataSize = m_pStaticNode->getDataSize();
  192. return pStm->Read(snapInData, dataSize, NULL);
  193. }
  194. HRESULT CComponentData::Save(
  195. /* [unique][in] */ IStream __RPC_FAR *pStm,
  196. /* [in] */ BOOL fClearDirty)
  197. {
  198. void *snapInData = m_pStaticNode->getData();
  199. ULONG dataSize = m_pStaticNode->getDataSize();
  200. if (fClearDirty)
  201. m_pStaticNode->clearDirty();
  202. return pStm->Write(snapInData, dataSize, NULL);
  203. }
  204. HRESULT CComponentData::GetSizeMax(
  205. /* [out] */ ULARGE_INTEGER __RPC_FAR *pcbSize)
  206. {
  207. return m_pStaticNode->getDataSize();
  208. }