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.

224 lines
7.1 KiB

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