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.

225 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. TCHAR tmpHelpFile[MAX_PATH];
  29. GetWindowsDirectory(tmpHelpFile, sizeof(tmpHelpFile));
  30. _tcscat(tmpHelpFile, _T("\\HELP\\"));
  31. LoadString(g_hinst, IDS_HELPFILE, &tmpHelpFile[_tcslen(tmpHelpFile)], MAX_PATH - _tcslen(tmpHelpFile));
  32. MAKE_WIDEPTR_FROMTSTR(wszHelpFile, tmpHelpFile);
  33. wcscpy(m_HelpFile, wszHelpFile);
  34. }
  35. CComponentData::~CComponentData()
  36. {
  37. if (m_pStaticNode) {
  38. delete m_pStaticNode;
  39. }
  40. OBJECT_DESTROYED
  41. }
  42. ///////////////////////
  43. // IUnknown implementation
  44. ///////////////////////
  45. STDMETHODIMP CComponentData::QueryInterface(REFIID riid, LPVOID *ppv)
  46. {
  47. if (!ppv)
  48. return E_FAIL;
  49. *ppv = NULL;
  50. if (IsEqualIID(riid, IID_IUnknown))
  51. *ppv = static_cast<IComponentData *>(this);
  52. else if (IsEqualIID(riid, IID_IComponentData))
  53. *ppv = static_cast<IComponentData *>(this);
  54. else if (IsEqualIID(riid, IID_ISnapinHelp2))
  55. *ppv = static_cast<ISnapinHelp2*>(this);
  56. if (*ppv)
  57. {
  58. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  59. return S_OK;
  60. }
  61. return E_NOINTERFACE;
  62. }
  63. STDMETHODIMP_(ULONG) CComponentData::AddRef()
  64. {
  65. return InterlockedIncrement((LONG *)&m_cref);
  66. }
  67. STDMETHODIMP_(ULONG) CComponentData::Release()
  68. {
  69. if (InterlockedDecrement((LONG *)&m_cref) == 0)
  70. {
  71. // we need to decrement our object count in the DLL
  72. delete this;
  73. return 0;
  74. }
  75. return m_cref;
  76. }
  77. ///////////////////////////////
  78. // Interface IComponentData
  79. ///////////////////////////////
  80. HRESULT CComponentData::Initialize(
  81. /* [in] */ LPUNKNOWN pUnknown)
  82. {
  83. HRESULT hr;
  84. //
  85. // Get pointer to name space interface
  86. //
  87. hr = pUnknown->QueryInterface(IID_IConsoleNameSpace, (void **)&m_ipConsoleNameSpace);
  88. _ASSERT( S_OK == hr );
  89. //
  90. // Get pointer to console interface
  91. //
  92. hr = pUnknown->QueryInterface(IID_IConsole, (void **)&m_ipConsole);
  93. _ASSERT( S_OK == hr );
  94. return S_OK;
  95. }
  96. HRESULT CComponentData::CreateComponent(
  97. /* [out] */ LPCOMPONENT __RPC_FAR *ppComponent)
  98. {
  99. *ppComponent = NULL;
  100. CComponent *pComponent = new CComponent(this);
  101. if (NULL == pComponent)
  102. return E_OUTOFMEMORY;
  103. return pComponent->QueryInterface(IID_IComponent, (void **)ppComponent);
  104. }
  105. HRESULT CComponentData::Notify(
  106. /* [in] */ LPDATAOBJECT lpDataObject,
  107. /* [in] */ MMC_NOTIFY_TYPE event,
  108. /* [in] */ LPARAM arg,
  109. /* [in] */ LPARAM param)
  110. {
  111. MMCN_Crack(TRUE, lpDataObject, this, NULL, event, arg, param);
  112. return S_FALSE;
  113. }
  114. HRESULT CComponentData::Destroy( void)
  115. {
  116. // Free interfaces
  117. if (m_ipConsoleNameSpace) {
  118. m_ipConsoleNameSpace->Release();
  119. m_ipConsoleNameSpace = NULL;
  120. }
  121. if (m_ipConsole) {
  122. m_ipConsole->Release();
  123. m_ipConsole = NULL;
  124. }
  125. return S_OK;
  126. }
  127. HRESULT CComponentData::QueryDataObject(
  128. /* [in] */ MMC_COOKIE cookie,
  129. /* [in] */ DATA_OBJECT_TYPES type,
  130. /* [out] */ LPDATAOBJECT *ppDataObject)
  131. {
  132. CDataObject *pObj = NULL;
  133. if (cookie == 0)
  134. pObj = new CDataObject((MMC_COOKIE)m_pStaticNode, type);
  135. else
  136. pObj = new CDataObject(cookie, type);
  137. if (!pObj)
  138. return E_OUTOFMEMORY;
  139. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  140. return S_OK;
  141. }
  142. HRESULT CComponentData::GetDisplayInfo(
  143. /* [out][in] */ SCOPEDATAITEM *pScopeDataItem)
  144. {
  145. HRESULT hr = S_FALSE;
  146. // if they are asking for the SDI_STR we have one of those to give
  147. if (pScopeDataItem->lParam) {
  148. CDelegationBase *base = (CDelegationBase *)pScopeDataItem->lParam;
  149. if (pScopeDataItem->mask & SDI_STR) {
  150. LPCTSTR pszT = base->GetDisplayName();
  151. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  152. pScopeDataItem->displayname = pszW;
  153. }
  154. if (pScopeDataItem->mask & SDI_IMAGE) {
  155. pScopeDataItem->nImage = base->GetBitmapIndex();
  156. }
  157. }
  158. return hr;
  159. }
  160. HRESULT CComponentData::CompareObjects(
  161. /* [in] */ LPDATAOBJECT lpDataObjectA,
  162. /* [in] */ LPDATAOBJECT lpDataObjectB)
  163. {
  164. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  165. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  166. // compare the object pointers
  167. if (baseA->GetCookie() == baseB->GetCookie())
  168. return S_OK;
  169. return S_FALSE;
  170. }
  171. ///////////////////////////////
  172. // Interface ISnapinHelp
  173. ///////////////////////////////
  174. HRESULT CComponentData::GetHelpTopic(
  175. /* [out] */ LPOLESTR *lpCompiledHelpFile)
  176. {
  177. *lpCompiledHelpFile = static_cast<LPOLESTR>(CoTaskMemAlloc((wcslen(m_HelpFile) + 1) * sizeof(WCHAR)));
  178. wcscpy(*lpCompiledHelpFile, m_HelpFile);
  179. return S_OK;
  180. }