2 * Implementation of DirectX File Interfaces
4 * Copyright 2004, 2008 Christian Costa
6 * This file contains the (internal) driver registration functions,
7 * driver enumeration APIs and DirectDraw creation functions.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/debug.h"
32 #include "d3dxof_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(d3dxof
);
39 #define MAKEFOUR(a,b,c,d) ((DWORD)a + ((DWORD)b << 8) + ((DWORD)c << 16) + ((DWORD)d << 24))
40 #define XOFFILE_FORMAT_MAGIC MAKEFOUR('x','o','f',' ')
41 #define XOFFILE_FORMAT_VERSION_302 MAKEFOUR('0','3','0','2')
42 #define XOFFILE_FORMAT_VERSION_303 MAKEFOUR('0','3','0','3')
43 #define XOFFILE_FORMAT_BINARY MAKEFOUR('b','i','n',' ')
44 #define XOFFILE_FORMAT_TEXT MAKEFOUR('t','x','t',' ')
45 #define XOFFILE_FORMAT_COMPRESSED MAKEFOUR('c','m','p',' ')
46 #define XOFFILE_FORMAT_FLOAT_BITS_32 MAKEFOUR('0','0','3','2')
47 #define XOFFILE_FORMAT_FLOAT_BITS_64 MAKEFOUR('0','0','6','4')
49 static const struct IDirectXFileVtbl IDirectXFile_Vtbl
;
50 static const struct IDirectXFileBinaryVtbl IDirectXFileBinary_Vtbl
;
51 static const struct IDirectXFileDataVtbl IDirectXFileData_Vtbl
;
52 static const struct IDirectXFileDataReferenceVtbl IDirectXFileDataReference_Vtbl
;
53 static const struct IDirectXFileEnumObjectVtbl IDirectXFileEnumObject_Vtbl
;
54 static const struct IDirectXFileObjectVtbl IDirectXFileObject_Vtbl
;
55 static const struct IDirectXFileSaveObjectVtbl IDirectXFileSaveObject_Vtbl
;
57 static HRESULT
IDirectXFileDataReferenceImpl_Create(IDirectXFileDataReferenceImpl
** ppObj
);
58 static HRESULT
IDirectXFileEnumObjectImpl_Create(IDirectXFileEnumObjectImpl
** ppObj
);
59 static HRESULT
IDirectXFileSaveObjectImpl_Create(IDirectXFileSaveObjectImpl
** ppObj
);
61 HRESULT
IDirectXFileImpl_Create(IUnknown
* pUnkOuter
, LPVOID
* ppObj
)
63 IDirectXFileImpl
* object
;
65 TRACE("(%p,%p)\n", pUnkOuter
, ppObj
);
67 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectXFileImpl
));
70 ERR("Out of memory\n");
71 return DXFILEERR_BADALLOC
;
74 object
->lpVtbl
.lpVtbl
= &IDirectXFile_Vtbl
;
82 /*** IUnknown methods ***/
83 static HRESULT WINAPI
IDirectXFileImpl_QueryInterface(IDirectXFile
* iface
, REFIID riid
, void** ppvObject
)
85 IDirectXFileImpl
*This
= (IDirectXFileImpl
*)iface
;
87 TRACE("(%p/%p)->(%s,%p)\n", iface
, This
, debugstr_guid(riid
), ppvObject
);
89 if (IsEqualGUID(riid
, &IID_IUnknown
)
90 || IsEqualGUID(riid
, &IID_IDirectXFile
))
92 IClassFactory_AddRef(iface
);
97 ERR("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
101 static ULONG WINAPI
IDirectXFileImpl_AddRef(IDirectXFile
* iface
)
103 IDirectXFileImpl
*This
= (IDirectXFileImpl
*)iface
;
104 ULONG ref
= InterlockedIncrement(&This
->ref
);
106 TRACE("(%p/%p): AddRef from %d\n", iface
, This
, ref
- 1);
111 static ULONG WINAPI
IDirectXFileImpl_Release(IDirectXFile
* iface
)
113 IDirectXFileImpl
*This
= (IDirectXFileImpl
*)iface
;
114 ULONG ref
= InterlockedDecrement(&This
->ref
);
116 TRACE("(%p/%p): ReleaseRef to %d\n", iface
, This
, ref
);
119 HeapFree(GetProcessHeap(), 0, This
);
124 /*** IDirectXFile methods ***/
125 static HRESULT WINAPI
IDirectXFileImpl_CreateEnumObject(IDirectXFile
* iface
, LPVOID pvSource
, DXFILELOADOPTIONS dwLoadOptions
, LPDIRECTXFILEENUMOBJECT
* ppEnumObj
)
127 IDirectXFileImpl
*This
= (IDirectXFileImpl
*)iface
;
128 IDirectXFileEnumObjectImpl
* object
;
131 HANDLE hFile
= INVALID_HANDLE_VALUE
;
132 HANDLE file_mapping
= 0;
133 LPBYTE buffer
= NULL
;
134 HGLOBAL resource_data
= 0;
138 LPDXFILELOADMEMORY lpdxflm
= NULL
;
140 TRACE("(%p/%p)->(%p,%x,%p)\n", This
, iface
, pvSource
, dwLoadOptions
, ppEnumObj
);
143 return DXFILEERR_BADVALUE
;
145 if (dwLoadOptions
== DXFILELOAD_FROMFILE
)
147 TRACE("Open source file '%s'\n", (char*)pvSource
);
149 hFile
= CreateFileA(pvSource
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, NULL
);
150 if (hFile
== INVALID_HANDLE_VALUE
)
152 TRACE("File '%s' not found\n", (char*)pvSource
);
153 return DXFILEERR_FILENOTFOUND
;
156 file_size
= GetFileSize(hFile
, NULL
);
158 file_mapping
= CreateFileMappingA(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
161 hr
= DXFILEERR_BADFILETYPE
;
165 buffer
= MapViewOfFile(file_mapping
, FILE_MAP_READ
, 0, 0, 0);
168 hr
= DXFILEERR_BADFILETYPE
;
171 file_buffer
= buffer
;
173 else if (dwLoadOptions
== DXFILELOAD_FROMRESOURCE
)
176 LPDXFILELOADRESOURCE lpdxflr
= pvSource
;
178 TRACE("Source in resource (module = %p, name = %s, type = %s\n", lpdxflr
->hModule
, debugstr_a(lpdxflr
->lpName
), debugstr_a(lpdxflr
->lpType
));
180 resource_info
= FindResourceA(lpdxflr
->hModule
, lpdxflr
->lpName
, lpdxflr
->lpType
);
183 hr
= DXFILEERR_RESOURCENOTFOUND
;
187 file_size
= SizeofResource(lpdxflr
->hModule
, resource_info
);
189 resource_data
= LoadResource(lpdxflr
->hModule
, resource_info
);
192 hr
= DXFILEERR_BADRESOURCE
;
196 file_buffer
= LockResource(resource_data
);
199 hr
= DXFILEERR_BADRESOURCE
;
203 else if (dwLoadOptions
== DXFILELOAD_FROMMEMORY
)
207 TRACE("Source in memory at %p with size %d\n", lpdxflm
->lpMemory
, lpdxflm
->dSize
);
209 file_buffer
= lpdxflm
->lpMemory
;
210 file_size
= lpdxflm
->dSize
;
214 FIXME("Source type %d is not handled yet\n", dwLoadOptions
);
215 hr
= DXFILEERR_NOTDONEYET
;
219 header
= (DWORD
*)file_buffer
;
221 if (TRACE_ON(d3dxof
))
224 memcpy(string
, header
, 16);
226 TRACE("header = '%s'\n", string
);
231 hr
= DXFILEERR_BADFILETYPE
;
235 if (header
[0] != XOFFILE_FORMAT_MAGIC
)
237 hr
= DXFILEERR_BADFILETYPE
;
241 if ((header
[1] != XOFFILE_FORMAT_VERSION_302
) && (header
[1] != XOFFILE_FORMAT_VERSION_303
))
243 hr
= DXFILEERR_BADFILEVERSION
;
247 if ((header
[2] != XOFFILE_FORMAT_BINARY
) && (header
[2] != XOFFILE_FORMAT_TEXT
) && (header
[2] != XOFFILE_FORMAT_COMPRESSED
))
249 hr
= DXFILEERR_BADFILETYPE
;
253 if (header
[2] == XOFFILE_FORMAT_COMPRESSED
)
255 FIXME("Compressed formats not supported yet\n");
256 hr
= DXFILEERR_BADVALUE
;
260 if ((header
[3] != XOFFILE_FORMAT_FLOAT_BITS_32
) && (header
[3] != XOFFILE_FORMAT_FLOAT_BITS_64
))
262 hr
= DXFILEERR_BADFILEFLOATSIZE
;
266 TRACE("Header is correct\n");
268 hr
= IDirectXFileEnumObjectImpl_Create(&object
);
272 object
->source
= dwLoadOptions
;
273 object
->hFile
= hFile
;
274 object
->file_mapping
= file_mapping
;
275 object
->buffer
= buffer
;
276 object
->pDirectXFile
= This
;
277 object
->buf
.pdxf
= This
;
278 object
->buf
.txt
= (header
[2] == XOFFILE_FORMAT_TEXT
);
279 object
->buf
.token_present
= FALSE
;
280 object
->buf
.cur_subobject
= 0;
282 TRACE("File size is %d bytes\n", file_size
);
284 /* Go to data after header */
285 object
->buf
.buffer
= file_buffer
+ 16;
286 object
->buf
.rem_bytes
= file_size
- 16;
288 *ppEnumObj
= (LPDIRECTXFILEENUMOBJECT
)object
;
290 while (object
->buf
.rem_bytes
&& is_template_available(&object
->buf
))
292 if (!parse_template(&object
->buf
))
294 TRACE("Template is not correct\n");
295 hr
= DXFILEERR_BADVALUE
;
300 TRACE("Template successfully parsed:\n");
301 if (TRACE_ON(d3dxof
))
302 dump_template(This
->xtemplates
, &This
->xtemplates
[This
->nb_xtemplates
- 1]);
306 if (TRACE_ON(d3dxof
))
309 TRACE("Registered templates (%d):\n", This
->nb_xtemplates
);
310 for (i
= 0; i
< This
->nb_xtemplates
; i
++)
311 DPRINTF("%s - %s\n", This
->xtemplates
[i
].name
, debugstr_guid(&This
->xtemplates
[i
].class_id
));
318 UnmapViewOfFile(buffer
);
320 CloseHandle(file_mapping
);
321 if (hFile
!= INVALID_HANDLE_VALUE
)
324 FreeResource(resource_data
);
330 static HRESULT WINAPI
IDirectXFileImpl_CreateSaveObject(IDirectXFile
* iface
, LPCSTR szFileName
, DXFILEFORMAT dwFileFormat
, LPDIRECTXFILESAVEOBJECT
* ppSaveObj
)
332 IDirectXFileImpl
*This
= (IDirectXFileImpl
*)iface
;
334 FIXME("(%p/%p)->(%s,%x,%p) partial stub!\n", This
, iface
, szFileName
, dwFileFormat
, ppSaveObj
);
336 if (!szFileName
|| !ppSaveObj
)
339 return IDirectXFileSaveObjectImpl_Create((IDirectXFileSaveObjectImpl
**)ppSaveObj
);
342 static HRESULT WINAPI
IDirectXFileImpl_RegisterTemplates(IDirectXFile
* iface
, LPVOID pvData
, DWORD cbSize
)
344 IDirectXFileImpl
*This
= (IDirectXFileImpl
*)iface
;
349 buf
.rem_bytes
= cbSize
;
351 buf
.token_present
= FALSE
;
354 TRACE("(%p/%p)->(%p,%d)\n", This
, iface
, pvData
, cbSize
);
357 return DXFILEERR_BADVALUE
;
360 return DXFILEERR_BADFILETYPE
;
362 if (TRACE_ON(d3dxof
))
365 memcpy(string
, pvData
, 16);
367 TRACE("header = '%s'\n", string
);
370 read_bytes(&buf
, &token_header
, 4);
372 if (token_header
!= XOFFILE_FORMAT_MAGIC
)
373 return DXFILEERR_BADFILETYPE
;
375 read_bytes(&buf
, &token_header
, 4);
377 if ((token_header
!= XOFFILE_FORMAT_VERSION_302
) && (token_header
!= XOFFILE_FORMAT_VERSION_303
))
378 return DXFILEERR_BADFILEVERSION
;
380 read_bytes(&buf
, &token_header
, 4);
382 if ((token_header
!= XOFFILE_FORMAT_BINARY
) && (token_header
!= XOFFILE_FORMAT_TEXT
) && (token_header
!= XOFFILE_FORMAT_COMPRESSED
))
383 return DXFILEERR_BADFILETYPE
;
385 if (token_header
== XOFFILE_FORMAT_TEXT
)
390 if (token_header
== XOFFILE_FORMAT_COMPRESSED
)
392 FIXME("Compressed formats not supported yet\n");
393 return DXFILEERR_BADVALUE
;
396 read_bytes(&buf
, &token_header
, 4);
398 if ((token_header
!= XOFFILE_FORMAT_FLOAT_BITS_32
) && (token_header
!= XOFFILE_FORMAT_FLOAT_BITS_64
))
399 return DXFILEERR_BADFILEFLOATSIZE
;
401 TRACE("Header is correct\n");
403 while (buf
.rem_bytes
)
405 if (!parse_template(&buf
))
407 TRACE("Template is not correct\n");
408 return DXFILEERR_BADVALUE
;
412 TRACE("Template successfully parsed:\n");
413 if (TRACE_ON(d3dxof
))
414 dump_template(This
->xtemplates
, &This
->xtemplates
[This
->nb_xtemplates
- 1]);
418 if (TRACE_ON(d3dxof
))
421 TRACE("Registered templates (%d):\n", This
->nb_xtemplates
);
422 for (i
= 0; i
< This
->nb_xtemplates
; i
++)
423 DPRINTF("%s - %s\n", This
->xtemplates
[i
].name
, debugstr_guid(&This
->xtemplates
[i
].class_id
));
429 static const IDirectXFileVtbl IDirectXFile_Vtbl
=
431 IDirectXFileImpl_QueryInterface
,
432 IDirectXFileImpl_AddRef
,
433 IDirectXFileImpl_Release
,
434 IDirectXFileImpl_CreateEnumObject
,
435 IDirectXFileImpl_CreateSaveObject
,
436 IDirectXFileImpl_RegisterTemplates
439 static HRESULT
IDirectXFileBinaryImpl_Create(IDirectXFileBinaryImpl
** ppObj
)
441 IDirectXFileBinaryImpl
* object
;
443 TRACE("(%p)\n", ppObj
);
445 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectXFileBinaryImpl
));
448 ERR("Out of memory\n");
449 return DXFILEERR_BADALLOC
;
452 object
->lpVtbl
.lpVtbl
= &IDirectXFileBinary_Vtbl
;
460 /*** IUnknown methods ***/
461 static HRESULT WINAPI
IDirectXFileBinaryImpl_QueryInterface(IDirectXFileBinary
* iface
, REFIID riid
, void** ppvObject
)
463 IDirectXFileBinaryImpl
*This
= (IDirectXFileBinaryImpl
*)iface
;
465 TRACE("(%p/%p)->(%s,%p)\n", iface
, This
, debugstr_guid(riid
), ppvObject
);
467 if (IsEqualGUID(riid
, &IID_IUnknown
)
468 || IsEqualGUID(riid
, &IID_IDirectXFileObject
)
469 || IsEqualGUID(riid
, &IID_IDirectXFileBinary
))
471 IClassFactory_AddRef(iface
);
476 /* Do not print an error for interfaces that can be queried to retrieve the type of the object */
477 if (!IsEqualGUID(riid
, &IID_IDirectXFileData
)
478 && !IsEqualGUID(riid
, &IID_IDirectXFileDataReference
))
479 ERR("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
481 return E_NOINTERFACE
;
484 static ULONG WINAPI
IDirectXFileBinaryImpl_AddRef(IDirectXFileBinary
* iface
)
486 IDirectXFileBinaryImpl
*This
= (IDirectXFileBinaryImpl
*)iface
;
487 ULONG ref
= InterlockedIncrement(&This
->ref
);
489 TRACE("(%p/%p): AddRef from %d\n", iface
, This
, ref
- 1);
494 static ULONG WINAPI
IDirectXFileBinaryImpl_Release(IDirectXFileBinary
* iface
)
496 IDirectXFileBinaryImpl
*This
= (IDirectXFileBinaryImpl
*)iface
;
497 ULONG ref
= InterlockedDecrement(&This
->ref
);
499 TRACE("(%p/%p): ReleaseRef to %d\n", iface
, This
, ref
);
502 HeapFree(GetProcessHeap(), 0, This
);
507 /*** IDirectXFileObject methods ***/
508 static HRESULT WINAPI
IDirectXFileBinaryImpl_GetName(IDirectXFileBinary
* iface
, LPSTR pstrNameBuf
, LPDWORD pdwBufLen
)
511 IDirectXFileBinaryImpl
*This
= (IDirectXFileBinaryImpl
*)iface
;
513 FIXME("(%p/%p)->(%p,%p) stub!\n", This
, iface
, pstrNameBuf
, pdwBufLen
);
515 return DXFILEERR_BADVALUE
;
518 static HRESULT WINAPI
IDirectXFileBinaryImpl_GetId(IDirectXFileBinary
* iface
, LPGUID pGuid
)
520 IDirectXFileBinaryImpl
*This
= (IDirectXFileBinaryImpl
*)iface
;
522 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, pGuid
);
524 return DXFILEERR_BADVALUE
;
527 /*** IDirectXFileBinary methods ***/
528 static HRESULT WINAPI
IDirectXFileBinaryImpl_GetSize(IDirectXFileBinary
* iface
, DWORD
* pcbSize
)
530 IDirectXFileBinaryImpl
*This
= (IDirectXFileBinaryImpl
*)iface
;
532 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, pcbSize
);
534 return DXFILEERR_BADVALUE
;
537 static HRESULT WINAPI
IDirectXFileBinaryImpl_GetMimeType(IDirectXFileBinary
* iface
, LPCSTR
* pszMimeType
)
539 IDirectXFileBinaryImpl
*This
= (IDirectXFileBinaryImpl
*)iface
;
541 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, pszMimeType
);
543 return DXFILEERR_BADVALUE
;
546 static HRESULT WINAPI
IDirectXFileBinaryImpl_Read(IDirectXFileBinary
* iface
, LPVOID pvData
, DWORD cbSize
, LPDWORD pcbRead
)
548 IDirectXFileBinaryImpl
*This
= (IDirectXFileBinaryImpl
*)iface
;
550 FIXME("(%p/%p)->(%p, %d, %p) stub!\n", This
, iface
, pvData
, cbSize
, pcbRead
);
552 return DXFILEERR_BADVALUE
;
555 static const IDirectXFileBinaryVtbl IDirectXFileBinary_Vtbl
=
557 IDirectXFileBinaryImpl_QueryInterface
,
558 IDirectXFileBinaryImpl_AddRef
,
559 IDirectXFileBinaryImpl_Release
,
560 IDirectXFileBinaryImpl_GetName
,
561 IDirectXFileBinaryImpl_GetId
,
562 IDirectXFileBinaryImpl_GetSize
,
563 IDirectXFileBinaryImpl_GetMimeType
,
564 IDirectXFileBinaryImpl_Read
567 static HRESULT
IDirectXFileDataImpl_Create(IDirectXFileDataImpl
** ppObj
)
569 IDirectXFileDataImpl
* object
;
571 TRACE("(%p)\n", ppObj
);
573 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectXFileDataImpl
));
576 ERR("Out of memory\n");
577 return DXFILEERR_BADALLOC
;
580 object
->lpVtbl
.lpVtbl
= &IDirectXFileData_Vtbl
;
588 /*** IUnknown methods ***/
589 static HRESULT WINAPI
IDirectXFileDataImpl_QueryInterface(IDirectXFileData
* iface
, REFIID riid
, void** ppvObject
)
591 IDirectXFileDataImpl
*This
= (IDirectXFileDataImpl
*)iface
;
593 TRACE("(%p/%p)->(%s,%p)\n", iface
, This
, debugstr_guid(riid
), ppvObject
);
595 if (IsEqualGUID(riid
, &IID_IUnknown
)
596 || IsEqualGUID(riid
, &IID_IDirectXFileObject
)
597 || IsEqualGUID(riid
, &IID_IDirectXFileData
))
599 IClassFactory_AddRef(iface
);
604 /* Do not print an error for interfaces that can be queried to retrieve the type of the object */
605 if (!IsEqualGUID(riid
, &IID_IDirectXFileBinary
)
606 && !IsEqualGUID(riid
, &IID_IDirectXFileDataReference
))
607 ERR("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
609 return E_NOINTERFACE
;
612 static ULONG WINAPI
IDirectXFileDataImpl_AddRef(IDirectXFileData
* iface
)
614 IDirectXFileDataImpl
*This
= (IDirectXFileDataImpl
*)iface
;
615 ULONG ref
= InterlockedIncrement(&This
->ref
);
617 TRACE("(%p/%p): AddRef from %d\n", iface
, This
, ref
- 1);
622 static ULONG WINAPI
IDirectXFileDataImpl_Release(IDirectXFileData
* iface
)
624 IDirectXFileDataImpl
*This
= (IDirectXFileDataImpl
*)iface
;
625 ULONG ref
= InterlockedDecrement(&This
->ref
);
627 TRACE("(%p/%p): ReleaseRef to %d\n", iface
, This
, ref
);
631 if (!This
->level
&& !This
->from_ref
)
633 HeapFree(GetProcessHeap(), 0, This
->pstrings
);
634 HeapFree(GetProcessHeap(), 0, This
->pobj
->pdata
);
635 HeapFree(GetProcessHeap(), 0, This
->pobj
);
637 HeapFree(GetProcessHeap(), 0, This
);
643 /*** IDirectXFileObject methods ***/
644 static HRESULT WINAPI
IDirectXFileDataImpl_GetName(IDirectXFileData
* iface
, LPSTR pstrNameBuf
, LPDWORD pdwBufLen
)
647 IDirectXFileDataImpl
*This
= (IDirectXFileDataImpl
*)iface
;
649 TRACE("(%p/%p)->(%p,%p)\n", This
, iface
, pstrNameBuf
, pdwBufLen
);
652 return DXFILEERR_BADVALUE
;
654 strcpy(pstrNameBuf
, This
->pobj
->name
);
659 static HRESULT WINAPI
IDirectXFileDataImpl_GetId(IDirectXFileData
* iface
, LPGUID pGuid
)
661 IDirectXFileDataImpl
*This
= (IDirectXFileDataImpl
*)iface
;
663 TRACE("(%p/%p)->(%p)\n", This
, iface
, pGuid
);
666 return DXFILEERR_BADVALUE
;
668 memcpy(pGuid
, &This
->pobj
->class_id
, 16);
673 /*** IDirectXFileData methods ***/
674 static HRESULT WINAPI
IDirectXFileDataImpl_GetData(IDirectXFileData
* iface
, LPCSTR szMember
, DWORD
* pcbSize
, void** ppvData
)
676 IDirectXFileDataImpl
*This
= (IDirectXFileDataImpl
*)iface
;
678 TRACE("(%p/%p)->(%s,%p,%p)\n", This
, iface
, szMember
, pcbSize
, ppvData
);
680 if (!pcbSize
|| !ppvData
)
681 return DXFILEERR_BADVALUE
;
685 FIXME("Specifying a member is not supported yet!\n");
686 return DXFILEERR_BADVALUE
;
689 *pcbSize
= This
->pobj
->size
;
690 *ppvData
= This
->pobj
->root
->pdata
+ This
->pobj
->pos_data
;
695 static HRESULT WINAPI
IDirectXFileDataImpl_GetType(IDirectXFileData
* iface
, const GUID
** pguid
)
697 IDirectXFileDataImpl
*This
= (IDirectXFileDataImpl
*)iface
;
700 TRACE("(%p/%p)->(%p)\n", This
, iface
, pguid
);
703 return DXFILEERR_BADVALUE
;
705 memcpy(&guid
, &This
->pobj
->type
, 16);
711 static HRESULT WINAPI
IDirectXFileDataImpl_GetNextObject(IDirectXFileData
* iface
, LPDIRECTXFILEOBJECT
* ppChildObj
)
714 IDirectXFileDataImpl
*This
= (IDirectXFileDataImpl
*)iface
;
716 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppChildObj
);
718 if (This
->cur_enum_object
>= This
->pobj
->nb_childs
)
719 return DXFILEERR_NOMOREOBJECTS
;
721 if (This
->from_ref
&& (This
->level
>= 1))
723 /* Only 2 levels can enumerated if the object is obtained from a reference */
724 return DXFILEERR_NOMOREOBJECTS
;
727 if (This
->pobj
->childs
[This
->cur_enum_object
]->binary
)
729 IDirectXFileBinaryImpl
*object
;
731 hr
= IDirectXFileBinaryImpl_Create(&object
);
735 *ppChildObj
= (LPDIRECTXFILEOBJECT
)object
;
737 else if (This
->pobj
->childs
[This
->cur_enum_object
]->ptarget
)
739 IDirectXFileDataReferenceImpl
*object
;
741 hr
= IDirectXFileDataReferenceImpl_Create(&object
);
745 object
->ptarget
= This
->pobj
->childs
[This
->cur_enum_object
++]->ptarget
;
747 *ppChildObj
= (LPDIRECTXFILEOBJECT
)object
;
751 IDirectXFileDataImpl
*object
;
753 hr
= IDirectXFileDataImpl_Create(&object
);
757 object
->pobj
= This
->pobj
->childs
[This
->cur_enum_object
++];
758 object
->cur_enum_object
= 0;
759 object
->from_ref
= This
->from_ref
;
760 object
->level
= This
->level
+ 1;
762 *ppChildObj
= (LPDIRECTXFILEOBJECT
)object
;
768 static HRESULT WINAPI
IDirectXFileDataImpl_AddDataObject(IDirectXFileData
* iface
, LPDIRECTXFILEDATA pDataObj
)
770 IDirectXFileDataImpl
*This
= (IDirectXFileDataImpl
*)iface
;
772 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, pDataObj
);
774 return DXFILEERR_BADVALUE
;
777 static HRESULT WINAPI
IDirectXFileDataImpl_AddDataReference(IDirectXFileData
* iface
, LPCSTR szRef
, const GUID
* pguidRef
)
779 IDirectXFileDataImpl
*This
= (IDirectXFileDataImpl
*)iface
;
781 FIXME("(%p/%p)->(%s,%p) stub!\n", This
, iface
, szRef
, pguidRef
);
783 return DXFILEERR_BADVALUE
;
786 static HRESULT WINAPI
IDirectXFileDataImpl_AddBinaryObject(IDirectXFileData
* iface
, LPCSTR szName
, const GUID
* pguid
, LPCSTR szMimeType
, LPVOID pvData
, DWORD cbSize
)
788 IDirectXFileDataImpl
*This
= (IDirectXFileDataImpl
*)iface
;
790 FIXME("(%p/%p)->(%s,%p,%s,%p,%d) stub!\n", This
, iface
, szName
, pguid
, szMimeType
, pvData
, cbSize
);
792 return DXFILEERR_BADVALUE
;
795 static const IDirectXFileDataVtbl IDirectXFileData_Vtbl
=
797 IDirectXFileDataImpl_QueryInterface
,
798 IDirectXFileDataImpl_AddRef
,
799 IDirectXFileDataImpl_Release
,
800 IDirectXFileDataImpl_GetName
,
801 IDirectXFileDataImpl_GetId
,
802 IDirectXFileDataImpl_GetData
,
803 IDirectXFileDataImpl_GetType
,
804 IDirectXFileDataImpl_GetNextObject
,
805 IDirectXFileDataImpl_AddDataObject
,
806 IDirectXFileDataImpl_AddDataReference
,
807 IDirectXFileDataImpl_AddBinaryObject
810 static HRESULT
IDirectXFileDataReferenceImpl_Create(IDirectXFileDataReferenceImpl
** ppObj
)
812 IDirectXFileDataReferenceImpl
* object
;
814 TRACE("(%p)\n", ppObj
);
816 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectXFileDataReferenceImpl
));
819 ERR("Out of memory\n");
820 return DXFILEERR_BADALLOC
;
823 object
->lpVtbl
.lpVtbl
= &IDirectXFileDataReference_Vtbl
;
831 /*** IUnknown methods ***/
832 static HRESULT WINAPI
IDirectXFileDataReferenceImpl_QueryInterface(IDirectXFileDataReference
* iface
, REFIID riid
, void** ppvObject
)
834 IDirectXFileDataReferenceImpl
*This
= (IDirectXFileDataReferenceImpl
*)iface
;
836 TRACE("(%p/%p)->(%s,%p)\n", iface
, This
, debugstr_guid(riid
), ppvObject
);
838 if (IsEqualGUID(riid
, &IID_IUnknown
)
839 || IsEqualGUID(riid
, &IID_IDirectXFileObject
)
840 || IsEqualGUID(riid
, &IID_IDirectXFileDataReference
))
842 IClassFactory_AddRef(iface
);
847 /* Do not print an error for interfaces that can be queried to retrieve the type of the object */
848 if (!IsEqualGUID(riid
, &IID_IDirectXFileData
)
849 && !IsEqualGUID(riid
, &IID_IDirectXFileBinary
))
850 ERR("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
852 return E_NOINTERFACE
;
855 static ULONG WINAPI
IDirectXFileDataReferenceImpl_AddRef(IDirectXFileDataReference
* iface
)
857 IDirectXFileDataReferenceImpl
*This
= (IDirectXFileDataReferenceImpl
*)iface
;
858 ULONG ref
= InterlockedIncrement(&This
->ref
);
860 TRACE("(%p/%p): AddRef from %d\n", iface
, This
, ref
- 1);
865 static ULONG WINAPI
IDirectXFileDataReferenceImpl_Release(IDirectXFileDataReference
* iface
)
867 IDirectXFileDataReferenceImpl
*This
= (IDirectXFileDataReferenceImpl
*)iface
;
868 ULONG ref
= InterlockedDecrement(&This
->ref
);
870 TRACE("(%p/%p): ReleaseRef to %d\n", iface
, This
, ref
);
873 HeapFree(GetProcessHeap(), 0, This
);
878 /*** IDirectXFileObject methods ***/
879 static HRESULT WINAPI
IDirectXFileDataReferenceImpl_GetName(IDirectXFileDataReference
* iface
, LPSTR pstrNameBuf
, LPDWORD pdwBufLen
)
881 IDirectXFileDataReferenceImpl
*This
= (IDirectXFileDataReferenceImpl
*)iface
;
883 TRACE("(%p/%p)->(%p,%p)\n", This
, iface
, pstrNameBuf
, pdwBufLen
);
886 return DXFILEERR_BADVALUE
;
888 strcpy(pstrNameBuf
, This
->ptarget
->name
);
890 return DXFILEERR_BADVALUE
;
893 static HRESULT WINAPI
IDirectXFileDataReferenceImpl_GetId(IDirectXFileDataReference
* iface
, LPGUID pGuid
)
895 IDirectXFileDataReferenceImpl
*This
= (IDirectXFileDataReferenceImpl
*)iface
;
897 TRACE("(%p/%p)->(%p)\n", This
, iface
, pGuid
);
900 return DXFILEERR_BADVALUE
;
902 memcpy(pGuid
, &This
->ptarget
->class_id
, 16);
907 /*** IDirectXFileDataReference ***/
908 static HRESULT WINAPI
IDirectXFileDataReferenceImpl_Resolve(IDirectXFileDataReference
* iface
, LPDIRECTXFILEDATA
* ppDataObj
)
910 IDirectXFileDataReferenceImpl
*This
= (IDirectXFileDataReferenceImpl
*)iface
;
911 IDirectXFileDataImpl
*object
;
914 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppDataObj
);
917 return DXFILEERR_BADVALUE
;
919 hr
= IDirectXFileDataImpl_Create(&object
);
923 object
->pobj
= This
->ptarget
;
924 object
->cur_enum_object
= 0;
926 object
->from_ref
= TRUE
;
928 *ppDataObj
= (LPDIRECTXFILEDATA
)object
;
933 static const IDirectXFileDataReferenceVtbl IDirectXFileDataReference_Vtbl
=
935 IDirectXFileDataReferenceImpl_QueryInterface
,
936 IDirectXFileDataReferenceImpl_AddRef
,
937 IDirectXFileDataReferenceImpl_Release
,
938 IDirectXFileDataReferenceImpl_GetName
,
939 IDirectXFileDataReferenceImpl_GetId
,
940 IDirectXFileDataReferenceImpl_Resolve
943 static HRESULT
IDirectXFileEnumObjectImpl_Create(IDirectXFileEnumObjectImpl
** ppObj
)
945 IDirectXFileEnumObjectImpl
* object
;
947 TRACE("(%p)\n", ppObj
);
949 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectXFileEnumObjectImpl
));
952 ERR("Out of memory\n");
953 return DXFILEERR_BADALLOC
;
956 object
->lpVtbl
.lpVtbl
= &IDirectXFileEnumObject_Vtbl
;
964 /*** IUnknown methods ***/
965 static HRESULT WINAPI
IDirectXFileEnumObjectImpl_QueryInterface(IDirectXFileEnumObject
* iface
, REFIID riid
, void** ppvObject
)
967 IDirectXFileEnumObjectImpl
*This
= (IDirectXFileEnumObjectImpl
*)iface
;
969 TRACE("(%p/%p)->(%s,%p)\n", iface
, This
, debugstr_guid(riid
), ppvObject
);
971 if (IsEqualGUID(riid
, &IID_IUnknown
)
972 || IsEqualGUID(riid
, &IID_IDirectXFileEnumObject
))
974 IClassFactory_AddRef(iface
);
979 ERR("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
980 return E_NOINTERFACE
;
983 static ULONG WINAPI
IDirectXFileEnumObjectImpl_AddRef(IDirectXFileEnumObject
* iface
)
985 IDirectXFileEnumObjectImpl
*This
= (IDirectXFileEnumObjectImpl
*)iface
;
986 ULONG ref
= InterlockedIncrement(&This
->ref
);
988 TRACE("(%p/%p): AddRef from %d\n", iface
, This
, ref
- 1);
993 static ULONG WINAPI
IDirectXFileEnumObjectImpl_Release(IDirectXFileEnumObject
* iface
)
995 IDirectXFileEnumObjectImpl
*This
= (IDirectXFileEnumObjectImpl
*)iface
;
996 ULONG ref
= InterlockedDecrement(&This
->ref
);
998 TRACE("(%p/%p): ReleaseRef to %d\n", iface
, This
, ref
);
1003 for (i
= 0; i
< This
->nb_xobjects
; i
++)
1004 IDirectXFileData_Release(This
->pRefObjects
[i
]);
1005 if (This
->source
== DXFILELOAD_FROMFILE
)
1007 UnmapViewOfFile(This
->buffer
);
1008 CloseHandle(This
->file_mapping
);
1009 CloseHandle(This
->hFile
);
1011 else if (This
->source
== DXFILELOAD_FROMRESOURCE
)
1012 FreeResource(This
->resource_data
);
1013 HeapFree(GetProcessHeap(), 0, This
);
1019 /*** IDirectXFileEnumObject methods ***/
1020 static HRESULT WINAPI
IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileEnumObject
* iface
, LPDIRECTXFILEDATA
* ppDataObj
)
1022 IDirectXFileEnumObjectImpl
*This
= (IDirectXFileEnumObjectImpl
*)iface
;
1023 IDirectXFileDataImpl
* object
;
1025 LPBYTE pstrings
= NULL
;
1027 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppDataObj
);
1029 if (This
->nb_xobjects
>= MAX_OBJECTS
)
1031 ERR("Too many objects\n");
1032 return DXFILEERR_NOMOREOBJECTS
;
1035 if (!This
->buf
.rem_bytes
)
1036 return DXFILEERR_NOMOREOBJECTS
;
1038 hr
= IDirectXFileDataImpl_Create(&object
);
1042 This
->buf
.pxo_globals
= This
->xobjects
;
1043 This
->buf
.nb_pxo_globals
= This
->nb_xobjects
;
1044 This
->buf
.cur_subobject
= 1;
1045 This
->buf
.level
= 0;
1047 This
->buf
.pxo_tab
= HeapAlloc(GetProcessHeap(), 0, sizeof(xobject
)*MAX_SUBOBJECTS
);
1048 if (!This
->buf
.pxo_tab
)
1050 ERR("Out of memory\n");
1051 hr
= DXFILEERR_BADALLOC
;
1054 This
->buf
.pxo
= This
->xobjects
[This
->nb_xobjects
] = This
->buf
.pxo_tab
;
1056 This
->buf
.pxo
->pdata
= This
->buf
.pdata
= NULL
;
1057 This
->buf
.capacity
= 0;
1058 This
->buf
.cur_pos_data
= 0;
1060 pstrings
= HeapAlloc(GetProcessHeap(), 0, MAX_STRINGS_BUFFER
);
1063 ERR("Out of memory\n");
1064 hr
= DXFILEERR_BADALLOC
;
1067 This
->buf
.cur_pstrings
= This
->buf
.pstrings
= object
->pstrings
= pstrings
;
1069 if (!parse_object(&This
->buf
))
1071 TRACE("Object is not correct\n");
1072 hr
= DXFILEERR_PARSEERROR
;
1076 This
->buf
.pxo
->nb_subobjects
= This
->buf
.cur_subobject
;
1077 if (This
->buf
.cur_subobject
> MAX_SUBOBJECTS
)
1079 FIXME("Too many suobjects %d\n", This
->buf
.cur_subobject
);
1080 hr
= DXFILEERR_BADALLOC
;
1084 object
->pstrings
= pstrings
;
1085 object
->pobj
= This
->buf
.pxo
;
1086 object
->cur_enum_object
= 0;
1088 object
->from_ref
= FALSE
;
1090 *ppDataObj
= (LPDIRECTXFILEDATA
)object
;
1092 /* Get a reference to created object */
1093 This
->pRefObjects
[This
->nb_xobjects
] = (LPDIRECTXFILEDATA
)object
;
1094 IDirectXFileData_AddRef(This
->pRefObjects
[This
->nb_xobjects
]);
1096 This
->nb_xobjects
++;
1102 HeapFree(GetProcessHeap(), 0, This
->buf
.pxo_tab
);
1103 HeapFree(GetProcessHeap(), 0, This
->buf
.pxo
->pdata
);
1104 HeapFree(GetProcessHeap(), 0, pstrings
);
1109 static HRESULT WINAPI
IDirectXFileEnumObjectImpl_GetDataObjectById(IDirectXFileEnumObject
* iface
, REFGUID rguid
, LPDIRECTXFILEDATA
* ppDataObj
)
1111 IDirectXFileEnumObjectImpl
*This
= (IDirectXFileEnumObjectImpl
*)iface
;
1113 FIXME("(%p/%p)->(%p,%p) stub!\n", This
, iface
, rguid
, ppDataObj
);
1115 return DXFILEERR_BADVALUE
;
1118 static HRESULT WINAPI
IDirectXFileEnumObjectImpl_GetDataObjectByName(IDirectXFileEnumObject
* iface
, LPCSTR szName
, LPDIRECTXFILEDATA
* ppDataObj
)
1120 IDirectXFileEnumObjectImpl
*This
= (IDirectXFileEnumObjectImpl
*)iface
;
1122 FIXME("(%p/%p)->(%s,%p) stub!\n", This
, iface
, szName
, ppDataObj
);
1124 return DXFILEERR_BADVALUE
;
1127 static const IDirectXFileEnumObjectVtbl IDirectXFileEnumObject_Vtbl
=
1129 IDirectXFileEnumObjectImpl_QueryInterface
,
1130 IDirectXFileEnumObjectImpl_AddRef
,
1131 IDirectXFileEnumObjectImpl_Release
,
1132 IDirectXFileEnumObjectImpl_GetNextDataObject
,
1133 IDirectXFileEnumObjectImpl_GetDataObjectById
,
1134 IDirectXFileEnumObjectImpl_GetDataObjectByName
1137 static HRESULT
IDirectXFileSaveObjectImpl_Create(IDirectXFileSaveObjectImpl
** ppObj
)
1139 IDirectXFileSaveObjectImpl
* object
;
1141 TRACE("(%p)\n", ppObj
);
1143 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectXFileSaveObjectImpl
));
1146 ERR("Out of memory\n");
1147 return DXFILEERR_BADALLOC
;
1150 object
->lpVtbl
.lpVtbl
= &IDirectXFileSaveObject_Vtbl
;
1158 /*** IUnknown methods ***/
1159 static HRESULT WINAPI
IDirectXFileSaveObjectImpl_QueryInterface(IDirectXFileSaveObject
* iface
, REFIID riid
, void** ppvObject
)
1161 IDirectXFileSaveObjectImpl
*This
= (IDirectXFileSaveObjectImpl
*)iface
;
1163 TRACE("(%p/%p)->(%s,%p)\n", iface
, This
, debugstr_guid(riid
), ppvObject
);
1165 if (IsEqualGUID(riid
, &IID_IUnknown
)
1166 || IsEqualGUID(riid
, &IID_IDirectXFileSaveObject
))
1168 IClassFactory_AddRef(iface
);
1173 ERR("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
1174 return E_NOINTERFACE
;
1177 static ULONG WINAPI
IDirectXFileSaveObjectImpl_AddRef(IDirectXFileSaveObject
* iface
)
1179 IDirectXFileSaveObjectImpl
*This
= (IDirectXFileSaveObjectImpl
*)iface
;
1180 ULONG ref
= InterlockedIncrement(&This
->ref
);
1182 TRACE("(%p/%p): AddRef from %d\n", iface
, This
, ref
- 1);
1187 static ULONG WINAPI
IDirectXFileSaveObjectImpl_Release(IDirectXFileSaveObject
* iface
)
1189 IDirectXFileSaveObjectImpl
*This
= (IDirectXFileSaveObjectImpl
*)iface
;
1190 ULONG ref
= InterlockedDecrement(&This
->ref
);
1192 TRACE("(%p/%p): ReleaseRef to %d\n", iface
, This
, ref
);
1195 HeapFree(GetProcessHeap(), 0, This
);
1200 static HRESULT WINAPI
IDirectXFileSaveObjectImpl_SaveTemplates(IDirectXFileSaveObject
* iface
, DWORD cTemplates
, const GUID
** ppguidTemplates
)
1202 IDirectXFileSaveObjectImpl
*This
= (IDirectXFileSaveObjectImpl
*)iface
;
1204 FIXME("(%p/%p)->(%d,%p) stub!\n", This
, iface
, cTemplates
, ppguidTemplates
);
1206 return DXFILEERR_BADVALUE
;
1209 static HRESULT WINAPI
IDirectXFileSaveObjectImpl_CreateDataObject(IDirectXFileSaveObject
* iface
, REFGUID rguidTemplate
, LPCSTR szName
, const GUID
* pguid
, DWORD cbSize
, LPVOID pvData
, LPDIRECTXFILEDATA
* ppDataObj
)
1211 IDirectXFileSaveObjectImpl
*This
= (IDirectXFileSaveObjectImpl
*)iface
;
1213 FIXME("(%p/%p)->(%p,%s,%p,%d,%p,%p) stub!\n", This
, iface
, rguidTemplate
, szName
, pguid
, cbSize
, pvData
, ppDataObj
);
1215 return DXFILEERR_BADVALUE
;
1218 static HRESULT WINAPI
IDirectXFileSaveObjectImpl_SaveData(IDirectXFileSaveObject
* iface
, LPDIRECTXFILEDATA ppDataObj
)
1220 IDirectXFileSaveObjectImpl
*This
= (IDirectXFileSaveObjectImpl
*)iface
;
1222 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, ppDataObj
);
1224 return DXFILEERR_BADVALUE
;
1227 static const IDirectXFileSaveObjectVtbl IDirectXFileSaveObject_Vtbl
=
1229 IDirectXFileSaveObjectImpl_QueryInterface
,
1230 IDirectXFileSaveObjectImpl_AddRef
,
1231 IDirectXFileSaveObjectImpl_Release
,
1232 IDirectXFileSaveObjectImpl_SaveTemplates
,
1233 IDirectXFileSaveObjectImpl_CreateDataObject
,
1234 IDirectXFileSaveObjectImpl_SaveData