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.

211 lines
6.4 KiB

  1. #include "precomp.h"
  2. unsigned int CDataObject::m_cfNodeType = RegisterClipboardFormat(CCF_NODETYPE);
  3. unsigned int CDataObject::m_cfNodeTypeString = RegisterClipboardFormat(CCF_SZNODETYPE);
  4. unsigned int CDataObject::m_cfDisplayName = RegisterClipboardFormat(CCF_DISPLAY_NAME);
  5. unsigned int CDataObject::m_cfCoClass = RegisterClipboardFormat(CCF_SNAPIN_CLASSID);
  6. ///////////////////////////////////////////////////////////////////////////////
  7. // //
  8. // CDataObject implementation //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. CDataObject::CDataObject(CComponentData *pComponent)
  12. {
  13. m_cRef = 1;
  14. InterlockedIncrement(&g_cRefThisDll);
  15. m_pcd = pComponent;
  16. m_type = CCT_UNINITIALIZED;
  17. m_cookie = -1;
  18. }
  19. CDataObject::~CDataObject()
  20. {
  21. InterlockedDecrement(&g_cRefThisDll);
  22. }
  23. ///////////////////////////////////////////////////////////////////////////////
  24. // //
  25. // CDataObject object implementation (IUnknown) //
  26. // //
  27. ///////////////////////////////////////////////////////////////////////////////
  28. HRESULT CDataObject::QueryInterface (REFIID riid, void **ppv)
  29. {
  30. if (IsEqualIID(riid, IID_IIEAKDataObject))
  31. {
  32. *ppv = (LPIEAKDATAOBJECT)this;
  33. m_cRef++;
  34. return S_OK;
  35. }
  36. else if (IsEqualIID(riid, IID_IDataObject) ||
  37. IsEqualIID(riid, IID_IUnknown))
  38. {
  39. *ppv = (LPDATAOBJECT)this;
  40. m_cRef++;
  41. return S_OK;
  42. }
  43. else
  44. {
  45. *ppv = NULL;
  46. return E_NOINTERFACE;
  47. }
  48. }
  49. ULONG CDataObject::AddRef (void)
  50. {
  51. return ++m_cRef;
  52. }
  53. ULONG CDataObject::Release (void)
  54. {
  55. if (--m_cRef == 0) {
  56. delete this;
  57. return 0;
  58. }
  59. return m_cRef;
  60. }
  61. ///////////////////////////////////////////////////////////////////////////////
  62. // //
  63. // CDataObject object implementation (IDataObject) //
  64. // //
  65. ///////////////////////////////////////////////////////////////////////////////
  66. STDMETHODIMP CDataObject::GetDataHere(LPFORMATETC lpFormatetc, LPSTGMEDIUM lpMedium)
  67. {
  68. HRESULT hr = DV_E_CLIPFORMAT;
  69. // Based on the CLIPFORMAT write data to the stream
  70. const CLIPFORMAT cf = lpFormatetc->cfFormat;
  71. if(cf == m_cfNodeType)
  72. {
  73. hr = CreateNodeTypeData(lpMedium);
  74. }
  75. else if(cf == m_cfNodeTypeString)
  76. {
  77. hr = CreateNodeTypeStringData(lpMedium);
  78. }
  79. else if (cf == m_cfDisplayName)
  80. {
  81. hr = CreateDisplayName(lpMedium);
  82. }
  83. else if (cf == m_cfCoClass)
  84. {
  85. hr = CreateCoClassID(lpMedium);
  86. }
  87. return hr;
  88. }
  89. ///////////////////////////////////////////////////////////////////////////////
  90. // //
  91. // CDataObject object implementation (Internal functions) //
  92. // //
  93. ///////////////////////////////////////////////////////////////////////////////
  94. HRESULT CDataObject::Create(LPVOID pBuffer, INT len, LPSTGMEDIUM lpMedium)
  95. {
  96. HRESULT hr = DV_E_TYMED;
  97. // Do some simple validation
  98. if (pBuffer == NULL || lpMedium == NULL)
  99. return E_POINTER;
  100. // Make sure the type medium is HGLOBAL
  101. if (lpMedium->tymed == TYMED_HGLOBAL)
  102. {
  103. // Create the stream on the hGlobal passed in
  104. LPSTREAM lpStream;
  105. hr = CreateStreamOnHGlobal(lpMedium->hGlobal, FALSE, &lpStream);
  106. if (SUCCEEDED(hr))
  107. {
  108. // Write to the stream the number of bytes
  109. unsigned long written;
  110. hr = lpStream->Write(pBuffer, len, &written);
  111. // Because we told CreateStreamOnHGlobal with 'FALSE',
  112. // only the stream is released here.
  113. // Note - the caller (i.e. snap-in, object) will free the HGLOBAL
  114. // at the correct time. This is according to the IDataObject specification.
  115. lpStream->Release();
  116. }
  117. }
  118. return hr;
  119. }
  120. HRESULT CDataObject::CreateNodeTypeData(LPSTGMEDIUM lpMedium)
  121. {
  122. const GUID * pGUID;
  123. if (m_cookie == -1)
  124. return E_UNEXPECTED;
  125. if (m_type == CCT_RESULT)
  126. {
  127. LPRESULTITEM lpResultItem = (LPRESULTITEM)((LPIEAKMMCCOOKIE)m_cookie)->lpItem;
  128. pGUID = g_NameSpace[lpResultItem->dwNameSpaceItem].pNodeID;
  129. }
  130. else
  131. pGUID = g_NameSpace[PtrToUlong(((LPIEAKMMCCOOKIE)m_cookie)->lpItem)].pNodeID;
  132. // Create the node type object in GUID format
  133. return Create((LPVOID)pGUID, sizeof(GUID), lpMedium);
  134. }
  135. HRESULT CDataObject::CreateNodeTypeStringData(LPSTGMEDIUM lpMedium)
  136. {
  137. const GUID * pGUID;
  138. TCHAR szNodeType[50];
  139. if (m_cookie == -1)
  140. return E_UNEXPECTED;
  141. if (m_type == CCT_RESULT)
  142. {
  143. LPRESULTITEM lpResultItem = (LPRESULTITEM)((LPIEAKMMCCOOKIE)m_cookie)->lpItem;
  144. pGUID = g_NameSpace[lpResultItem->dwNameSpaceItem].pNodeID;
  145. }
  146. else
  147. pGUID = g_NameSpace[PtrToUlong(((LPIEAKMMCCOOKIE)m_cookie)->lpItem)].pNodeID;
  148. szNodeType[0] = TEXT('\0');
  149. StringFromGUID2(*pGUID, szNodeType, ARRAYSIZE(szNodeType));
  150. // Create the node type object in GUID string format
  151. return Create((LPVOID)szNodeType, ((lstrlenW(szNodeType)+1) * sizeof(WCHAR)), lpMedium);
  152. }
  153. HRESULT CDataObject::CreateDisplayName(LPSTGMEDIUM lpMedium)
  154. {
  155. TCHAR szDisplayName[100];
  156. LoadString(g_hInstance, IDS_SIE_NAME, szDisplayName, ARRAYSIZE(szDisplayName));
  157. return Create((LPVOID)szDisplayName, (lstrlen(szDisplayName) + 1) * sizeof(TCHAR), lpMedium);
  158. }
  159. HRESULT CDataObject::CreateCoClassID(LPSTGMEDIUM lpMedium)
  160. {
  161. // Create the CoClass information
  162. if (m_pcd->IsRSoP())
  163. return Create((LPVOID)&CLSID_IEAKRSoPSnapinExt, sizeof(CLSID), lpMedium);
  164. else
  165. return Create((LPVOID)&CLSID_IEAKSnapinExt, sizeof(CLSID), lpMedium);
  166. }