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.

716 lines
24 KiB

  1. // DataObj.cpp : Implementation of data object classes
  2. #include "stdafx.h"
  3. #include "compdata.h"
  4. #include "safetemp.h"
  5. #include "macros.h"
  6. USE_HANDLE_MACROS("FILEMGMT(dataobj.cpp)")
  7. #include "FileSvc.h" // FileServiceProvider
  8. #include "dataobj.h"
  9. #include "smb.h"
  10. #include "sfm.h"
  11. #include "cmponent.h" // for COLNUM_SESSIONS_COMPUTERNAME
  12. #define DONT_WANT_SHELLDEBUG
  13. #include "shlobjp.h" // ILFree, ILGetSize, ILClone, etc.
  14. #include <comstrm.h>
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. #include "stddtobj.cpp"
  21. // IDataObject interface implementation
  22. HRESULT CFileMgmtDataObject::GetDataHere(
  23. FORMATETC __RPC_FAR *pFormatEtcIn,
  24. STGMEDIUM __RPC_FAR *pMedium)
  25. {
  26. MFC_TRY;
  27. const CLIPFORMAT cf=pFormatEtcIn->cfFormat;
  28. if (cf == m_CFInternal)
  29. {
  30. CFileMgmtDataObject *pThis = this;
  31. stream_ptr s(pMedium);
  32. return s.Write(&pThis, sizeof(CFileMgmtDataObject*));
  33. }
  34. else if (cf == m_CFSnapInCLSID)
  35. {
  36. stream_ptr s(pMedium);
  37. return s.Write(&m_SnapInCLSID, sizeof(GUID));
  38. }
  39. if (!m_MultiSelectObjList.empty())
  40. {
  41. //
  42. // this is the multiselect data object, we don't support other clipformats in GetDataHere().
  43. //
  44. return DV_E_FORMATETC;
  45. }
  46. if (cf == m_CFNodeType)
  47. {
  48. const GUID* pguid = GetObjectTypeGUID( m_objecttype );
  49. stream_ptr s(pMedium);
  50. return s.Write(pguid, sizeof(GUID));
  51. }
  52. else if (cf == m_CFNodeTypeString)
  53. {
  54. const BSTR strGUID = GetObjectTypeString( m_objecttype );
  55. stream_ptr s(pMedium);
  56. return s.Write(strGUID);
  57. }
  58. else if (cf == m_CFDisplayName)
  59. {
  60. return PutDisplayName(pMedium);
  61. }
  62. else if (cf == m_CFDataObjectType)
  63. {
  64. stream_ptr s(pMedium);
  65. return s.Write(&m_dataobjecttype, sizeof(m_dataobjecttype));
  66. }
  67. else if (cf == m_CFMachineName)
  68. {
  69. stream_ptr s(pMedium);
  70. return s.Write(m_strMachineName);
  71. }
  72. else if (cf == m_CFTransport)
  73. {
  74. FILEMGMT_TRANSPORT transport = FILEMGMT_OTHER;
  75. HRESULT hr = m_pcookie->GetTransport( &transport );
  76. if ( FAILED(hr) )
  77. return hr;
  78. stream_ptr s(pMedium);
  79. return s.Write(&transport, sizeof(DWORD));
  80. }
  81. else if (cf == m_CFShareName)
  82. {
  83. ASSERT( NULL != m_pcookie );
  84. CString strShareName;
  85. HRESULT hr = m_pcookie->GetShareName( strShareName );
  86. if ( FAILED(hr) )
  87. return hr;
  88. stream_ptr s(pMedium);
  89. return s.Write(strShareName);
  90. }
  91. else if (cf == m_CFSessionClientName)
  92. {
  93. ASSERT( NULL != m_pcookie );
  94. CString strSessionClientName;
  95. HRESULT hr = m_pcookie->GetSessionClientName( strSessionClientName );
  96. if ( FAILED(hr) )
  97. return hr;
  98. stream_ptr s(pMedium);
  99. return s.Write(strSessionClientName);
  100. }
  101. else if (cf == m_CFSessionUserName)
  102. {
  103. ASSERT( NULL != m_pcookie );
  104. CString strSessionUserName;
  105. HRESULT hr = m_pcookie->GetSessionUserName( strSessionUserName );
  106. if ( FAILED(hr) )
  107. return hr;
  108. stream_ptr s(pMedium);
  109. return s.Write(strSessionUserName);
  110. }
  111. else if (cf == m_CFSessionID)
  112. {
  113. DWORD dwSessionID = 0;
  114. HRESULT hr = m_pcookie->GetSessionID( &dwSessionID );
  115. if ( FAILED(hr) )
  116. return hr;
  117. stream_ptr s(pMedium);
  118. return s.Write(&dwSessionID, sizeof(DWORD));
  119. }
  120. else if (cf == m_CFFileID)
  121. {
  122. DWORD dwFileID = 0;
  123. HRESULT hr = m_pcookie->GetFileID( &dwFileID );
  124. if ( FAILED(hr) )
  125. return hr;
  126. stream_ptr s(pMedium);
  127. return s.Write(&dwFileID, sizeof(DWORD));
  128. }
  129. else if (cf == m_CFServiceName)
  130. {
  131. ASSERT( NULL != m_pcookie );
  132. CString strServiceName;
  133. HRESULT hr = m_pcookie->GetServiceName( strServiceName );
  134. if ( FAILED(hr) )
  135. return hr;
  136. stream_ptr s(pMedium);
  137. return s.Write(strServiceName);
  138. }
  139. else if (cf == m_CFServiceDisplayName)
  140. {
  141. ASSERT( NULL != m_pcookie );
  142. CString strServiceDisplayName;
  143. HRESULT hr = m_pcookie->GetServiceDisplayName( strServiceDisplayName );
  144. if ( FAILED(hr) )
  145. return hr;
  146. stream_ptr s(pMedium);
  147. return s.Write(strServiceDisplayName);
  148. }
  149. else if (cf == m_CFRawCookie)
  150. {
  151. stream_ptr s(pMedium);
  152. return s.Write((PBYTE)&m_pcookie, sizeof(m_pcookie));
  153. }
  154. else if (cf == m_CFSnapinPreloads) // added JonN 01/19/00
  155. {
  156. stream_ptr s(pMedium);
  157. BOOL bPreload = TRUE;
  158. return s.Write((PBYTE)&bPreload, sizeof(BOOL));
  159. }
  160. return DV_E_FORMATETC;
  161. MFC_CATCH;
  162. }
  163. HRESULT CFileMgmtDataObject::Initialize( CFileMgmtCookie* pcookie,
  164. CFileMgmtComponentData& refComponentData,
  165. DATA_OBJECT_TYPES type )
  166. {
  167. if (NULL == pcookie)
  168. {
  169. ASSERT(FALSE);
  170. return E_UNEXPECTED;
  171. }
  172. m_pComponentData = &refComponentData;
  173. ((IComponentData*) m_pComponentData)->AddRef ();
  174. m_objecttype = pcookie->QueryObjectType();
  175. m_fAllowOverrideMachineName = refComponentData.m_fAllowOverrideMachineName;
  176. #ifdef SNAPIN_PROTOTYPER
  177. if (m_objecttype != FILEMGMT_PROTOTYPER_LEAF)
  178. m_strMachineName = pcookie->QueryTargetServer();
  179. #else
  180. m_strMachineName = pcookie->QueryTargetServer();
  181. #endif
  182. m_dataobjecttype = type;
  183. m_pcookie = pcookie;
  184. m_pcookie->AddRefCookie();
  185. VERIFY( SUCCEEDED(refComponentData.GetClassID(&m_SnapInCLSID)) );
  186. return S_OK;
  187. }
  188. CFileMgmtDataObject::~CFileMgmtDataObject()
  189. {
  190. FreeMultiSelectObjList();
  191. if (NULL != m_pcookie)
  192. {
  193. m_pcookie->ReleaseCookie();
  194. }
  195. if ( m_pComponentData )
  196. ((IComponentData*) m_pComponentData)->Release ();
  197. }
  198. /////////////////////////////////////////////////////////////////////
  199. // CFileMgmtDataObject::IDataObject::GetData()
  200. //
  201. // Write data into the storage medium.
  202. // The data will be retrieved by the Send Console Message snapin.
  203. //
  204. //
  205. HRESULT CFileMgmtDataObject::GetData(
  206. FORMATETC __RPC_FAR * pFormatEtcIn,
  207. STGMEDIUM __RPC_FAR * pMedium)
  208. {
  209. ASSERT(pFormatEtcIn != NULL);
  210. ASSERT(pMedium != NULL);
  211. HRESULT hResult = S_OK;
  212. const CLIPFORMAT cf = pFormatEtcIn->cfFormat;
  213. if (!m_MultiSelectObjList.empty())
  214. {
  215. //
  216. // This is the multiselect dataobject.
  217. //
  218. if (cf == m_CFObjectTypesInMultiSelect)
  219. {
  220. //
  221. // We will provide the list of object types of all the currently selected items here.
  222. // MMC will use this format to determine extensions snapins
  223. //
  224. UINT nMultiSelectedObjects = m_MultiSelectObjList.size();
  225. // Calculate the size of SMMCObjectTypes.
  226. int cb = sizeof(DWORD) + sizeof(SMMCObjectTypes) * nMultiSelectedObjects;
  227. //Fill out parameters
  228. pMedium->tymed = TYMED_HGLOBAL;
  229. pMedium->hGlobal = ::GlobalAlloc(GMEM_SHARE|GMEM_MOVEABLE, cb);
  230. if (pMedium->hGlobal == NULL)
  231. return STG_E_MEDIUMFULL;
  232. SMMCObjectTypes* pMMCDO = reinterpret_cast<SMMCObjectTypes*>(::GlobalLock(pMedium->hGlobal));
  233. pMMCDO->count = 0;
  234. GUID *pMMCDOGuid = pMMCDO->guid;
  235. for (CDataObjectList::iterator i = m_MultiSelectObjList.begin(); i != m_MultiSelectObjList.end(); i++)
  236. {
  237. CCookie* pbasecookie = NULL;
  238. hResult = ExtractData(*i, CFileMgmtDataObject::m_CFRawCookie, &pbasecookie, sizeof(pbasecookie));
  239. if (FAILED(hResult))
  240. break;
  241. pbasecookie = m_pComponentData->ActiveBaseCookie( pbasecookie );
  242. CFileMgmtCookie* pUseThisCookie = dynamic_cast<CFileMgmtCookie*>(pbasecookie);
  243. FileMgmtObjectType objecttype = pUseThisCookie->QueryObjectType();
  244. const GUID* pguid = GetObjectTypeGUID(objecttype);
  245. memcpy(pMMCDOGuid++, pguid, sizeof(GUID));
  246. pMMCDO->count++;
  247. }
  248. ::GlobalUnlock(pMedium->hGlobal);
  249. if (FAILED(hResult))
  250. {
  251. ::GlobalFree(pMedium->hGlobal);
  252. pMedium->hGlobal = NULL;
  253. }
  254. } else
  255. hResult = DV_E_FORMATETC;
  256. return hResult;
  257. }
  258. if (cf == m_cfSendConsoleMessageRecipients)
  259. {
  260. ASSERT (m_pComponentData);
  261. if ( m_pComponentData )
  262. {
  263. // I suppose it doesn't matter what type this cookie is because we
  264. // are just using to hang enumerated session cookies off of, as long
  265. // as it's not an abstract class.
  266. BOOL fContinue = TRUE;
  267. HRESULT hr = S_OK;
  268. CSmbSessionCookie* pCookie = new CSmbSessionCookie[1];
  269. if ( pCookie )
  270. {
  271. CSmbCookieBlock cookieBlock (pCookie, 1, (LPCTSTR) m_strMachineName, 0);
  272. CBaseCookieBlock* pCookieBlock = 0;
  273. //
  274. // JonN 6/28/01 426224
  275. // Shared Folder: Send Message access denied error title needs to be changed for localization
  276. //
  277. AFX_MANAGE_STATE(AfxGetStaticModuleState()); // required for CWaitCursor
  278. // Enumerate all the session cookies
  279. for (INT iTransport = FILEMGMT_FIRST_TRANSPORT;
  280. fContinue && iTransport < FILEMGMT_NUM_TRANSPORTS;
  281. iTransport++ )
  282. {
  283. hr = m_pComponentData->GetFileServiceProvider(iTransport)->EnumerateSessions(
  284. NULL, &pCookie[0], false);
  285. fContinue = SUCCEEDED(hr);
  286. }
  287. // Enumerate all the computer names from the session cookies and store them in
  288. // the computerList
  289. CStringList computerList;
  290. size_t len = 0; // number of WCHARS
  291. while ( !pCookie[0].m_listResultCookieBlocks.IsEmpty () )
  292. {
  293. pCookieBlock = pCookie[0].m_listResultCookieBlocks.RemoveHead ();
  294. ASSERT (pCookieBlock);
  295. if ( !pCookieBlock )
  296. break;
  297. int nCookies = pCookieBlock->QueryNumCookies ();
  298. while (nCookies--)
  299. {
  300. CCookie* pBaseCookie = pCookieBlock->QueryBaseCookie (nCookies);
  301. ASSERT (pBaseCookie);
  302. if ( pBaseCookie )
  303. {
  304. CFileMgmtCookie* pFMCookie = dynamic_cast <CFileMgmtCookie*> (pBaseCookie);
  305. ASSERT (pFMCookie);
  306. if ( pFMCookie )
  307. {
  308. computerList.AddHead (pFMCookie->QueryResultColumnText (
  309. COLNUM_SESSIONS_COMPUTERNAME, *m_pComponentData));
  310. len += computerList.GetHead ().GetLength () + 1; // to account for NULL
  311. }
  312. }
  313. }
  314. pCookieBlock->Release ();
  315. }
  316. if ( !m_strMachineName.IsEmpty () )
  317. {
  318. computerList.AddHead (m_strMachineName);
  319. len += computerList.GetHead ().GetLength () + 1; // to account for NULL
  320. }
  321. // Run through all the computer names in computerList and add them to the output buffer
  322. //
  323. // Write the list of recipients to the storage medium.
  324. // - The list of recipients is a group of UNICODE strings
  325. // terminated by TWO null characters.c
  326. // - Allocated memory must include BOTH null characters.
  327. //
  328. len += 1; // to account for extra NULL at end.
  329. WCHAR* pgrszRecipients = new WCHAR[len];
  330. WCHAR* ptr = pgrszRecipients;
  331. CString computerName;
  332. if ( pgrszRecipients )
  333. {
  334. ::ZeroMemory (pgrszRecipients, len * sizeof (WCHAR));
  335. while ( !computerList.IsEmpty () )
  336. {
  337. computerName = computerList.RemoveHead ();
  338. // append computer name
  339. wcscpy (ptr, (LPCTSTR) computerName);
  340. // skip past computer name and terminating NULL
  341. ptr += computerName.GetLength () + 1;
  342. }
  343. // Add the name of this computer
  344. HGLOBAL hGlobal = ::GlobalAlloc (GMEM_FIXED, len * sizeof (WCHAR));
  345. if ( hGlobal )
  346. {
  347. memcpy (OUT hGlobal, pgrszRecipients, len * sizeof (WCHAR));
  348. pMedium->hGlobal = hGlobal;
  349. }
  350. else
  351. hResult = E_OUTOFMEMORY;
  352. delete [] pgrszRecipients;
  353. }
  354. else
  355. hResult = E_OUTOFMEMORY;
  356. // pCookie deleted in destructor of cookieBlock
  357. }
  358. else
  359. hResult = E_OUTOFMEMORY;
  360. }
  361. else
  362. hResult = E_UNEXPECTED;
  363. }
  364. else if (cf == m_CFIDList)
  365. {
  366. LPITEMIDLIST pidl = NULL, pidlR = NULL;
  367. hResult = m_pcookie->GetSharePIDList( &pidl );
  368. if (SUCCEEDED(hResult))
  369. {
  370. pidlR = ILClone(ILFindLastID(pidl)); // relative IDList
  371. ILRemoveLastID(pidl); // folder IDList
  372. int cidl = 1;
  373. UINT offset = sizeof(CIDA) + sizeof(UINT)*cidl;
  374. UINT cbFolder = ILGetSize(pidl);
  375. UINT cbRelative = ILGetSize(pidlR);
  376. UINT cbTotal = offset + cbFolder + cbRelative;
  377. HGLOBAL hGlobal = ::GlobalAlloc (GPTR, cbTotal);
  378. if ( hGlobal )
  379. {
  380. LPIDA pida = (LPIDA)hGlobal;
  381. pida->cidl = cidl;
  382. pida->aoffset[0] = offset;
  383. MoveMemory(((LPBYTE)hGlobal+offset), pidl, cbFolder);
  384. offset += cbFolder;
  385. pida->aoffset[1] = offset;
  386. MoveMemory(((LPBYTE)hGlobal+offset), pidlR, cbRelative);
  387. pMedium->hGlobal = hGlobal;
  388. }
  389. else
  390. hResult = E_OUTOFMEMORY;
  391. // free pidl & pidlR
  392. if (pidl)
  393. ILFree(pidl);
  394. if (pidlR)
  395. ILFree(pidlR);
  396. } else
  397. hResult = DV_E_FORMATETC;
  398. } else if (cf == m_CFNodeID2)
  399. {
  400. if (m_objecttype != FILEMGMT_ROOT &&
  401. m_objecttype != FILEMGMT_SHARES &&
  402. m_objecttype != FILEMGMT_SESSIONS &&
  403. m_objecttype != FILEMGMT_RESOURCES &&
  404. m_objecttype != FILEMGMT_SERVICES)
  405. {
  406. hResult = DV_E_FORMATETC;
  407. } else
  408. {
  409. const BSTR strGUID = GetObjectTypeString( m_objecttype );
  410. // JonN 12/11/01 502856
  411. int cbString = (lstrlen(strGUID) + 1) * sizeof(TCHAR);
  412. pMedium->tymed = TYMED_HGLOBAL;
  413. pMedium->hGlobal = ::GlobalAlloc(GMEM_SHARE|GMEM_MOVEABLE,
  414. sizeof(SNodeID2) + cbString);
  415. if (!(pMedium->hGlobal))
  416. {
  417. hResult = E_OUTOFMEMORY;
  418. } else
  419. {
  420. SNodeID2 *pNodeID = (SNodeID2 *)GlobalLock(pMedium->hGlobal);
  421. if (!pNodeID)
  422. {
  423. hResult = HRESULT_FROM_WIN32(GetLastError());
  424. GlobalFree(pMedium->hGlobal);
  425. pMedium->hGlobal = NULL;
  426. } else
  427. {
  428. pNodeID->dwFlags = 0;
  429. pNodeID->cBytes = cbString;
  430. CopyMemory(pNodeID->id, strGUID, cbString);
  431. GlobalUnlock(pMedium->hGlobal);
  432. }
  433. }
  434. }
  435. } else
  436. hResult = DV_E_FORMATETC; // Invalid/unknown clipboard format
  437. return hResult;
  438. } // CMyComputerDataObject::GetData()
  439. HRESULT CFileMgmtDataObject::PutDisplayName(STGMEDIUM* pMedium)
  440. // Writes the "friendly name" to the provided storage medium
  441. // Returns the result of the write operation
  442. {
  443. if ( !IsAutonomousObjectType(m_objecttype) )
  444. {
  445. ASSERT(FALSE);
  446. return DV_E_FORMATETC;
  447. }
  448. CString strDisplayName;
  449. BOOL fStaticNode = ( NULL != m_pComponentData
  450. && !m_pComponentData->IsExtensionSnapin()
  451. && m_pComponentData->QueryRootCookie().QueryObjectType()
  452. == m_objecttype);
  453. // will only succeed for scope cookies
  454. m_pcookie->GetDisplayName( strDisplayName, fStaticNode );
  455. // LoadStringPrintf(nStringId, OUT &strDisplayName, (LPCTSTR)m_strMachineName);
  456. stream_ptr s(pMedium);
  457. return s.Write(strDisplayName);
  458. }
  459. void CFileMgmtDataObject::FreeMultiSelectObjList()
  460. {
  461. if (!m_MultiSelectObjList.empty())
  462. {
  463. for (CDataObjectList::iterator i = m_MultiSelectObjList.begin(); i != m_MultiSelectObjList.end(); i++)
  464. {
  465. CComObject<CFileMgmtDataObject>* pDataObject = reinterpret_cast<CComObject<CFileMgmtDataObject>*>(*i);
  466. delete pDataObject;
  467. }
  468. m_MultiSelectObjList.clear();
  469. }
  470. }
  471. HRESULT CFileMgmtDataObject::InitMultiSelectDataObjects(CFileMgmtComponentData& refComponentData)
  472. {
  473. FreeMultiSelectObjList();
  474. ASSERT(!m_pComponentData);
  475. m_pComponentData = &refComponentData;
  476. ((IComponentData*) m_pComponentData)->AddRef ();
  477. VERIFY( SUCCEEDED(refComponentData.GetClassID(&m_SnapInCLSID)) );
  478. return S_OK;
  479. }
  480. HRESULT CFileMgmtDataObject::AddMultiSelectDataObjects(CFileMgmtCookie* pCookie, DATA_OBJECT_TYPES type)
  481. {
  482. HRESULT hr = S_OK;
  483. CComObject<CFileMgmtDataObject>* pDataObject = NULL;
  484. hr = CComObject<CFileMgmtDataObject>::CreateInstance(&pDataObject);
  485. if (SUCCEEDED(hr))
  486. hr = pDataObject->Initialize(pCookie, *m_pComponentData, type );
  487. IDataObject *piDataObject = NULL;
  488. if (SUCCEEDED(hr))
  489. hr = pDataObject->QueryInterface(IID_IDataObject, reinterpret_cast<void**>(&piDataObject));
  490. if (SUCCEEDED(hr))
  491. {
  492. m_MultiSelectObjList.push_back(piDataObject);
  493. } else
  494. {
  495. delete pDataObject;
  496. }
  497. return hr;
  498. }
  499. // Register the clipboard formats
  500. CLIPFORMAT CFileMgmtDataObject::m_CFSnapinPreloads =
  501. (CLIPFORMAT)RegisterClipboardFormat(CCF_SNAPIN_PRELOADS);
  502. CLIPFORMAT CFileMgmtDataObject::m_CFDisplayName =
  503. (CLIPFORMAT)RegisterClipboardFormat(CCF_DISPLAY_NAME);
  504. CLIPFORMAT CFileMgmtDataObject::m_CFNodeID2 =
  505. (CLIPFORMAT)RegisterClipboardFormat(CCF_NODEID2);
  506. CLIPFORMAT CFileMgmtDataObject::m_CFTransport =
  507. (CLIPFORMAT)RegisterClipboardFormat(L"FILEMGMT_TRANSPORT");
  508. CLIPFORMAT CFileMgmtDataObject::m_CFMachineName =
  509. (CLIPFORMAT)RegisterClipboardFormat(L"MMC_SNAPIN_MACHINE_NAME");
  510. CLIPFORMAT CFileMgmtDataObject::m_CFShareName =
  511. (CLIPFORMAT)RegisterClipboardFormat(L"FILEMGMT_SNAPIN_SHARE_NAME");
  512. CLIPFORMAT CFileMgmtDataObject::m_CFSessionClientName =
  513. (CLIPFORMAT)RegisterClipboardFormat(L"FILEMGMT_SNAPIN_SESSION_CLIENT_NAME");
  514. CLIPFORMAT CFileMgmtDataObject::m_CFSessionUserName =
  515. (CLIPFORMAT)RegisterClipboardFormat(L"FILEMGMT_SNAPIN_SESSION_USER_NAME");
  516. CLIPFORMAT CFileMgmtDataObject::m_CFSessionID =
  517. (CLIPFORMAT)RegisterClipboardFormat(L"FILEMGMT_SNAPIN_SESSION_ID");
  518. CLIPFORMAT CFileMgmtDataObject::m_CFFileID =
  519. (CLIPFORMAT)RegisterClipboardFormat(L"FILEMGMT_SNAPIN_FILE_ID");
  520. CLIPFORMAT CFileMgmtDataObject::m_CFServiceName =
  521. (CLIPFORMAT)RegisterClipboardFormat(L"FILEMGMT_SNAPIN_SERVICE_NAME");
  522. CLIPFORMAT CFileMgmtDataObject::m_CFServiceDisplayName =
  523. (CLIPFORMAT)RegisterClipboardFormat(L"FILEMGMT_SNAPIN_SERVICE_DISPLAYNAME");
  524. CLIPFORMAT CDataObject::m_CFRawCookie =
  525. (CLIPFORMAT)RegisterClipboardFormat(L"FILEMGMT_SNAPIN_RAW_COOKIE");
  526. // Additional clipboard formats for the Send Console Message snapin
  527. CLIPFORMAT CFileMgmtDataObject::m_cfSendConsoleMessageRecipients =
  528. (CLIPFORMAT)RegisterClipboardFormat(_T("mmc.sendcmsg.MessageRecipients"));
  529. // Additional clipboard formats for the Security Page
  530. CLIPFORMAT CFileMgmtDataObject::m_CFIDList =
  531. (CLIPFORMAT)RegisterClipboardFormat(CFSTR_SHELLIDLIST);
  532. CLIPFORMAT CFileMgmtDataObject::m_CFObjectTypesInMultiSelect =
  533. (CLIPFORMAT)RegisterClipboardFormat(CCF_OBJECT_TYPES_IN_MULTI_SELECT);
  534. CLIPFORMAT CFileMgmtDataObject::m_CFMultiSelectDataObject =
  535. (CLIPFORMAT)RegisterClipboardFormat(CCF_MMC_MULTISELECT_DATAOBJECT);
  536. CLIPFORMAT CFileMgmtDataObject::m_CFMultiSelectSnapins =
  537. (CLIPFORMAT)RegisterClipboardFormat(CCF_MULTI_SELECT_SNAPINS);
  538. CLIPFORMAT CFileMgmtDataObject::m_CFInternal =
  539. (CLIPFORMAT)RegisterClipboardFormat(L"FILEMGMT_SNAPIN_INTERNAL");
  540. STDMETHODIMP CFileMgmtComponentData::QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT* ppDataObject)
  541. {
  542. MFC_TRY;
  543. // WARNING cookie cast
  544. CCookie* pbasecookie = reinterpret_cast<CCookie*>(cookie);
  545. CFileMgmtCookie* pUseThisCookie = ActiveCookie((CFileMgmtCookie*)pbasecookie);
  546. ASSERT( IsValidObjectType(pUseThisCookie->QueryObjectType()) );
  547. CComObject<CFileMgmtDataObject>* pDataObject = NULL;
  548. HRESULT hRes = CComObject<CFileMgmtDataObject>::CreateInstance(&pDataObject);
  549. if ( FAILED(hRes) )
  550. return hRes;
  551. HRESULT hr = pDataObject->Initialize( pUseThisCookie, *this, type );
  552. if ( SUCCEEDED(hr) )
  553. {
  554. hr = pDataObject->QueryInterface(IID_IDataObject,
  555. reinterpret_cast<void**>(ppDataObject));
  556. }
  557. if ( FAILED(hr) )
  558. {
  559. delete pDataObject;
  560. return hr;
  561. }
  562. return hr;
  563. MFC_CATCH;
  564. }
  565. /////////////////////////////////////////////////////////////////////
  566. // FileMgmtObjectTypeFromIDataObject()
  567. //
  568. // Find the objecttype of a IDataObject pointer. The purpose
  569. // of this routine is to combine ExtractObjectTypeGUID() and
  570. // CheckObjectTypeGUID() into a single function.
  571. //
  572. // Return the FILEMGMT_* node type (enum FileMgmtObjectType).
  573. //
  574. // HISTORY
  575. // 30-Jul-97 t-danm Creation.
  576. //
  577. FileMgmtObjectType
  578. FileMgmtObjectTypeFromIDataObject(IN LPDATAOBJECT lpDataObject)
  579. {
  580. ASSERT(lpDataObject != NULL);
  581. GUID guidObjectType = GUID_NULL; // JonN 11/21/00 PREFIX 226042
  582. HRESULT hr = ExtractObjectTypeGUID( IN lpDataObject, OUT &guidObjectType );
  583. ASSERT( SUCCEEDED(hr) );
  584. return (FileMgmtObjectType)CheckObjectTypeGUID(IN &guidObjectType );
  585. } // FileMgmtObjectTypeFromIDataObject()
  586. HRESULT ExtractBaseCookie(
  587. IN LPDATAOBJECT piDataObject,
  588. OUT CCookie** ppcookie,
  589. OUT FileMgmtObjectType* pobjecttype )
  590. {
  591. HRESULT hr = ExtractData( piDataObject,
  592. CFileMgmtDataObject::m_CFRawCookie,
  593. (PBYTE)ppcookie,
  594. sizeof(CCookie*) );
  595. if ( SUCCEEDED(hr) && NULL != pobjecttype )
  596. {
  597. *pobjecttype = FileMgmtObjectTypeFromIDataObject(piDataObject);
  598. }
  599. return hr;
  600. }
  601. BOOL IsMultiSelectObject(LPDATAOBJECT piDataObject)
  602. {
  603. BOOL bMultiSelectObject = FALSE;
  604. if (piDataObject)
  605. {
  606. //
  607. // return TRUE if piDataObject is the composite data object (MMC_MS_DO) created by MMC.
  608. //
  609. STGMEDIUM stgmedium = {TYMED_HGLOBAL, NULL, NULL};
  610. FORMATETC formatetc = {CFileMgmtDataObject::m_CFMultiSelectDataObject,
  611. NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  612. HRESULT hr = piDataObject->GetData(&formatetc, &stgmedium);
  613. if (S_OK == hr && stgmedium.hGlobal)
  614. {
  615. DWORD* pdwData = reinterpret_cast<DWORD*>(::GlobalLock(stgmedium.hGlobal));
  616. bMultiSelectObject = (1 == *pdwData);
  617. ::GlobalUnlock(stgmedium.hGlobal);
  618. ::GlobalFree(stgmedium.hGlobal);
  619. }
  620. }
  621. return bMultiSelectObject;
  622. }