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.

403 lines
6.8 KiB

  1. //-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: xfiledataobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "dxfile.h"
  14. #include "XFileBinaryObj.h"
  15. #include "XFileReferenceObj.h"
  16. #include "XFileDataObj.h"
  17. extern HRESULT BSTRtoGUID(LPGUID,BSTR);
  18. extern BSTR GUIDtoBSTR(LPGUID);
  19. extern BSTR XFILEGUIDtoBSTR(LPGUID);
  20. extern HRESULT XFILEBSTRtoGUID(LPGUID,BSTR);
  21. C_dxj_DirectXFileDataObject::C_dxj_DirectXFileDataObject()
  22. {
  23. m_pXFileData=NULL;
  24. }
  25. C_dxj_DirectXFileDataObject::~C_dxj_DirectXFileDataObject()
  26. {
  27. if (m_pXFileData) m_pXFileData->Release();
  28. }
  29. HRESULT C_dxj_DirectXFileDataObject::create( IDirectXFileData *pData,I_dxj_DirectXFileData **ret)
  30. {
  31. HRESULT hr;
  32. if (!ret) return E_INVALIDARG;
  33. C_dxj_DirectXFileDataObject *c=NULL;
  34. c=new CComObject<C_dxj_DirectXFileDataObject>;
  35. if( c == NULL ) return E_OUTOFMEMORY;
  36. hr=c->InternalSetObject((IUnknown*)pData);
  37. if FAILED(hr){
  38. delete c;
  39. return hr;
  40. }
  41. hr=IUNK(c)->QueryInterface(IID_I_dxj_DirectXFileData, (void**)ret);
  42. return hr;
  43. }
  44. HRESULT C_dxj_DirectXFileDataObject::InternalSetObject(IUnknown *pUnk)
  45. {
  46. m_pXFileData=(IDirectXFileData*)pUnk;
  47. return S_OK;
  48. }
  49. HRESULT C_dxj_DirectXFileDataObject::InternalGetObject(IUnknown **pUnk)
  50. {
  51. *pUnk=(IUnknown*)m_pXFileData;
  52. return S_OK;
  53. }
  54. STDMETHODIMP C_dxj_DirectXFileDataObject::GetName(
  55. /* [retval][out] */ BSTR __RPC_FAR *name)
  56. {
  57. HRESULT hr;
  58. USES_CONVERSION;
  59. char szName[1024];
  60. DWORD dwSize=1024;
  61. hr=m_pXFileData->GetName(szName,&dwSize);
  62. if FAILED(hr) return hr;
  63. *name=T2BSTR(szName);
  64. return S_OK;
  65. }
  66. STDMETHODIMP C_dxj_DirectXFileDataObject::GetId(
  67. /* [retval][out] */ BSTR __RPC_FAR *name)
  68. {
  69. HRESULT hr;
  70. GUID g;
  71. ZeroMemory(&g,sizeof(GUID));
  72. hr=m_pXFileData->GetId(&g);
  73. if FAILED(hr) return hr;
  74. *name=XFILEGUIDtoBSTR(&g);
  75. return hr;
  76. }
  77. STDMETHODIMP C_dxj_DirectXFileDataObject::GetDataSize(
  78. /* [in] */ BSTR name,
  79. /* [retval][out] */ long __RPC_FAR *size)
  80. {
  81. USES_CONVERSION;
  82. HRESULT hr;
  83. LPVOID pvData=NULL;
  84. DWORD dwSize=0;
  85. if (name[0]==0)
  86. {
  87. hr=m_pXFileData->GetData(NULL,&dwSize,&pvData);
  88. }
  89. else
  90. {
  91. LPSTR szName=W2T(name);
  92. hr=m_pXFileData->GetData(szName,&dwSize,&pvData);
  93. }
  94. *size=dwSize;
  95. return hr;
  96. }
  97. STDMETHODIMP C_dxj_DirectXFileDataObject::GetData(
  98. /* [in] */ BSTR name,
  99. /* [in] */ void __RPC_FAR *data)
  100. {
  101. USES_CONVERSION;
  102. HRESULT hr;
  103. LPVOID pvData=NULL;
  104. DWORD dwSize=0;
  105. if (name[0]==0)
  106. {
  107. hr=m_pXFileData->GetData(NULL,&dwSize,&pvData);
  108. }
  109. else
  110. {
  111. LPSTR szName=W2T(name);
  112. hr=m_pXFileData->GetData(szName,&dwSize,&pvData);
  113. }
  114. __try{
  115. memcpy(data,pvData,dwSize);
  116. }
  117. __except(1,1){
  118. return E_INVALIDARG;
  119. }
  120. return hr;
  121. }
  122. STDMETHODIMP C_dxj_DirectXFileDataObject::GetType(
  123. /* [retval][out] */ BSTR __RPC_FAR *type)
  124. {
  125. HRESULT hr;
  126. const GUID* pGUID;
  127. hr=m_pXFileData->GetType(&pGUID);
  128. if FAILED(hr) return hr;
  129. *type=XFILEGUIDtoBSTR((GUID*)pGUID);
  130. return hr;
  131. }
  132. STDMETHODIMP C_dxj_DirectXFileDataObject::GetNextObject(
  133. /* [retval][out] */ I_dxj_DirectXFileObject __RPC_FAR *__RPC_FAR *type)
  134. {
  135. HRESULT hr;
  136. IDirectXFileObject *pObj=NULL;
  137. hr=m_pXFileData->GetNextObject(&pObj);
  138. if (hr==DXFILEERR_NOMOREOBJECTS){
  139. *type=NULL;
  140. return S_OK;
  141. }
  142. if FAILED(hr) return hr;
  143. LPUNKNOWN pUnk=NULL;
  144. LPUNKNOWN pCover=NULL;
  145. if (!pObj){
  146. *type=NULL;
  147. return S_OK;
  148. }
  149. hr=pObj->QueryInterface(IID_IDirectXFileData,(void**)&pUnk);
  150. if SUCCEEDED(hr)
  151. {
  152. pObj->Release();
  153. hr=C_dxj_DirectXFileDataObject::create((IDirectXFileData*)pUnk,(I_dxj_DirectXFileData**)&pCover);
  154. if FAILED(hr)
  155. {
  156. pUnk->Release();
  157. return hr;
  158. }
  159. hr=pCover->QueryInterface(IID_I_dxj_DirectXFileObject,(void**)type);
  160. pCover->Release();
  161. if FAILED(hr) pUnk->Release();
  162. return hr;
  163. }
  164. hr=pObj->QueryInterface(IID_IDirectXFileBinary,(void**)&pUnk);
  165. if SUCCEEDED(hr)
  166. {
  167. pObj->Release();
  168. hr=C_dxj_DirectXFileBinaryObject::create((IDirectXFileBinary*)pUnk,(I_dxj_DirectXFileBinary**)&pCover);
  169. if FAILED(hr)
  170. {
  171. pUnk->Release();
  172. return hr;
  173. }
  174. hr=pCover->QueryInterface(IID_I_dxj_DirectXFileObject,(void**)type);
  175. pCover->Release();
  176. if FAILED(hr) pUnk->Release();
  177. return hr;
  178. }
  179. hr=pObj->QueryInterface(IID_IDirectXFileDataReference,(void**)&pUnk);
  180. if SUCCEEDED(hr)
  181. {
  182. pObj->Release();
  183. hr=C_dxj_DirectXFileReferenceObject::create((IDirectXFileDataReference*)pUnk,(I_dxj_DirectXFileReference**)&pCover);
  184. if FAILED(hr)
  185. {
  186. pUnk->Release();
  187. return hr;
  188. }
  189. hr=pCover->QueryInterface(IID_I_dxj_DirectXFileObject,(void**)type);
  190. pCover->Release();
  191. if FAILED(hr) pUnk->Release();
  192. return hr;
  193. }
  194. return E_NOTIMPL;
  195. }
  196. STDMETHODIMP C_dxj_DirectXFileDataObject::AddDataObject(
  197. /* [in] */ I_dxj_DirectXFileData __RPC_FAR *data)
  198. {
  199. HRESULT hr;
  200. if (!data) return E_INVALIDARG;
  201. IDirectXFileData *pData=NULL;
  202. //note does not addref
  203. data->InternalGetObject((IUnknown**)&pData);
  204. if (!pData) return E_FAIL;
  205. hr=m_pXFileData->AddDataObject(pData);
  206. return hr;
  207. }
  208. STDMETHODIMP C_dxj_DirectXFileDataObject::AddDataReference(
  209. /* [in] */ BSTR name,
  210. /* [in] */ BSTR guid)
  211. {
  212. USES_CONVERSION;
  213. HRESULT hr;
  214. LPSTR szName=NULL;
  215. GUID *lpGuid=NULL;
  216. GUID g;
  217. ZeroMemory(&g,sizeof(GUID));
  218. if (name[0]!=0)
  219. {
  220. szName=W2T(name);
  221. }
  222. if (guid[0]!=0)
  223. {
  224. hr=XFILEBSTRtoGUID(&g,guid);
  225. if FAILED(hr) return hr;
  226. lpGuid=&g;
  227. }
  228. hr=m_pXFileData->AddDataReference(szName,lpGuid);
  229. return hr;
  230. }
  231. STDMETHODIMP C_dxj_DirectXFileDataObject::AddBinaryObject(
  232. /* [in] */ BSTR name,
  233. /* [in] */ BSTR guidObject,
  234. /* [in] */ BSTR MimeType,
  235. void __RPC_FAR *data,
  236. /* [in] */ long size)
  237. {
  238. USES_CONVERSION;
  239. HRESULT hr;
  240. GUID gObj;
  241. GUID *lpGuid=NULL;
  242. LPSTR szMime=NULL;
  243. LPSTR szName=NULL;
  244. ZeroMemory(&gObj,sizeof(GUID));
  245. if (!data) return E_INVALIDARG;
  246. if ((guidObject) && (guidObject[0]!=0))
  247. {
  248. hr=XFILEBSTRtoGUID(&gObj,guidObject);
  249. if FAILED(hr) return hr;
  250. lpGuid=&gObj;
  251. }
  252. if ((name) && (name[0]!=0))
  253. {
  254. szName=W2T(name);
  255. }
  256. if ((MimeType) && (MimeType[0]!=0))
  257. {
  258. szMime=W2T(MimeType);
  259. }
  260. IDirectXFileData *pData=NULL;
  261. __try
  262. {
  263. hr=m_pXFileData->AddBinaryObject(szName,lpGuid,szMime,data,size);
  264. }
  265. __except(1,1)
  266. {
  267. return E_INVALIDARG;
  268. }
  269. return hr;
  270. }
  271. STDMETHODIMP C_dxj_DirectXFileDataObject::GetDataFromOffset(
  272. /* [in] */ BSTR name,
  273. /* [in] */ long offset,
  274. /* [in] */ long bytecount,
  275. /* [in] */ void *data)
  276. {
  277. USES_CONVERSION;
  278. HRESULT hr;
  279. LPVOID pvData=NULL;
  280. DWORD dwSize=0;
  281. if (name[0]==0)
  282. {
  283. hr=m_pXFileData->GetData(NULL,&dwSize,&pvData);
  284. }
  285. else
  286. {
  287. LPSTR szName=W2T(name);
  288. hr=m_pXFileData->GetData(szName,&dwSize,&pvData);
  289. }
  290. __try{
  291. memcpy(data,&((char*)pvData)[offset],bytecount);
  292. }
  293. __except(1,1){
  294. return E_INVALIDARG;
  295. }
  296. return hr;
  297. }