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.

255 lines
7.0 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_ISnapinHelp))
  55. *ppv = static_cast<ISnapinHelp*>(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. IImageList *pImageList;
  95. m_ipConsole->QueryScopeImageList(&pImageList);
  96. _ASSERT( S_OK == hr );
  97. hr = pImageList->ImageListSetStrip( (long *)m_pStaticNode->m_pBMapSm, // pointer to a handle
  98. (long *)m_pStaticNode->m_pBMapLg, // pointer to a handle
  99. 0, // index of the first image in the strip
  100. RGB(0, 128, 128) // color of the icon mask
  101. );
  102. pImageList->Release();
  103. return S_OK;
  104. }
  105. HRESULT CComponentData::CreateComponent(
  106. /* [out] */ LPCOMPONENT __RPC_FAR *ppComponent)
  107. {
  108. *ppComponent = NULL;
  109. CComponent *pComponent = new CComponent(this);
  110. if (NULL == pComponent)
  111. return E_OUTOFMEMORY;
  112. return pComponent->QueryInterface(IID_IComponent, (void **)ppComponent);
  113. }
  114. HRESULT CComponentData::Notify(
  115. /* [in] */ LPDATAOBJECT lpDataObject,
  116. /* [in] */ MMC_NOTIFY_TYPE event,
  117. /* [in] */ LPARAM arg,
  118. /* [in] */ LPARAM param)
  119. {
  120. MMCN_Crack(TRUE, lpDataObject, this, NULL, event, arg, param);
  121. HRESULT hr = S_FALSE;
  122. //Get our data object. If it is NULL, we return with S_FALSE.
  123. //See implementation of GetOurDataObject() to see how to
  124. //handle special data objects.
  125. CDataObject *pDataObject = GetOurDataObject(lpDataObject);
  126. if (NULL == pDataObject)
  127. return S_FALSE;
  128. CDelegationBase *base = pDataObject->GetBaseNodeObject();
  129. switch (event)
  130. {
  131. case MMCN_EXPAND:
  132. hr = base->OnExpand(m_ipConsoleNameSpace, m_ipConsole, (HSCOPEITEM)param);
  133. break;
  134. }
  135. return hr;
  136. }
  137. HRESULT CComponentData::Destroy( void)
  138. {
  139. // Free interfaces
  140. if (m_ipConsoleNameSpace) {
  141. m_ipConsoleNameSpace->Release();
  142. m_ipConsoleNameSpace = NULL;
  143. }
  144. if (m_ipConsole) {
  145. m_ipConsole->Release();
  146. m_ipConsole = NULL;
  147. }
  148. return S_OK;
  149. }
  150. HRESULT CComponentData::QueryDataObject(
  151. /* [in] */ MMC_COOKIE cookie,
  152. /* [in] */ DATA_OBJECT_TYPES type,
  153. /* [out] */ LPDATAOBJECT *ppDataObject)
  154. {
  155. CDataObject *pObj = NULL;
  156. if (cookie == 0)
  157. pObj = new CDataObject((MMC_COOKIE)m_pStaticNode, type);
  158. else
  159. pObj = new CDataObject(cookie, type);
  160. if (!pObj)
  161. return E_OUTOFMEMORY;
  162. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  163. return S_OK;
  164. }
  165. HRESULT CComponentData::GetDisplayInfo(
  166. /* [out][in] */ SCOPEDATAITEM *pScopeDataItem)
  167. {
  168. HRESULT hr = S_FALSE;
  169. // if they are asking for the SDI_STR we have one of those to give
  170. if (pScopeDataItem->lParam) {
  171. CDelegationBase *base = (CDelegationBase *)pScopeDataItem->lParam;
  172. if (pScopeDataItem->mask & SDI_STR) {
  173. LPCTSTR pszT = base->GetDisplayName();
  174. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  175. pScopeDataItem->displayname = pszW;
  176. }
  177. if (pScopeDataItem->mask & SDI_IMAGE) {
  178. pScopeDataItem->nImage = base->GetBitmapIndex();
  179. }
  180. }
  181. return hr;
  182. }
  183. HRESULT CComponentData::CompareObjects(
  184. /* [in] */ LPDATAOBJECT lpDataObjectA,
  185. /* [in] */ LPDATAOBJECT lpDataObjectB)
  186. {
  187. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  188. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  189. // compare the object pointers
  190. if (baseA->GetCookie() == baseB->GetCookie())
  191. return S_OK;
  192. return S_FALSE;
  193. }
  194. ///////////////////////////////
  195. // Interface ISnapinHelp
  196. ///////////////////////////////
  197. HRESULT CComponentData::GetHelpTopic(
  198. /* [out] */ LPOLESTR *lpCompiledHelpFile)
  199. {
  200. *lpCompiledHelpFile = static_cast<LPOLESTR>(CoTaskMemAlloc((wcslen(m_HelpFile) + 1) * sizeof(WCHAR)));
  201. wcscpy(*lpCompiledHelpFile, m_HelpFile);
  202. return S_OK;
  203. }