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.

259 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. 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->Expand(m_ipConsoleNameSpace, m_ipConsole, (HSCOPEITEM)param);
  133. break;
  134. case MMCN_INITOCX:
  135. hr = base->InitOCX(reinterpret_cast<IUnknown *>(param));
  136. break;
  137. }
  138. return hr;
  139. }
  140. HRESULT CComponentData::Destroy( void)
  141. {
  142. // Free interfaces
  143. if (m_ipConsoleNameSpace) {
  144. m_ipConsoleNameSpace->Release();
  145. m_ipConsoleNameSpace = NULL;
  146. }
  147. if (m_ipConsole) {
  148. m_ipConsole->Release();
  149. m_ipConsole = NULL;
  150. }
  151. return S_OK;
  152. }
  153. HRESULT CComponentData::QueryDataObject(
  154. /* [in] */ MMC_COOKIE cookie,
  155. /* [in] */ DATA_OBJECT_TYPES type,
  156. /* [out] */ LPDATAOBJECT *ppDataObject)
  157. {
  158. CDataObject *pObj = NULL;
  159. if (cookie == 0)
  160. pObj = new CDataObject((MMC_COOKIE)m_pStaticNode, type);
  161. else
  162. pObj = new CDataObject(cookie, type);
  163. if (!pObj)
  164. return E_OUTOFMEMORY;
  165. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  166. return S_OK;
  167. }
  168. HRESULT CComponentData::GetDisplayInfo(
  169. /* [out][in] */ SCOPEDATAITEM *pScopeDataItem)
  170. {
  171. HRESULT hr = S_FALSE;
  172. // if they are asking for the SDI_STR we have one of those to give
  173. if (pScopeDataItem->lParam) {
  174. CDelegationBase *base = (CDelegationBase *)pScopeDataItem->lParam;
  175. if (pScopeDataItem->mask & SDI_STR) {
  176. LPCTSTR pszT = base->GetDisplayName();
  177. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  178. pScopeDataItem->displayname = pszW;
  179. }
  180. if (pScopeDataItem->mask & SDI_IMAGE) {
  181. pScopeDataItem->nImage = base->GetBitmapIndex();
  182. }
  183. }
  184. return hr;
  185. }
  186. HRESULT CComponentData::CompareObjects(
  187. /* [in] */ LPDATAOBJECT lpDataObjectA,
  188. /* [in] */ LPDATAOBJECT lpDataObjectB)
  189. {
  190. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  191. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  192. // compare the object pointers
  193. if (baseA->GetCookie() == baseB->GetCookie())
  194. return S_OK;
  195. return S_FALSE;
  196. }
  197. ///////////////////////////////
  198. // Interface ISnapinHelp
  199. ///////////////////////////////
  200. HRESULT CComponentData::GetHelpTopic(
  201. /* [out] */ LPOLESTR *lpCompiledHelpFile)
  202. {
  203. *lpCompiledHelpFile = static_cast<LPOLESTR>(CoTaskMemAlloc((wcslen(m_HelpFile) + 1) * sizeof(WCHAR)));
  204. wcscpy(*lpCompiledHelpFile, m_HelpFile);
  205. return S_OK;
  206. }