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.

219 lines
5.9 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. #include "stdafx.h"
  13. #include "Comp.h"
  14. #include "DataObj.h"
  15. #include <crtdbg.h>
  16. #include "globals.h"
  17. #include "resource.h"
  18. #include "DeleBase.h"
  19. #include "ClassExtSnap.h"
  20. CComponent::CComponent(CClassExtSnap *parent)
  21. : m_pComponentData(parent), m_cref(0), m_ipConsole(NULL), m_ipDisplayHelp(NULL)
  22. {
  23. }
  24. CComponent::~CComponent()
  25. {
  26. }
  27. STDMETHODIMP CComponent::QueryInterface(REFIID riid, LPVOID *ppv)
  28. {
  29. if (!ppv)
  30. return E_FAIL;
  31. *ppv = NULL;
  32. if (IsEqualIID(riid, IID_IUnknown))
  33. *ppv = static_cast<IComponent *>(this);
  34. else if (IsEqualIID(riid, IID_IComponent))
  35. *ppv = static_cast<IComponent *>(this);
  36. if (*ppv)
  37. {
  38. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  39. return S_OK;
  40. }
  41. return E_NOINTERFACE;
  42. }
  43. STDMETHODIMP_(ULONG) CComponent::AddRef()
  44. {
  45. return InterlockedIncrement((LONG *)&m_cref);
  46. }
  47. STDMETHODIMP_(ULONG) CComponent::Release()
  48. {
  49. if (InterlockedDecrement((LONG *)&m_cref) == 0)
  50. {
  51. delete this;
  52. return 0;
  53. }
  54. return m_cref;
  55. }
  56. ///////////////////////////////
  57. // Interface IComponent
  58. ///////////////////////////////
  59. STDMETHODIMP CComponent::Initialize(
  60. /* [in] */ LPCONSOLE lpConsole)
  61. {
  62. HRESULT hr = S_OK;
  63. // Save away all the interfaces we'll need.
  64. // Fail if we can't QI the required interfaces.
  65. m_ipConsole = lpConsole;
  66. m_ipConsole->AddRef();
  67. hr = m_ipConsole->QueryInterface(IID_IDisplayHelp, (void **)&m_ipDisplayHelp);
  68. return hr;
  69. }
  70. STDMETHODIMP CComponent::Notify(
  71. /* [in] */ LPDATAOBJECT lpDataObject,
  72. /* [in] */ MMC_NOTIFY_TYPE event,
  73. /* [in] */ LPARAM arg,
  74. /* [in] */ LPARAM param)
  75. {
  76. MMCN_Crack(FALSE, lpDataObject, NULL, this, event, arg, param);
  77. HRESULT hr = S_FALSE;
  78. //Get our data object. If it is NULL, we return with S_FALSE.
  79. //See implementation of GetOurDataObject() to see how to
  80. //handle special data objects.
  81. CDataObject *pDataObject = GetOurDataObject(lpDataObject);
  82. if (NULL == pDataObject)
  83. return S_FALSE;
  84. CDelegationBase *base = pDataObject->GetBaseNodeObject();
  85. switch (event) {
  86. case MMCN_ADD_IMAGES:
  87. hr = base->OnAddImages((IImageList *)arg, (HSCOPEITEM)param);
  88. break;
  89. case MMCN_SHOW:
  90. hr = base->OnShow(m_ipConsole, (BOOL)arg, (HSCOPEITEM)param);
  91. break;
  92. }
  93. return hr;
  94. }
  95. STDMETHODIMP CComponent::Destroy(
  96. /* [in] */ MMC_COOKIE cookie)
  97. {
  98. if (m_ipConsole) {
  99. m_ipConsole->Release();
  100. m_ipConsole = NULL;
  101. }
  102. if (m_ipDisplayHelp) {
  103. m_ipDisplayHelp->Release();
  104. m_ipDisplayHelp = NULL;
  105. }
  106. return S_OK;
  107. }
  108. STDMETHODIMP CComponent::QueryDataObject(
  109. /* [in] */ MMC_COOKIE cookie,
  110. /* [in] */ DATA_OBJECT_TYPES type,
  111. /* [out] */ LPDATAOBJECT __RPC_FAR *ppDataObject)
  112. {
  113. CDataObject *pObj = NULL;
  114. //cookie always != 0 for namespace extensions)
  115. //if (cookie == 0) //static node
  116. // pObj = new CDataObject((MMC_COOKIE)m_pComponentData, type);
  117. //else
  118. pObj = new CDataObject(cookie, type);
  119. if (!pObj)
  120. return E_OUTOFMEMORY;
  121. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  122. return S_OK;
  123. }
  124. STDMETHODIMP CComponent::GetResultViewType(
  125. /* [in] */ MMC_COOKIE cookie,
  126. /* [out] */ LPOLESTR __RPC_FAR *ppViewType,
  127. /* [out] */ long __RPC_FAR *pViewOptions)
  128. {
  129. CDelegationBase *base = (CDelegationBase *)cookie;
  130. //
  131. // Ask for default listview.
  132. //
  133. if (base == NULL)
  134. {
  135. *pViewOptions = MMC_VIEW_OPTIONS_NONE;
  136. *ppViewType = NULL;
  137. }
  138. else
  139. return base->GetResultViewType(ppViewType, pViewOptions);
  140. return S_OK;
  141. }
  142. STDMETHODIMP CComponent::GetDisplayInfo(
  143. /* [out][in] */ RESULTDATAITEM __RPC_FAR *pResultDataItem)
  144. {
  145. LPOLESTR pszW = NULL;
  146. HRESULT hr = S_OK;
  147. CDelegationBase *base = NULL;
  148. // if they are asking for the RDI_STR we have one of those to give
  149. if (pResultDataItem->lParam) {
  150. base = (CDelegationBase *)pResultDataItem->lParam;
  151. if (pResultDataItem->mask & RDI_STR) {
  152. LPCTSTR pszT = base->GetDisplayName(pResultDataItem->nCol);
  153. AllocOleStr(&pszW, (LPTSTR)pszT);
  154. pResultDataItem->str = pszW;
  155. }
  156. if (pResultDataItem->mask & RDI_IMAGE) {
  157. pResultDataItem->nImage = base->GetBitmapIndex();
  158. }
  159. }
  160. return hr;
  161. }
  162. STDMETHODIMP CComponent::CompareObjects(
  163. /* [in] */ LPDATAOBJECT lpDataObjectA,
  164. /* [in] */ LPDATAOBJECT lpDataObjectB)
  165. {
  166. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  167. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  168. // compare the object pointers
  169. if (baseA->GetCookie() == baseB->GetCookie())
  170. return S_OK;
  171. return S_FALSE;
  172. }