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.

152 lines
4.4 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1998.
  5. //
  6. // File: dataobj.cpp
  7. //
  8. // Contents: implementation of IDataObject
  9. //
  10. // Classes: CDataObject
  11. //
  12. // History: 03-14-1998 stevebl Commented
  13. //
  14. //---------------------------------------------------------------------------
  15. #include "precomp.hxx"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. unsigned int CDataObject::m_cfNodeType = RegisterClipboardFormat(CCF_NODETYPE);
  22. unsigned int CDataObject::m_cfNodeTypeString = RegisterClipboardFormat(CCF_SZNODETYPE);
  23. unsigned int CDataObject::m_cfDisplayName = RegisterClipboardFormat(CCF_DISPLAY_NAME);
  24. unsigned int CDataObject::m_cfCoClass = RegisterClipboardFormat(CCF_SNAPIN_CLASSID);
  25. unsigned int CDataObject::m_cfInternal = RegisterClipboardFormat(SNAPIN_INTERNAL);
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CDataObject implementations
  28. STDMETHODIMP CDataObject::GetDataHere(LPFORMATETC lpFormatetc, LPSTGMEDIUM lpMedium)
  29. {
  30. HRESULT hr = DV_E_CLIPFORMAT;
  31. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  32. // Based on the CLIPFORMAT write data to the stream
  33. const CLIPFORMAT cf = lpFormatetc->cfFormat;
  34. if(cf == m_cfNodeType)
  35. {
  36. hr = CreateNodeTypeData(lpMedium);
  37. }
  38. else if(cf == m_cfNodeTypeString)
  39. {
  40. hr = CreateNodeTypeStringData(lpMedium);
  41. }
  42. else if (cf == m_cfDisplayName)
  43. {
  44. hr = CreateDisplayName(lpMedium);
  45. }
  46. else if (cf == m_cfCoClass)
  47. {
  48. hr = CreateCoClassID(lpMedium);
  49. }
  50. else if (cf == m_cfInternal)
  51. {
  52. hr = CreateInternal(lpMedium);
  53. }
  54. return hr;
  55. }
  56. // Note - Sample does not implement these
  57. STDMETHODIMP CDataObject::GetData(LPFORMATETC lpFormatetcIn, LPSTGMEDIUM lpMedium)
  58. {
  59. return E_NOTIMPL;
  60. }
  61. STDMETHODIMP CDataObject::EnumFormatEtc(DWORD dwDirection, LPENUMFORMATETC* ppEnumFormatEtc)
  62. {
  63. return E_NOTIMPL;
  64. }
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CDataObject creation members
  67. HRESULT CDataObject::Create(const void* pBuffer, int len, LPSTGMEDIUM lpMedium)
  68. {
  69. HRESULT hr = DV_E_TYMED;
  70. // Do some simple validation
  71. if (pBuffer == NULL || lpMedium == NULL)
  72. return E_POINTER;
  73. // Make sure the type medium is HGLOBAL
  74. if (lpMedium->tymed == TYMED_HGLOBAL)
  75. {
  76. // Create the stream on the hGlobal passed in
  77. LPSTREAM lpStream;
  78. hr = CreateStreamOnHGlobal(lpMedium->hGlobal, FALSE, &lpStream);
  79. if (SUCCEEDED(hr))
  80. {
  81. // Write to the stream the number of bytes
  82. unsigned long written;
  83. hr = lpStream->Write(pBuffer, len, &written);
  84. // Because we told CreateStreamOnHGlobal with 'FALSE',
  85. // only the stream is released here.
  86. // Note - the caller (i.e. snap-in, object) will free the HGLOBAL
  87. // at the correct time. This is according to the IDataObject specification.
  88. lpStream->Release();
  89. }
  90. }
  91. return hr;
  92. }
  93. HRESULT CDataObject::CreateNodeTypeData(LPSTGMEDIUM lpMedium)
  94. {
  95. // Create the node type object in GUID format
  96. return Create(reinterpret_cast<const void*>(&cNodeType), sizeof(GUID), lpMedium);
  97. }
  98. HRESULT CDataObject::CreateNodeTypeStringData(LPSTGMEDIUM lpMedium)
  99. {
  100. // Create the node type object in GUID string format
  101. return Create(cszNodeType, ((wcslen(cszNodeType)+1) * sizeof(wchar_t)), lpMedium);
  102. }
  103. HRESULT CDataObject::CreateDisplayName(LPSTGMEDIUM lpMedium)
  104. {
  105. // This is the display named used in the scope pane and snap-in manager
  106. // Load the name from resource
  107. // Note - if this is not provided, the console will used the snap-in name
  108. CString szDispName;
  109. szDispName.LoadString(IDS_NODENAME);
  110. return Create(szDispName, ((szDispName.GetLength()+1) * sizeof(wchar_t)), lpMedium);
  111. }
  112. HRESULT CDataObject::CreateCoClassID(LPSTGMEDIUM lpMedium)
  113. {
  114. // Create the CoClass information
  115. if (m_fMachine)
  116. return Create((LPVOID)&CLSID_MachineSnapin, sizeof(CLSID), lpMedium);
  117. else
  118. return Create((LPVOID)&CLSID_Snapin, sizeof(CLSID), lpMedium);
  119. }
  120. HRESULT CDataObject::CreateInternal(LPSTGMEDIUM lpMedium)
  121. {
  122. return Create(&m_internal, sizeof(INTERNAL), lpMedium);
  123. }