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.

158 lines
4.3 KiB

  1. // DataObj.cpp : Implementation of data object classes
  2. #include "stdafx.h"
  3. #include "stdutils.h"
  4. #include "macros.h"
  5. USE_HANDLE_MACROS("SCHMMGMT(dataobj.cpp)")
  6. #include "dataobj.h"
  7. #include "compdata.h"
  8. #include "resource.h"
  9. #include "stddtobj.cpp"
  10. //
  11. // IDataObject interface implementation.
  12. //
  13. HRESULT
  14. CSchmMgmtDataObject::GetDataHere(
  15. FORMATETC __RPC_FAR *pFormatEtcIn,
  16. STGMEDIUM __RPC_FAR *pMedium
  17. )
  18. {
  19. MFC_TRY;
  20. const CLIPFORMAT cf=pFormatEtcIn->cfFormat;
  21. if (cf == m_CFNodeType)
  22. {
  23. const GUID* pguid = GetObjectTypeGUID( m_pcookie->m_objecttype );
  24. stream_ptr s(pMedium);
  25. return s.Write(pguid, sizeof(GUID));
  26. }
  27. else if (cf == m_CFSnapInCLSID)
  28. {
  29. const GUID* pguid = &CLSID_SchmMgmt;
  30. stream_ptr s(pMedium);
  31. return s.Write(pguid, sizeof(GUID));
  32. }
  33. else if (cf == m_CFNodeTypeString)
  34. {
  35. const BSTR strGUID = GetObjectTypeString( m_pcookie->m_objecttype );
  36. stream_ptr s(pMedium);
  37. return s.Write(strGUID);
  38. }
  39. else if (cf == m_CFDisplayName)
  40. {
  41. return PutDisplayName(pMedium);
  42. }
  43. else if (cf == m_CFDataObjectType)
  44. {
  45. stream_ptr s(pMedium);
  46. return s.Write(&m_dataobjecttype, sizeof(m_dataobjecttype));
  47. }
  48. else if (cf == m_CFMachineName)
  49. {
  50. stream_ptr s(pMedium);
  51. return s.Write(m_pcookie->QueryNonNULLMachineName());
  52. }
  53. else if (cf == m_CFRawCookie)
  54. {
  55. stream_ptr s(pMedium);
  56. // CODEWORK This cast ensures that the data format is
  57. // always a CCookie*, even for derived subclasses
  58. CCookie* pcookie = (CCookie*)m_pcookie;
  59. return s.Write(reinterpret_cast<PBYTE>(&pcookie), sizeof(m_pcookie));
  60. }
  61. return DV_E_FORMATETC;
  62. MFC_CATCH;
  63. }
  64. HRESULT CSchmMgmtDataObject::Initialize( Cookie* pcookie, DATA_OBJECT_TYPES type )
  65. {
  66. if (NULL == pcookie || NULL != m_pcookie)
  67. {
  68. ASSERT(FALSE);
  69. return E_UNEXPECTED;
  70. }
  71. m_dataobjecttype = type;
  72. m_pcookie = pcookie;
  73. ((CRefcountedObject*)m_pcookie)->AddRef();
  74. return S_OK;
  75. }
  76. CSchmMgmtDataObject::~CSchmMgmtDataObject()
  77. {
  78. if (NULL != m_pcookie)
  79. {
  80. ((CRefcountedObject*)m_pcookie)->Release();
  81. }
  82. else
  83. {
  84. ASSERT(FALSE);
  85. }
  86. }
  87. HRESULT CSchmMgmtDataObject::PutDisplayName(STGMEDIUM* pMedium)
  88. // Writes the "friendly name" to the provided storage medium
  89. // Returns the result of the write operation
  90. {
  91. CString strDisplayName;
  92. LPCTSTR pszTarget = m_pcookie->QueryTargetServer();
  93. if ( NULL != pszTarget )
  94. {
  95. if ( pszTarget[0] == _T('\\') && pszTarget[1] == _T('\\') )
  96. pszTarget += 2;
  97. strDisplayName = pszTarget;
  98. }
  99. else
  100. {
  101. VERIFY( strDisplayName.LoadString(IDS_SCOPE_SCHMMGMT) );
  102. }
  103. stream_ptr s(pMedium);
  104. return s.Write(strDisplayName);
  105. }
  106. // Register the clipboard formats
  107. CLIPFORMAT CSchmMgmtDataObject::m_CFDisplayName =
  108. (CLIPFORMAT)RegisterClipboardFormat(CCF_DISPLAY_NAME);
  109. CLIPFORMAT CSchmMgmtDataObject::m_CFMachineName =
  110. (CLIPFORMAT)RegisterClipboardFormat(L"MMC_SNAPIN_MACHINE_NAME");
  111. CLIPFORMAT CDataObject::m_CFRawCookie =
  112. (CLIPFORMAT)RegisterClipboardFormat(L"MYCOMPUT_SNAPIN_RAW_COOKIE");
  113. STDMETHODIMP ComponentData::QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT* ppDataObject)
  114. {
  115. MFC_TRY;
  116. Cookie* pUseThisCookie =
  117. (Cookie*) ActiveBaseCookie(reinterpret_cast<CCookie*>(cookie));
  118. CComObject<CSchmMgmtDataObject>* pDataObject = NULL;
  119. HRESULT hRes = CComObject<CSchmMgmtDataObject>::CreateInstance(&pDataObject);
  120. if ( FAILED(hRes) )
  121. return hRes;
  122. HRESULT hr = pDataObject->Initialize( pUseThisCookie, type );
  123. if ( SUCCEEDED(hr) )
  124. {
  125. hr = pDataObject->QueryInterface(IID_IDataObject,
  126. reinterpret_cast<void**>(ppDataObject));
  127. }
  128. if ( FAILED(hr) )
  129. {
  130. delete pDataObject;
  131. return hr;
  132. }
  133. return hr;
  134. MFC_CATCH;
  135. }