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.

232 lines
6.9 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : Snapin.cpp //
  3. // //
  4. // DESCRIPTION : Implementation file for //
  5. // CSnapin class //
  6. // CSnapinComponent class //
  7. // //
  8. // AUTHOR : ATL Snapin wizard //
  9. // //
  10. // HISTORY : //
  11. // May 25 1998 adik Init. //
  12. // Sep 14 1998 yossg seperate common source to an included file //
  13. // Mar 28 1999 adik Remove persistence support (done by mmc 1.2). //
  14. // //
  15. // Sep 27 1999 yossg Welcome to Fax Server //
  16. // Dec 12 1999 yossg add CSnapin::Notify //
  17. // Apr 14 2000 yossg add support for primary snapin mode //
  18. // Jun 25 2000 yossg add stream and command line primary snapin //
  19. // machine targeting. //
  20. // Windows XP //
  21. // Feb 14 2001 yossg Add Manual Receive support //
  22. // //
  23. // Copyright (C) 1999 - 2000 Microsoft Corporation All Rights Reserved //
  24. /////////////////////////////////////////////////////////////////////////////
  25. #include "stdafx.h"
  26. #include "resource.h"
  27. #include "MsFxsSnp.h"
  28. #include "Snapin.h"
  29. #include "root.h"
  30. #include "FaxServerNode.h"
  31. #include "FaxMMCPropertyChange.h"
  32. static const GUID CSnapinExtGUID_NODETYPE =
  33. { 0x476e6449, 0xaaff, 0x11d0, { 0xb9, 0x44, 0x0, 0xc0, 0x4f, 0xd8, 0xd5, 0xb0 } };
  34. const GUID* CSnapinExtData::m_NODETYPE = &CSnapinExtGUID_NODETYPE;
  35. const OLECHAR* CSnapinExtData::m_SZNODETYPE = OLESTR("476e6449-aaff-11d0-b944-00c04fd8d5b0");
  36. const OLECHAR* CSnapinExtData::m_SZDISPLAY_NAME = OLESTR("Fax");
  37. const CLSID* CSnapinExtData::m_SNAPIN_CLASSID = &CLSID_Snapin;
  38. /////////////////////////////////////////////////////////////////////////////
  39. #include "resutil.h"
  40. #include "c_snapin.cpp"
  41. /////////////////////////////////////////////////////////////////////////////
  42. //
  43. // Clipboard Formats
  44. //
  45. const CLIPFORMAT gx_CCF_COMPUTERNAME = (CLIPFORMAT) RegisterClipboardFormat(_T("MMC_SNAPIN_MACHINE_NAME"));
  46. BOOL ExtractComputerName(IDataObject* pDataObject, BSTR * pVal)
  47. {
  48. DEBUG_FUNCTION_NAME( _T("ExtractComputerName"));
  49. //
  50. // Find the computer name from the ComputerManagement snapin
  51. //
  52. STGMEDIUM stgmedium = { TYMED_HGLOBAL, NULL };
  53. FORMATETC formatetc = { gx_CCF_COMPUTERNAME, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  54. //
  55. // Allocate memory for the stream
  56. //
  57. int len = 500;
  58. stgmedium.hGlobal = GlobalAlloc(GMEM_SHARE, len);
  59. if(stgmedium.hGlobal == NULL)
  60. {
  61. DebugPrintEx( DEBUG_ERR,
  62. _T("GlobalAlloc Fail. stgmedium.hGlobal == NULL, can not extract computerName"));
  63. return FALSE;
  64. }
  65. HRESULT hr = pDataObject->GetDataHere(&formatetc, &stgmedium);
  66. if (!SUCCEEDED(hr))
  67. {
  68. ATLASSERT(FALSE);
  69. DebugPrintEx( DEBUG_ERR,
  70. _T("Fail to GetDataHere"));
  71. return FALSE;
  72. }
  73. //
  74. // Get the computer name
  75. //
  76. *pVal = SysAllocString((WCHAR *)stgmedium.hGlobal);
  77. if (NULL == *pVal)
  78. {
  79. DebugPrintEx( DEBUG_ERR,
  80. _T("Out of memory - fail to allocate server name !!!"));
  81. return FALSE;
  82. }
  83. GlobalFree(stgmedium.hGlobal);
  84. return TRUE;
  85. }
  86. /*
  87. - CSnapinExtData::GetExtNodeObject
  88. -
  89. * Purpose:
  90. * Connect as an extension to root node.
  91. *
  92. * Arguments
  93. *
  94. * Return:
  95. * The HTM path name
  96. */
  97. CSnapInItem*
  98. CSnapinExtData::GetExtNodeObject(IDataObject* pDataObject, CSnapInItem* pDefault)
  99. {
  100. DEBUG_FUNCTION_NAME( _T("MsFxsSnp.dll - CSnapinExtData::GetExtNodeObject"));
  101. CComBSTR bstrComputer;
  102. m_pDataObject = pDataObject;
  103. CSnapinRoot *pRoot = new CSnapinRoot(this, m_pComponentData);
  104. if (pRoot == NULL)
  105. {
  106. DebugPrintEx(DEBUG_ERR,_T("new CSnapinRoot"), E_OUTOFMEMORY);
  107. return pDefault;
  108. }
  109. if (!ExtractComputerName(pDataObject, &bstrComputer))
  110. {
  111. DebugPrintEx( DEBUG_MSG,
  112. _T("Fail to extract computer name"));
  113. delete pRoot;
  114. pRoot = NULL;
  115. return pDefault;
  116. }
  117. ATLASSERT(bstrComputer);
  118. if (S_OK != pRoot->SetServerName(bstrComputer))
  119. {
  120. DebugPrintEx(DEBUG_ERR,_T("pRoot->SetServerName"), E_OUTOFMEMORY);
  121. delete pRoot;
  122. pRoot = NULL;
  123. return pDefault;
  124. }
  125. return pRoot;
  126. }
  127. /*
  128. - CSnapin::GetHelpTopic
  129. -
  130. * Purpose:
  131. * Get the HTM file name within comet.chm that contains the info about this node.
  132. *
  133. * Arguments
  134. *
  135. * Return:
  136. * The HTM path name
  137. */
  138. WCHAR*
  139. CSnapin::GetHelpTopic()
  140. {
  141. return NULL;
  142. }
  143. /*
  144. - CSnapin::Notify
  145. -
  146. * Purpose:
  147. * Override IComponentDataImpl::Notify for the special case with
  148. * (lpDataObject == NULL) && (event == MMCN_PROPERTY_CHANGE)
  149. * were the assumption is that notification got from scope node TYPE == CCT_SCOPE
  150. * this was done for the Device scope pane node refreshment of
  151. * result pane colmons data !
  152. *
  153. * Arguments:
  154. * [in] lpDataObject
  155. *
  156. * [in] event
  157. *
  158. * [in] arg
  159. *
  160. * [in] param
  161. *
  162. * Return:
  163. * OLE error code.
  164. *
  165. */
  166. HRESULT CSnapin::Notify(
  167. LPDATAOBJECT lpDataObject,
  168. MMC_NOTIFY_TYPE event,
  169. LPARAM arg,
  170. LPARAM param)
  171. {
  172. DEBUG_FUNCTION_NAME( _T("++<<<<< CSnapin::Notify >>>>>++"));
  173. HRESULT hr = E_POINTER;
  174. CSnapInItem* pItem;
  175. //T* pT = static_cast<T*>(this);
  176. CSnapin * pT = this;
  177. if ( (NULL == lpDataObject) && (MMCN_PROPERTY_CHANGE == event) )
  178. {
  179. DebugPrintEx( DEBUG_MSG,
  180. _T("Special case: (NULL == lpDataObject) && (MMCN_PROPERTY_CHANGE == event)"));
  181. CFaxPropertyChangeNotification * pNotification;
  182. pNotification = ( CFaxPropertyChangeNotification * ) param;
  183. ATLASSERT(pNotification);
  184. pItem = pNotification->pItem;
  185. ATLASSERT(pItem);
  186. hr = pItem->Notify(event, arg, param, pT, NULL, CCT_SCOPE);
  187. return hr;
  188. }
  189. else
  190. {
  191. return IComponentDataImpl<CSnapin, CSnapinComponent>::Notify(
  192. lpDataObject, event, arg, param);
  193. }
  194. return hr;
  195. }