Source code of Windows XP (NT5)
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.

287 lines
7.6 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. #include "stdafx.h"
  3. #include "tscc.h"
  4. #include "dataobj.h"
  5. #include "resource.h"
  6. #include "rnodes.h"
  7. extern const GUID GUID_ResultNode;
  8. static UINT s_cfInternal;// = RegisterClipboardFormat( TEXT( "TSCC" ) );
  9. static UINT s_cfDisplayName;// = RegisterClipboardFormat( CCF_DISPLAY_NAME );
  10. static UINT s_cfNodeType;// = RegisterClipboardFormat( CCF_NODETYPE );
  11. static UINT s_cfSnapinClsid;// = RegisterClipboardFormat( CCF_SNAPIN_CLASSID );
  12. static UINT s_cfSZNodeType;// = RegisterClipboardFormat( CCF_SZNODETYPE );
  13. static UINT s_cfSZWinstaName;
  14. //--------------------------------------------------------------------------
  15. // ctor
  16. //--------------------------------------------------------------------------
  17. CBaseNode::CBaseNode( )
  18. {
  19. // The ndmgr gets the dataobj via IComponent and then calls release
  20. // so dataobj should have an implicit addref
  21. m_cref = 1;
  22. if( s_cfInternal == 0 )
  23. {
  24. s_cfInternal = RegisterClipboardFormat( TEXT( "TSCC" ) );
  25. }
  26. if( s_cfSZWinstaName == 0 )
  27. {
  28. s_cfSZWinstaName = RegisterClipboardFormat( TEXT( "TSCC_WINSTANAME" ) );
  29. }
  30. if( s_cfDisplayName == 0 )
  31. {
  32. s_cfDisplayName = RegisterClipboardFormat( CCF_DISPLAY_NAME );
  33. }
  34. if( s_cfNodeType == 0 )
  35. {
  36. s_cfNodeType = RegisterClipboardFormat( CCF_NODETYPE );
  37. }
  38. if( s_cfSnapinClsid == 0 )
  39. {
  40. s_cfSnapinClsid = RegisterClipboardFormat( CCF_SNAPIN_CLASSID );
  41. }
  42. if( s_cfSZNodeType == 0 )
  43. {
  44. s_cfSZNodeType = RegisterClipboardFormat( CCF_SZNODETYPE );
  45. }
  46. m_nNodeType = 0;
  47. }
  48. //--------------------------------------------------------------------------
  49. // Standard QI behavior
  50. //--------------------------------------------------------------------------
  51. STDMETHODIMP CBaseNode::QueryInterface( REFIID riid , PVOID *ppv )
  52. {
  53. if( riid == IID_IUnknown )
  54. {
  55. *ppv = ( LPUNKNOWN )this;
  56. }
  57. else if( riid == IID_IDataObject )
  58. {
  59. *ppv = ( LPDATAOBJECT )this;
  60. }
  61. else
  62. {
  63. *ppv = NULL;
  64. return E_NOINTERFACE;
  65. }
  66. AddRef( );
  67. return S_OK;
  68. }
  69. //--------------------------------------------------------------------------
  70. // Standard addref
  71. //--------------------------------------------------------------------------
  72. STDMETHODIMP_( ULONG )CBaseNode::AddRef( )
  73. {
  74. return InterlockedIncrement( ( LPLONG )&m_cref );
  75. }
  76. //--------------------------------------------------------------------------
  77. // Same as addref no need for cs
  78. //--------------------------------------------------------------------------
  79. STDMETHODIMP_( ULONG )CBaseNode::Release( )
  80. {
  81. if( InterlockedDecrement( ( LPLONG )&m_cref ) == 0 )
  82. {
  83. ODS( L"CBaseNode -- Releasing Dataobj\n" );
  84. delete this;
  85. return 0;
  86. }
  87. return m_cref;
  88. }
  89. //--------------------------------------------------------------------------
  90. // Trust me ndmgr will call this with a fury
  91. //--------------------------------------------------------------------------
  92. STDMETHODIMP CBaseNode::GetDataHere( LPFORMATETC pF , LPSTGMEDIUM pMedium)
  93. {
  94. HRESULT hr = DV_E_FORMATETC;
  95. const CLIPFORMAT cf = pF->cfFormat;
  96. IStream *pStream = NULL;
  97. pMedium->pUnkForRelease = NULL;
  98. hr = CreateStreamOnHGlobal( pMedium->hGlobal, FALSE, &pStream );
  99. if( SUCCEEDED( hr ) )
  100. {
  101. if( cf == s_cfDisplayName )
  102. {
  103. TCHAR szDispname[ 128 ]; // = TEXT("Terminal Server Connection Configuration" );
  104. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_NAMESTRING , szDispname , SIZE_OF_BUFFER( szDispname ) ) );
  105. // Include null terminator
  106. hr = pStream->Write( szDispname , SIZE_OF_BUFFER( szDispname )/* + sizeof( TCHAR )*/ , NULL );
  107. }
  108. else if( cf == s_cfInternal )
  109. {
  110. // The nodemgr will use this copy and pass it back to us in
  111. // functions such as ::Notify
  112. ODS( L"GetDataHere -- s_cfInternal used\n" );
  113. hr = pStream->Write( this , sizeof( CBaseNode ) , NULL );
  114. }
  115. else if( cf == s_cfSZWinstaName )
  116. {
  117. CResultNode *pNode = dynamic_cast< CResultNode *>( this );
  118. hr = E_FAIL; // generic failure
  119. // if we're talking about a connection base node get the winstation name
  120. ODS( L"GetDataHere -- current winstaname\n" );
  121. if( pNode != NULL )
  122. {
  123. LPTSTR szConName = pNode->GetConName( );
  124. hr = pStream->Write( szConName , lstrlen( szConName ) * sizeof( TCHAR ) + sizeof( TCHAR ) , NULL );
  125. }
  126. }
  127. else if( cf == s_cfNodeType )
  128. {
  129. const GUID *pGuid = NULL;
  130. if( GetNodeType( ) == MAIN_NODE )
  131. {
  132. ODS( L"GetDataHere -- NodeType is MAIN_NODE\n" );
  133. pGuid = &GUID_MainNode;
  134. }
  135. else if( GetNodeType( ) == SETTINGS_NODE )
  136. {
  137. ODS( L"GetDataHere -- NodeType is SETTINGS_NODE\n" );
  138. pGuid = &GUID_SettingsNode;
  139. }
  140. else if( GetNodeType( ) == RESULT_NODE )
  141. {
  142. ODS( L"GetDataHere -- NodeType is RESULT_NODE\n" );
  143. pGuid = &GUID_ResultNode;
  144. }
  145. else
  146. {
  147. ODS( L"GetDataHere -- NodeType is userdefined\n ");
  148. pGuid = &GUID_ResultNode;
  149. }
  150. hr = pStream->Write( ( PVOID )pGuid , sizeof( GUID ) , NULL );
  151. }
  152. else if( cf == s_cfSZNodeType )
  153. {
  154. TCHAR szGUID[ 40 ];
  155. if( GetNodeType( ) == MAIN_NODE )
  156. {
  157. StringFromGUID2( GUID_MainNode , szGUID , SIZE_OF_BUFFER( szGUID ) );
  158. }
  159. else if( GetNodeType( ) == SETTINGS_NODE )
  160. {
  161. StringFromGUID2( GUID_SettingsNode , szGUID , SIZE_OF_BUFFER( szGUID ) );
  162. }
  163. else if( GetNodeType( ) == RESULT_NODE )
  164. {
  165. StringFromGUID2( GUID_ResultNode , szGUID , SIZE_OF_BUFFER( szGUID ) );
  166. }
  167. else
  168. {
  169. StringFromGUID2( GUID_ResultNode , szGUID , SIZE_OF_BUFFER( szGUID ) );
  170. }
  171. // write nodetype in String format -- ok
  172. hr = pStream->Write( szGUID , sizeof( szGUID ) , NULL );
  173. }
  174. else if( cf == s_cfSnapinClsid )
  175. {
  176. // write out snapin's clsid
  177. hr = pStream->Write( &CLSID_Compdata , sizeof( CLSID ) , NULL );
  178. }
  179. pStream->Release( );
  180. } // CreateStreamOnHGlobal
  181. return hr;
  182. }
  183. //--------------------------------------------------------------------------
  184. STDMETHODIMP CBaseNode::GetData( LPFORMATETC , LPSTGMEDIUM )
  185. {
  186. return E_NOTIMPL;
  187. }
  188. //--------------------------------------------------------------------------
  189. STDMETHODIMP CBaseNode::QueryGetData( LPFORMATETC )
  190. {
  191. return E_NOTIMPL;
  192. }
  193. //--------------------------------------------------------------------------
  194. STDMETHODIMP CBaseNode::GetCanonicalFormatEtc( LPFORMATETC , LPFORMATETC )
  195. {
  196. return E_NOTIMPL;
  197. }
  198. //--------------------------------------------------------------------------
  199. STDMETHODIMP CBaseNode::SetData( LPFORMATETC , LPSTGMEDIUM , BOOL )
  200. {
  201. return E_NOTIMPL;
  202. }
  203. //--------------------------------------------------------------------------
  204. STDMETHODIMP CBaseNode::EnumFormatEtc( DWORD , LPENUMFORMATETC * )
  205. {
  206. return E_NOTIMPL;
  207. }
  208. //--------------------------------------------------------------------------
  209. STDMETHODIMP CBaseNode::DAdvise( LPFORMATETC , ULONG , LPADVISESINK , PULONG )
  210. {
  211. return E_NOTIMPL;
  212. }
  213. //--------------------------------------------------------------------------
  214. STDMETHODIMP CBaseNode::DUnadvise( DWORD )
  215. {
  216. return E_NOTIMPL;
  217. }
  218. //--------------------------------------------------------------------------
  219. STDMETHODIMP CBaseNode::EnumDAdvise( LPENUMSTATDATA * )
  220. {
  221. return E_NOTIMPL;
  222. }