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.

280 lines
7.9 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_IExtendContextMenu))
  55. *ppv = static_cast<IExtendContextMenu *>(this);
  56. else if (IsEqualIID(riid, IID_ISnapinHelp))
  57. *ppv = static_cast<ISnapinHelp*>(this);
  58. if (*ppv)
  59. {
  60. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  61. return S_OK;
  62. }
  63. return E_NOINTERFACE;
  64. }
  65. STDMETHODIMP_(ULONG) CComponentData::AddRef()
  66. {
  67. return InterlockedIncrement((LONG *)&m_cref);
  68. }
  69. STDMETHODIMP_(ULONG) CComponentData::Release()
  70. {
  71. if (InterlockedDecrement((LONG *)&m_cref) == 0)
  72. {
  73. // we need to decrement our object count in the DLL
  74. delete this;
  75. return 0;
  76. }
  77. return m_cref;
  78. }
  79. ///////////////////////////////
  80. // Interface IComponentData
  81. ///////////////////////////////
  82. HRESULT CComponentData::Initialize(
  83. /* [in] */ LPUNKNOWN pUnknown)
  84. {
  85. HRESULT hr;
  86. //
  87. // Get pointer to name space interface
  88. //
  89. hr = pUnknown->QueryInterface(IID_IConsoleNameSpace, (void **)&m_ipConsoleNameSpace);
  90. _ASSERT( S_OK == hr );
  91. //
  92. // Get pointer to console interface
  93. //
  94. hr = pUnknown->QueryInterface(IID_IConsole, (void **)&m_ipConsole);
  95. _ASSERT( S_OK == hr );
  96. IImageList *pImageList;
  97. m_ipConsole->QueryScopeImageList(&pImageList);
  98. _ASSERT( S_OK == hr );
  99. hr = pImageList->ImageListSetStrip( (long *)m_pStaticNode->m_pBMapSm, // pointer to a handle
  100. (long *)m_pStaticNode->m_pBMapLg, // pointer to a handle
  101. 0, // index of the first image in the strip
  102. RGB(0, 128, 128) // color of the icon mask
  103. );
  104. pImageList->Release();
  105. return S_OK;
  106. }
  107. HRESULT CComponentData::CreateComponent(
  108. /* [out] */ LPCOMPONENT __RPC_FAR *ppComponent)
  109. {
  110. *ppComponent = NULL;
  111. CComponent *pComponent = new CComponent(this);
  112. if (NULL == pComponent)
  113. return E_OUTOFMEMORY;
  114. return pComponent->QueryInterface(IID_IComponent, (void **)ppComponent);
  115. }
  116. HRESULT CComponentData::Notify(
  117. /* [in] */ LPDATAOBJECT lpDataObject,
  118. /* [in] */ MMC_NOTIFY_TYPE event,
  119. /* [in] */ LPARAM arg,
  120. /* [in] */ LPARAM param)
  121. {
  122. MMCN_Crack(TRUE, lpDataObject, this, NULL, event, arg, param);
  123. HRESULT hr = S_FALSE;
  124. //Get our data object. If it is NULL, we return with S_FALSE.
  125. //See implementation of GetOurDataObject() to see how to
  126. //handle special data objects.
  127. CDataObject *pDataObject = GetOurDataObject(lpDataObject);
  128. if (NULL == pDataObject)
  129. return S_FALSE;
  130. CDelegationBase *base = pDataObject->GetBaseNodeObject();
  131. switch (event)
  132. {
  133. case MMCN_EXPAND:
  134. hr = base->OnExpand(m_ipConsoleNameSpace, m_ipConsole, (HSCOPEITEM)param);
  135. break;
  136. }
  137. return hr;
  138. }
  139. HRESULT CComponentData::Destroy( void)
  140. {
  141. // Free interfaces
  142. if (m_ipConsoleNameSpace) {
  143. m_ipConsoleNameSpace->Release();
  144. m_ipConsoleNameSpace = NULL;
  145. }
  146. if (m_ipConsole) {
  147. m_ipConsole->Release();
  148. m_ipConsole = NULL;
  149. }
  150. return S_OK;
  151. }
  152. HRESULT CComponentData::QueryDataObject(
  153. /* [in] */ MMC_COOKIE cookie,
  154. /* [in] */ DATA_OBJECT_TYPES type,
  155. /* [out] */ LPDATAOBJECT *ppDataObject)
  156. {
  157. CDataObject *pObj = NULL;
  158. if (cookie == 0)
  159. pObj = new CDataObject((MMC_COOKIE)m_pStaticNode, type);
  160. else
  161. pObj = new CDataObject(cookie, type);
  162. if (!pObj)
  163. return E_OUTOFMEMORY;
  164. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  165. return S_OK;
  166. }
  167. HRESULT CComponentData::GetDisplayInfo(
  168. /* [out][in] */ SCOPEDATAITEM *pScopeDataItem)
  169. {
  170. HRESULT hr = S_FALSE;
  171. // if they are asking for the SDI_STR we have one of those to give
  172. if (pScopeDataItem->lParam) {
  173. CDelegationBase *base = (CDelegationBase *)pScopeDataItem->lParam;
  174. if (pScopeDataItem->mask & SDI_STR) {
  175. LPCTSTR pszT = base->GetDisplayName();
  176. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  177. pScopeDataItem->displayname = pszW;
  178. }
  179. if (pScopeDataItem->mask & SDI_IMAGE) {
  180. pScopeDataItem->nImage = base->GetBitmapIndex();
  181. }
  182. }
  183. return hr;
  184. }
  185. HRESULT CComponentData::CompareObjects(
  186. /* [in] */ LPDATAOBJECT lpDataObjectA,
  187. /* [in] */ LPDATAOBJECT lpDataObjectB)
  188. {
  189. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  190. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  191. // compare the object pointers
  192. if (baseA->GetCookie() == baseB->GetCookie())
  193. return S_OK;
  194. return S_FALSE;
  195. }
  196. ///////////////////////////////
  197. // Interface ISnapinHelp
  198. ///////////////////////////////
  199. HRESULT CComponentData::GetHelpTopic(
  200. /* [out] */ LPOLESTR *lpCompiledHelpFile)
  201. {
  202. *lpCompiledHelpFile = static_cast<LPOLESTR>(CoTaskMemAlloc((wcslen(m_HelpFile) + 1) * sizeof(WCHAR)));
  203. wcscpy(*lpCompiledHelpFile, m_HelpFile);
  204. return S_OK;
  205. }
  206. ///////////////////////////////
  207. // Interface IExtendContextMenu
  208. ///////////////////////////////
  209. HRESULT CComponentData::AddMenuItems(
  210. /* [in] */ LPDATAOBJECT piDataObject,
  211. /* [in] */ LPCONTEXTMENUCALLBACK piCallback,
  212. /* [out][in] */ long __RPC_FAR *pInsertionAllowed)
  213. {
  214. CDelegationBase *base = GetOurDataObject(piDataObject)->GetBaseNodeObject();
  215. return base->OnAddMenuItems(piCallback, pInsertionAllowed);
  216. }
  217. HRESULT CComponentData::Command(
  218. /* [in] */ long lCommandID,
  219. /* [in] */ LPDATAOBJECT piDataObject)
  220. {
  221. CDelegationBase *base = GetOurDataObject(piDataObject)->GetBaseNodeObject();
  222. return base->OnMenuCommand(m_ipConsole, lCommandID);
  223. }