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.

217 lines
6.4 KiB

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