widl: Pass a structure containing the parameters to NdrClientCall instead of accessin...
[wine/multimedia.git] / dlls / d3dxof / d3dxof.c
blob6717fc70d4d89f35bb95e497ec9743eda47c0e62
1 /*
2 * Implementation of DirectX File Interfaces
4 * Copyright 2004, 2008, 2010 Christian Costa
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/debug.h"
24 #define COBJMACROS
26 #include "winbase.h"
27 #include "wingdi.h"
29 #include "d3dxof_private.h"
30 #include "dxfile.h"
32 #include <stdio.h>
34 WINE_DEFAULT_DEBUG_CHANNEL(d3dxof);
36 #define MAKEFOUR(a,b,c,d) ((DWORD)a + ((DWORD)b << 8) + ((DWORD)c << 16) + ((DWORD)d << 24))
37 #define XOFFILE_FORMAT_MAGIC MAKEFOUR('x','o','f',' ')
38 #define XOFFILE_FORMAT_VERSION_302 MAKEFOUR('0','3','0','2')
39 #define XOFFILE_FORMAT_VERSION_303 MAKEFOUR('0','3','0','3')
40 #define XOFFILE_FORMAT_BINARY MAKEFOUR('b','i','n',' ')
41 #define XOFFILE_FORMAT_TEXT MAKEFOUR('t','x','t',' ')
42 #define XOFFILE_FORMAT_BINARY_MSZIP MAKEFOUR('b','z','i','p')
43 #define XOFFILE_FORMAT_TEXT_MSZIP MAKEFOUR('t','z','i','p')
44 #define XOFFILE_FORMAT_COMPRESSED MAKEFOUR('c','m','p',' ')
45 #define XOFFILE_FORMAT_FLOAT_BITS_32 MAKEFOUR('0','0','3','2')
46 #define XOFFILE_FORMAT_FLOAT_BITS_64 MAKEFOUR('0','0','6','4')
48 static const struct IDirectXFileVtbl IDirectXFile_Vtbl;
49 static const struct IDirectXFileBinaryVtbl IDirectXFileBinary_Vtbl;
50 static const struct IDirectXFileDataVtbl IDirectXFileData_Vtbl;
51 static const struct IDirectXFileDataReferenceVtbl IDirectXFileDataReference_Vtbl;
52 static const struct IDirectXFileEnumObjectVtbl IDirectXFileEnumObject_Vtbl;
53 static const struct IDirectXFileObjectVtbl IDirectXFileObject_Vtbl;
54 static const struct IDirectXFileSaveObjectVtbl IDirectXFileSaveObject_Vtbl;
56 static HRESULT IDirectXFileDataReferenceImpl_Create(IDirectXFileDataReferenceImpl** ppObj);
57 static HRESULT IDirectXFileEnumObjectImpl_Create(IDirectXFileEnumObjectImpl** ppObj);
58 static HRESULT IDirectXFileSaveObjectImpl_Create(IDirectXFileSaveObjectImpl** ppObj);
60 /* FOURCC to string conversion for debug messages */
61 static const char *debugstr_fourcc(DWORD fourcc)
63 if (!fourcc) return "'null'";
64 return wine_dbg_sprintf ("\'%c%c%c%c\'",
65 (char)(fourcc), (char)(fourcc >> 8),
66 (char)(fourcc >> 16), (char)(fourcc >> 24));
69 HRESULT IDirectXFileImpl_Create(IUnknown* pUnkOuter, LPVOID* ppObj)
71 IDirectXFileImpl* object;
73 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
75 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileImpl));
76 if (!object)
78 ERR("Out of memory\n");
79 return DXFILEERR_BADALLOC;
82 object->IDirectXFile_iface.lpVtbl = &IDirectXFile_Vtbl;
83 object->ref = 1;
85 *ppObj = &object->IDirectXFile_iface;
87 return S_OK;
90 static inline IDirectXFileImpl *impl_from_IDirectXFile(IDirectXFile *iface)
92 return CONTAINING_RECORD(iface, IDirectXFileImpl, IDirectXFile_iface);
95 /*** IUnknown methods ***/
96 static HRESULT WINAPI IDirectXFileImpl_QueryInterface(IDirectXFile* iface, REFIID riid, void** ppvObject)
98 IDirectXFileImpl *This = impl_from_IDirectXFile(iface);
100 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
102 if (IsEqualGUID(riid, &IID_IUnknown)
103 || IsEqualGUID(riid, &IID_IDirectXFile))
105 IUnknown_AddRef(iface);
106 *ppvObject = &This->IDirectXFile_iface;
107 return S_OK;
110 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
111 return E_NOINTERFACE;
114 static ULONG WINAPI IDirectXFileImpl_AddRef(IDirectXFile* iface)
116 IDirectXFileImpl *This = impl_from_IDirectXFile(iface);
117 ULONG ref = InterlockedIncrement(&This->ref);
119 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
121 return ref;
124 static ULONG WINAPI IDirectXFileImpl_Release(IDirectXFile* iface)
126 IDirectXFileImpl *This = impl_from_IDirectXFile(iface);
127 ULONG ref = InterlockedDecrement(&This->ref);
129 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
131 if (!ref)
132 HeapFree(GetProcessHeap(), 0, This);
134 return ref;
137 /*** IDirectXFile methods ***/
138 static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPVOID pvSource, DXFILELOADOPTIONS dwLoadOptions, LPDIRECTXFILEENUMOBJECT* ppEnumObj)
140 IDirectXFileImpl *This = impl_from_IDirectXFile(iface);
141 IDirectXFileEnumObjectImpl* object;
142 HRESULT hr;
143 DWORD* header;
144 HANDLE hFile = INVALID_HANDLE_VALUE;
145 HANDLE file_mapping = 0;
146 LPBYTE buffer = NULL;
147 HGLOBAL resource_data = 0;
148 LPBYTE decomp_buffer = NULL;
149 DWORD decomp_size = 0;
150 LPBYTE file_buffer;
151 DWORD file_size;
153 LPDXFILELOADMEMORY lpdxflm = NULL;
155 TRACE("(%p/%p)->(%p,%x,%p)\n", This, iface, pvSource, dwLoadOptions, ppEnumObj);
157 if (!ppEnumObj)
158 return DXFILEERR_BADVALUE;
160 /* Only lowest 4 bits are relevant in DXFILELOADOPTIONS */
161 dwLoadOptions &= 0xF;
163 if (dwLoadOptions == DXFILELOAD_FROMFILE)
165 TRACE("Open source file '%s'\n", (char*)pvSource);
167 hFile = CreateFileA(pvSource, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
168 if (hFile == INVALID_HANDLE_VALUE)
170 TRACE("File '%s' not found\n", (char*)pvSource);
171 return DXFILEERR_FILENOTFOUND;
174 file_size = GetFileSize(hFile, NULL);
176 file_mapping = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
177 if (!file_mapping)
179 hr = DXFILEERR_BADFILETYPE;
180 goto error;
183 buffer = MapViewOfFile(file_mapping, FILE_MAP_READ, 0, 0, 0);
184 if (!buffer)
186 hr = DXFILEERR_BADFILETYPE;
187 goto error;
189 file_buffer = buffer;
191 else if (dwLoadOptions == DXFILELOAD_FROMRESOURCE)
193 HRSRC resource_info;
194 LPDXFILELOADRESOURCE lpdxflr = pvSource;
196 TRACE("Source in resource (module = %p, name = %s, type = %s\n", lpdxflr->hModule, debugstr_a(lpdxflr->lpName), debugstr_a(lpdxflr->lpType));
198 resource_info = FindResourceA(lpdxflr->hModule, lpdxflr->lpName, lpdxflr->lpType);
199 if (!resource_info)
201 hr = DXFILEERR_RESOURCENOTFOUND;
202 goto error;
205 file_size = SizeofResource(lpdxflr->hModule, resource_info);
207 resource_data = LoadResource(lpdxflr->hModule, resource_info);
208 if (!resource_data)
210 hr = DXFILEERR_BADRESOURCE;
211 goto error;
214 file_buffer = LockResource(resource_data);
215 if (!file_buffer)
217 hr = DXFILEERR_BADRESOURCE;
218 goto error;
221 else if (dwLoadOptions == DXFILELOAD_FROMMEMORY)
223 lpdxflm = pvSource;
225 TRACE("Source in memory at %p with size %d\n", lpdxflm->lpMemory, lpdxflm->dSize);
227 file_buffer = lpdxflm->lpMemory;
228 file_size = lpdxflm->dSize;
230 else
232 FIXME("Source type %d is not handled yet\n", dwLoadOptions);
233 hr = DXFILEERR_NOTDONEYET;
234 goto error;
237 header = (DWORD*)file_buffer;
239 if (TRACE_ON(d3dxof))
241 char string[17];
242 memcpy(string, header, 16);
243 string[16] = 0;
244 TRACE("header = '%s'\n", string);
247 if (file_size < 16)
249 hr = DXFILEERR_BADFILETYPE;
250 goto error;
253 if (header[0] != XOFFILE_FORMAT_MAGIC)
255 hr = DXFILEERR_BADFILETYPE;
256 goto error;
259 if ((header[1] != XOFFILE_FORMAT_VERSION_302) && (header[1] != XOFFILE_FORMAT_VERSION_303))
261 hr = DXFILEERR_BADFILEVERSION;
262 goto error;
265 if ((header[2] != XOFFILE_FORMAT_BINARY) && (header[2] != XOFFILE_FORMAT_TEXT) &&
266 (header[2] != XOFFILE_FORMAT_BINARY_MSZIP) && (header[2] != XOFFILE_FORMAT_TEXT_MSZIP))
268 WARN("File type %s unknown\n", debugstr_fourcc(header[2]));
269 hr = DXFILEERR_BADFILETYPE;
270 goto error;
273 if ((header[2] == XOFFILE_FORMAT_BINARY_MSZIP) || (header[2] == XOFFILE_FORMAT_TEXT_MSZIP))
275 int err;
276 DWORD comp_size;
278 /* 0-15 -> xfile header, 16-17 -> decompressed size w/ header, 18-19 -> null,
279 20-21 -> decompressed size w/o header, 22-23 -> size of MSZIP compressed data,
280 24-xx -> compressed MSZIP data */
281 decomp_size = ((WORD*)file_buffer)[10];
282 comp_size = ((WORD*)file_buffer)[11];
284 TRACE("Compressed format %s detected: compressed_size = %x, decompressed_size = %x\n",
285 debugstr_fourcc(header[2]), comp_size, decomp_size);
287 decomp_buffer = HeapAlloc(GetProcessHeap(), 0, decomp_size);
288 if (!decomp_buffer)
290 ERR("Out of memory\n");
291 hr = DXFILEERR_BADALLOC;
292 goto error;
294 err = mszip_decompress(comp_size, decomp_size, (char*)file_buffer + 24, (char*)decomp_buffer);
295 if (err)
297 WARN("Error while decomrpessing mszip archive %d\n", err);
298 hr = DXFILEERR_BADALLOC;
299 goto error;
303 if ((header[3] != XOFFILE_FORMAT_FLOAT_BITS_32) && (header[3] != XOFFILE_FORMAT_FLOAT_BITS_64))
305 hr = DXFILEERR_BADFILEFLOATSIZE;
306 goto error;
309 TRACE("Header is correct\n");
311 hr = IDirectXFileEnumObjectImpl_Create(&object);
312 if (FAILED(hr))
313 goto error;
315 object->source = dwLoadOptions;
316 object->hFile = hFile;
317 object->file_mapping = file_mapping;
318 object->buffer = buffer;
319 object->decomp_buffer = decomp_buffer;
320 object->pDirectXFile = This;
321 object->buf.pdxf = This;
322 object->buf.txt = (header[2] == XOFFILE_FORMAT_TEXT) || (header[2] == XOFFILE_FORMAT_TEXT_MSZIP);
323 object->buf.token_present = FALSE;
325 TRACE("File size is %d bytes\n", file_size);
327 if (decomp_size)
329 /* Use decompressed data */
330 object->buf.buffer = decomp_buffer;
331 object->buf.rem_bytes = decomp_size;
333 else
335 /* Go to data after header */
336 object->buf.buffer = file_buffer + 16;
337 object->buf.rem_bytes = file_size - 16;
340 *ppEnumObj = &object->IDirectXFileEnumObject_iface;
342 while (object->buf.rem_bytes && is_template_available(&object->buf))
344 if (!parse_template(&object->buf))
346 WARN("Template is not correct\n");
347 hr = DXFILEERR_BADVALUE;
348 goto error;
350 else
352 TRACE("Template successfully parsed:\n");
353 if (TRACE_ON(d3dxof))
354 dump_template(This->xtemplates, &This->xtemplates[This->nb_xtemplates - 1]);
358 if (TRACE_ON(d3dxof))
360 int i;
361 TRACE("Registered templates (%d):\n", This->nb_xtemplates);
362 for (i = 0; i < This->nb_xtemplates; i++)
363 DPRINTF("%s - %s\n", This->xtemplates[i].name, debugstr_guid(&This->xtemplates[i].class_id));
366 return DXFILE_OK;
368 error:
369 if (buffer)
370 UnmapViewOfFile(buffer);
371 if (file_mapping)
372 CloseHandle(file_mapping);
373 if (hFile != INVALID_HANDLE_VALUE)
374 CloseHandle(hFile);
375 if (resource_data)
376 FreeResource(resource_data);
377 HeapFree(GetProcessHeap(), 0, decomp_buffer);
378 *ppEnumObj = NULL;
380 return hr;
383 static HRESULT WINAPI IDirectXFileImpl_CreateSaveObject(IDirectXFile* iface, LPCSTR szFileName, DXFILEFORMAT dwFileFormat, LPDIRECTXFILESAVEOBJECT* ppSaveObj)
385 IDirectXFileImpl *This = impl_from_IDirectXFile(iface);
386 IDirectXFileSaveObjectImpl *object;
387 HRESULT hr;
389 FIXME("(%p/%p)->(%s,%x,%p) partial stub!\n", This, iface, szFileName, dwFileFormat, ppSaveObj);
391 if (!szFileName || !ppSaveObj)
392 return E_POINTER;
394 hr = IDirectXFileSaveObjectImpl_Create(&object);
395 if (SUCCEEDED(hr))
396 *ppSaveObj = &object->IDirectXFileSaveObject_iface;
397 return hr;
400 static HRESULT WINAPI IDirectXFileImpl_RegisterTemplates(IDirectXFile* iface, LPVOID pvData, DWORD cbSize)
402 IDirectXFileImpl *This = impl_from_IDirectXFile(iface);
403 DWORD token_header;
404 parse_buffer buf;
405 LPBYTE decomp_buffer = NULL;
406 DWORD decomp_size = 0;
408 buf.buffer = pvData;
409 buf.rem_bytes = cbSize;
410 buf.txt = FALSE;
411 buf.token_present = FALSE;
412 buf.pdxf = This;
414 TRACE("(%p/%p)->(%p,%d)\n", This, iface, pvData, cbSize);
416 if (!pvData)
417 return DXFILEERR_BADVALUE;
419 if (cbSize < 16)
420 return DXFILEERR_BADFILETYPE;
422 if (TRACE_ON(d3dxof))
424 char string[17];
425 memcpy(string, pvData, 16);
426 string[16] = 0;
427 TRACE("header = '%s'\n", string);
430 read_bytes(&buf, &token_header, 4);
432 if (token_header != XOFFILE_FORMAT_MAGIC)
433 return DXFILEERR_BADFILETYPE;
435 read_bytes(&buf, &token_header, 4);
437 if ((token_header != XOFFILE_FORMAT_VERSION_302) && (token_header != XOFFILE_FORMAT_VERSION_303))
438 return DXFILEERR_BADFILEVERSION;
440 read_bytes(&buf, &token_header, 4);
442 if ((token_header != XOFFILE_FORMAT_BINARY) && (token_header != XOFFILE_FORMAT_TEXT) &&
443 (token_header != XOFFILE_FORMAT_BINARY_MSZIP) && (token_header != XOFFILE_FORMAT_TEXT_MSZIP))
445 WARN("File type %s unknown\n", debugstr_fourcc(token_header));
446 return DXFILEERR_BADFILETYPE;
449 if ((token_header == XOFFILE_FORMAT_BINARY_MSZIP) || (token_header == XOFFILE_FORMAT_TEXT_MSZIP))
451 int err;
452 DWORD comp_size;
454 /* 0-15 -> xfile header, 16-17 -> decompressed size w/ header, 18-19 -> null,
455 20-21 -> decompressed size w/o header, 22-23 -> size of MSZIP compressed data,
456 24-xx -> compressed MSZIP data */
457 decomp_size = ((WORD*)pvData)[10];
458 comp_size = ((WORD*)pvData)[11];
460 TRACE("Compressed format %s detected: compressed_size = %x, decompressed_size = %x\n",
461 debugstr_fourcc(token_header), comp_size, decomp_size);
463 decomp_buffer = HeapAlloc(GetProcessHeap(), 0, decomp_size);
464 if (!decomp_buffer)
466 ERR("Out of memory\n");
467 return DXFILEERR_BADALLOC;
469 err = mszip_decompress(comp_size, decomp_size, (char*)pvData + 24, (char*)decomp_buffer);
470 if (err)
472 WARN("Error while decomrpessing mszip archive %d\n", err);
473 HeapFree(GetProcessHeap(), 0, decomp_buffer);
474 return DXFILEERR_BADALLOC;
478 if ((token_header == XOFFILE_FORMAT_TEXT) || (token_header == XOFFILE_FORMAT_TEXT_MSZIP))
479 buf.txt = TRUE;
481 read_bytes(&buf, &token_header, 4);
483 if ((token_header != XOFFILE_FORMAT_FLOAT_BITS_32) && (token_header != XOFFILE_FORMAT_FLOAT_BITS_64))
484 return DXFILEERR_BADFILEFLOATSIZE;
486 TRACE("Header is correct\n");
488 if (decomp_size)
490 buf.buffer = decomp_buffer;
491 buf.rem_bytes = decomp_size;
494 while (buf.rem_bytes && is_template_available(&buf))
496 if (!parse_template(&buf))
498 WARN("Template is not correct\n");
499 return DXFILEERR_BADVALUE;
501 else
503 TRACE("Template successfully parsed:\n");
504 if (TRACE_ON(d3dxof))
505 dump_template(This->xtemplates, &This->xtemplates[This->nb_xtemplates - 1]);
509 if (TRACE_ON(d3dxof))
511 int i;
512 TRACE("Registered templates (%d):\n", This->nb_xtemplates);
513 for (i = 0; i < This->nb_xtemplates; i++)
514 DPRINTF("%s - %s\n", This->xtemplates[i].name, debugstr_guid(&This->xtemplates[i].class_id));
517 HeapFree(GetProcessHeap(), 0, decomp_buffer);
519 return DXFILE_OK;
522 static const IDirectXFileVtbl IDirectXFile_Vtbl =
524 IDirectXFileImpl_QueryInterface,
525 IDirectXFileImpl_AddRef,
526 IDirectXFileImpl_Release,
527 IDirectXFileImpl_CreateEnumObject,
528 IDirectXFileImpl_CreateSaveObject,
529 IDirectXFileImpl_RegisterTemplates
532 static HRESULT IDirectXFileBinaryImpl_Create(IDirectXFileBinaryImpl** ppObj)
534 IDirectXFileBinaryImpl* object;
536 TRACE("(%p)\n", ppObj);
538 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileBinaryImpl));
539 if (!object)
541 ERR("Out of memory\n");
542 return DXFILEERR_BADALLOC;
545 object->IDirectXFileBinary_iface.lpVtbl = &IDirectXFileBinary_Vtbl;
546 object->ref = 1;
548 *ppObj = object;
550 return DXFILE_OK;
553 static inline IDirectXFileBinaryImpl *impl_from_IDirectXFileBinary(IDirectXFileBinary *iface)
555 return CONTAINING_RECORD(iface, IDirectXFileBinaryImpl, IDirectXFileBinary_iface);
558 /*** IUnknown methods ***/
559 static HRESULT WINAPI IDirectXFileBinaryImpl_QueryInterface(IDirectXFileBinary* iface, REFIID riid, void** ppvObject)
561 IDirectXFileBinaryImpl *This = impl_from_IDirectXFileBinary(iface);
563 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
565 if (IsEqualGUID(riid, &IID_IUnknown)
566 || IsEqualGUID(riid, &IID_IDirectXFileObject)
567 || IsEqualGUID(riid, &IID_IDirectXFileBinary))
569 IUnknown_AddRef(iface);
570 *ppvObject = &This->IDirectXFileBinary_iface;
571 return S_OK;
574 /* Do not print an error for interfaces that can be queried to retrieve the type of the object */
575 if (!IsEqualGUID(riid, &IID_IDirectXFileData)
576 && !IsEqualGUID(riid, &IID_IDirectXFileDataReference))
577 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
579 return E_NOINTERFACE;
582 static ULONG WINAPI IDirectXFileBinaryImpl_AddRef(IDirectXFileBinary* iface)
584 IDirectXFileBinaryImpl *This = impl_from_IDirectXFileBinary(iface);
585 ULONG ref = InterlockedIncrement(&This->ref);
587 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
589 return ref;
592 static ULONG WINAPI IDirectXFileBinaryImpl_Release(IDirectXFileBinary* iface)
594 IDirectXFileBinaryImpl *This = impl_from_IDirectXFileBinary(iface);
595 ULONG ref = InterlockedDecrement(&This->ref);
597 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
599 if (!ref)
600 HeapFree(GetProcessHeap(), 0, This);
602 return ref;
605 /*** IDirectXFileObject methods ***/
606 static HRESULT WINAPI IDirectXFileBinaryImpl_GetName(IDirectXFileBinary* iface, LPSTR pstrNameBuf, LPDWORD pdwBufLen)
609 IDirectXFileBinaryImpl *This = impl_from_IDirectXFileBinary(iface);
611 FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, pstrNameBuf, pdwBufLen);
613 return DXFILEERR_BADVALUE;
616 static HRESULT WINAPI IDirectXFileBinaryImpl_GetId(IDirectXFileBinary* iface, LPGUID pGuid)
618 IDirectXFileBinaryImpl *This = impl_from_IDirectXFileBinary(iface);
620 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pGuid);
622 return DXFILEERR_BADVALUE;
625 /*** IDirectXFileBinary methods ***/
626 static HRESULT WINAPI IDirectXFileBinaryImpl_GetSize(IDirectXFileBinary* iface, DWORD* pcbSize)
628 IDirectXFileBinaryImpl *This = impl_from_IDirectXFileBinary(iface);
630 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pcbSize);
632 return DXFILEERR_BADVALUE;
635 static HRESULT WINAPI IDirectXFileBinaryImpl_GetMimeType(IDirectXFileBinary* iface, LPCSTR* pszMimeType)
637 IDirectXFileBinaryImpl *This = impl_from_IDirectXFileBinary(iface);
639 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pszMimeType);
641 return DXFILEERR_BADVALUE;
644 static HRESULT WINAPI IDirectXFileBinaryImpl_Read(IDirectXFileBinary* iface, LPVOID pvData, DWORD cbSize, LPDWORD pcbRead)
646 IDirectXFileBinaryImpl *This = impl_from_IDirectXFileBinary(iface);
648 FIXME("(%p/%p)->(%p, %d, %p) stub!\n", This, iface, pvData, cbSize, pcbRead);
650 return DXFILEERR_BADVALUE;
653 static const IDirectXFileBinaryVtbl IDirectXFileBinary_Vtbl =
655 IDirectXFileBinaryImpl_QueryInterface,
656 IDirectXFileBinaryImpl_AddRef,
657 IDirectXFileBinaryImpl_Release,
658 IDirectXFileBinaryImpl_GetName,
659 IDirectXFileBinaryImpl_GetId,
660 IDirectXFileBinaryImpl_GetSize,
661 IDirectXFileBinaryImpl_GetMimeType,
662 IDirectXFileBinaryImpl_Read
665 static HRESULT IDirectXFileDataImpl_Create(IDirectXFileDataImpl** ppObj)
667 IDirectXFileDataImpl* object;
669 TRACE("(%p)\n", ppObj);
671 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileDataImpl));
672 if (!object)
674 ERR("Out of memory\n");
675 return DXFILEERR_BADALLOC;
678 object->IDirectXFileData_iface.lpVtbl = &IDirectXFileData_Vtbl;
679 object->ref = 1;
681 *ppObj = object;
683 return S_OK;
686 static inline IDirectXFileDataImpl *impl_from_IDirectXFileData(IDirectXFileData *iface)
688 return CONTAINING_RECORD(iface, IDirectXFileDataImpl, IDirectXFileData_iface);
691 /*** IUnknown methods ***/
692 static HRESULT WINAPI IDirectXFileDataImpl_QueryInterface(IDirectXFileData* iface, REFIID riid, void** ppvObject)
694 IDirectXFileDataImpl *This = impl_from_IDirectXFileData(iface);
696 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
698 if (IsEqualGUID(riid, &IID_IUnknown)
699 || IsEqualGUID(riid, &IID_IDirectXFileObject)
700 || IsEqualGUID(riid, &IID_IDirectXFileData))
702 IUnknown_AddRef(iface);
703 *ppvObject = &This->IDirectXFileData_iface;
704 return S_OK;
707 /* Do not print an error for interfaces that can be queried to retrieve the type of the object */
708 if (!IsEqualGUID(riid, &IID_IDirectXFileBinary)
709 && !IsEqualGUID(riid, &IID_IDirectXFileDataReference))
710 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
712 return E_NOINTERFACE;
715 static ULONG WINAPI IDirectXFileDataImpl_AddRef(IDirectXFileData* iface)
717 IDirectXFileDataImpl *This = impl_from_IDirectXFileData(iface);
718 ULONG ref = InterlockedIncrement(&This->ref);
720 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
722 return ref;
725 static ULONG WINAPI IDirectXFileDataImpl_Release(IDirectXFileData* iface)
727 IDirectXFileDataImpl *This = impl_from_IDirectXFileData(iface);
728 ULONG ref = InterlockedDecrement(&This->ref);
730 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
732 if (!ref)
734 if (!This->level && !This->from_ref)
736 HeapFree(GetProcessHeap(), 0, This->pstrings);
737 HeapFree(GetProcessHeap(), 0, This->pobj->pdata);
738 HeapFree(GetProcessHeap(), 0, This->pobj);
740 HeapFree(GetProcessHeap(), 0, This);
743 return ref;
746 /*** IDirectXFileObject methods ***/
747 static HRESULT WINAPI IDirectXFileDataImpl_GetName(IDirectXFileData* iface, LPSTR pstrNameBuf, LPDWORD pdwBufLen)
749 IDirectXFileDataImpl *This = impl_from_IDirectXFileData(iface);
750 DWORD len;
752 TRACE("(%p/%p)->(%p,%p)\n", This, iface, pstrNameBuf, pdwBufLen);
754 if (!pdwBufLen)
755 return DXFILEERR_BADVALUE;
757 len = strlen(This->pobj->name);
758 if (len)
759 len++;
761 if (pstrNameBuf) {
762 if (*pdwBufLen < len)
763 return DXFILEERR_BADVALUE;
764 CopyMemory(pstrNameBuf, This->pobj->name, len);
766 *pdwBufLen = len;
768 return DXFILE_OK;
771 static HRESULT WINAPI IDirectXFileDataImpl_GetId(IDirectXFileData* iface, LPGUID pGuid)
773 IDirectXFileDataImpl *This = impl_from_IDirectXFileData(iface);
775 TRACE("(%p/%p)->(%p)\n", This, iface, pGuid);
777 if (!pGuid)
778 return DXFILEERR_BADVALUE;
780 memcpy(pGuid, &This->pobj->class_id, 16);
782 return DXFILE_OK;
785 /*** IDirectXFileData methods ***/
786 static HRESULT WINAPI IDirectXFileDataImpl_GetData(IDirectXFileData* iface, LPCSTR szMember, DWORD* pcbSize, void** ppvData)
788 IDirectXFileDataImpl *This = impl_from_IDirectXFileData(iface);
790 TRACE("(%p/%p)->(%s,%p,%p)\n", This, iface, szMember, pcbSize, ppvData);
792 if (!pcbSize || !ppvData)
793 return DXFILEERR_BADVALUE;
795 if (szMember)
797 FIXME("Specifying a member is not supported yet!\n");
798 return DXFILEERR_BADVALUE;
801 *pcbSize = This->pobj->size;
802 *ppvData = This->pobj->root->pdata + This->pobj->pos_data;
804 return DXFILE_OK;
807 static HRESULT WINAPI IDirectXFileDataImpl_GetType(IDirectXFileData* iface, const GUID** pguid)
809 IDirectXFileDataImpl *This = impl_from_IDirectXFileData(iface);
810 static GUID guid;
812 TRACE("(%p/%p)->(%p)\n", This, iface, pguid);
814 if (!pguid)
815 return DXFILEERR_BADVALUE;
817 memcpy(&guid, &This->pobj->type, 16);
818 *pguid = &guid;
820 return DXFILE_OK;
823 static HRESULT WINAPI IDirectXFileDataImpl_GetNextObject(IDirectXFileData* iface, LPDIRECTXFILEOBJECT* ppChildObj)
825 HRESULT hr;
826 IDirectXFileDataImpl *This = impl_from_IDirectXFileData(iface);
828 TRACE("(%p/%p)->(%p)\n", This, iface, ppChildObj);
830 if (This->cur_enum_object >= This->pobj->nb_childs)
831 return DXFILEERR_NOMOREOBJECTS;
833 if (This->from_ref && (This->level >= 1))
835 /* Only 2 levels can be enumerated if the object is obtained from a reference */
836 return DXFILEERR_NOMOREOBJECTS;
839 if (This->pobj->childs[This->cur_enum_object]->binary)
841 IDirectXFileBinaryImpl *object;
843 hr = IDirectXFileBinaryImpl_Create(&object);
844 if (FAILED(hr))
845 return hr;
847 *ppChildObj = (LPDIRECTXFILEOBJECT)&object->IDirectXFileBinary_iface;
849 else if (This->pobj->childs[This->cur_enum_object]->ptarget)
851 IDirectXFileDataReferenceImpl *object;
853 hr = IDirectXFileDataReferenceImpl_Create(&object);
854 if (FAILED(hr))
855 return hr;
857 object->ptarget = This->pobj->childs[This->cur_enum_object++]->ptarget;
859 *ppChildObj = (LPDIRECTXFILEOBJECT)&object->IDirectXFileDataReference_iface;
861 else
863 IDirectXFileDataImpl *object;
865 hr = IDirectXFileDataImpl_Create(&object);
866 if (FAILED(hr))
867 return hr;
869 object->pobj = This->pobj->childs[This->cur_enum_object++];
870 object->cur_enum_object = 0;
871 object->from_ref = This->from_ref;
872 object->level = This->level + 1;
874 *ppChildObj = (LPDIRECTXFILEOBJECT)&object->IDirectXFileData_iface;
877 return DXFILE_OK;
880 static HRESULT WINAPI IDirectXFileDataImpl_AddDataObject(IDirectXFileData* iface, LPDIRECTXFILEDATA pDataObj)
882 IDirectXFileDataImpl *This = impl_from_IDirectXFileData(iface);
884 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pDataObj);
886 return DXFILEERR_BADVALUE;
889 static HRESULT WINAPI IDirectXFileDataImpl_AddDataReference(IDirectXFileData* iface, LPCSTR szRef, const GUID* pguidRef)
891 IDirectXFileDataImpl *This = impl_from_IDirectXFileData(iface);
893 FIXME("(%p/%p)->(%s,%p) stub!\n", This, iface, szRef, pguidRef);
895 return DXFILEERR_BADVALUE;
898 static HRESULT WINAPI IDirectXFileDataImpl_AddBinaryObject(IDirectXFileData* iface, LPCSTR szName, const GUID* pguid, LPCSTR szMimeType, LPVOID pvData, DWORD cbSize)
900 IDirectXFileDataImpl *This = impl_from_IDirectXFileData(iface);
902 FIXME("(%p/%p)->(%s,%p,%s,%p,%d) stub!\n", This, iface, szName, pguid, szMimeType, pvData, cbSize);
904 return DXFILEERR_BADVALUE;
907 static const IDirectXFileDataVtbl IDirectXFileData_Vtbl =
909 IDirectXFileDataImpl_QueryInterface,
910 IDirectXFileDataImpl_AddRef,
911 IDirectXFileDataImpl_Release,
912 IDirectXFileDataImpl_GetName,
913 IDirectXFileDataImpl_GetId,
914 IDirectXFileDataImpl_GetData,
915 IDirectXFileDataImpl_GetType,
916 IDirectXFileDataImpl_GetNextObject,
917 IDirectXFileDataImpl_AddDataObject,
918 IDirectXFileDataImpl_AddDataReference,
919 IDirectXFileDataImpl_AddBinaryObject
922 static HRESULT IDirectXFileDataReferenceImpl_Create(IDirectXFileDataReferenceImpl** ppObj)
924 IDirectXFileDataReferenceImpl* object;
926 TRACE("(%p)\n", ppObj);
928 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileDataReferenceImpl));
929 if (!object)
931 ERR("Out of memory\n");
932 return DXFILEERR_BADALLOC;
935 object->IDirectXFileDataReference_iface.lpVtbl = &IDirectXFileDataReference_Vtbl;
936 object->ref = 1;
938 *ppObj = object;
940 return S_OK;
943 static inline IDirectXFileDataReferenceImpl *impl_from_IDirectXFileDataReference(IDirectXFileDataReference *iface)
945 return CONTAINING_RECORD(iface, IDirectXFileDataReferenceImpl, IDirectXFileDataReference_iface);
948 /*** IUnknown methods ***/
949 static HRESULT WINAPI IDirectXFileDataReferenceImpl_QueryInterface(IDirectXFileDataReference* iface, REFIID riid, void** ppvObject)
951 IDirectXFileDataReferenceImpl *This = impl_from_IDirectXFileDataReference(iface);
953 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
955 if (IsEqualGUID(riid, &IID_IUnknown)
956 || IsEqualGUID(riid, &IID_IDirectXFileObject)
957 || IsEqualGUID(riid, &IID_IDirectXFileDataReference))
959 IUnknown_AddRef(iface);
960 *ppvObject = &This->IDirectXFileDataReference_iface;
961 return S_OK;
964 /* Do not print an error for interfaces that can be queried to retrieve the type of the object */
965 if (!IsEqualGUID(riid, &IID_IDirectXFileData)
966 && !IsEqualGUID(riid, &IID_IDirectXFileBinary))
967 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
969 return E_NOINTERFACE;
972 static ULONG WINAPI IDirectXFileDataReferenceImpl_AddRef(IDirectXFileDataReference* iface)
974 IDirectXFileDataReferenceImpl *This = impl_from_IDirectXFileDataReference(iface);
975 ULONG ref = InterlockedIncrement(&This->ref);
977 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
979 return ref;
982 static ULONG WINAPI IDirectXFileDataReferenceImpl_Release(IDirectXFileDataReference* iface)
984 IDirectXFileDataReferenceImpl *This = impl_from_IDirectXFileDataReference(iface);
985 ULONG ref = InterlockedDecrement(&This->ref);
987 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
989 if (!ref)
990 HeapFree(GetProcessHeap(), 0, This);
992 return ref;
995 /*** IDirectXFileObject methods ***/
996 static HRESULT WINAPI IDirectXFileDataReferenceImpl_GetName(IDirectXFileDataReference* iface, LPSTR pstrNameBuf, LPDWORD pdwBufLen)
998 IDirectXFileDataReferenceImpl *This = impl_from_IDirectXFileDataReference(iface);
999 DWORD len;
1001 TRACE("(%p/%p)->(%p,%p)\n", This, iface, pstrNameBuf, pdwBufLen);
1003 if (!pdwBufLen)
1004 return DXFILEERR_BADVALUE;
1006 len = strlen(This->ptarget->name);
1007 if (len)
1008 len++;
1010 if (pstrNameBuf) {
1011 if (*pdwBufLen < len)
1012 return DXFILEERR_BADVALUE;
1013 CopyMemory(pstrNameBuf, This->ptarget->name, len);
1015 *pdwBufLen = len;
1017 return DXFILE_OK;
1020 static HRESULT WINAPI IDirectXFileDataReferenceImpl_GetId(IDirectXFileDataReference* iface, LPGUID pGuid)
1022 IDirectXFileDataReferenceImpl *This = impl_from_IDirectXFileDataReference(iface);
1024 TRACE("(%p/%p)->(%p)\n", This, iface, pGuid);
1026 if (!pGuid)
1027 return DXFILEERR_BADVALUE;
1029 memcpy(pGuid, &This->ptarget->class_id, 16);
1031 return DXFILE_OK;
1034 /*** IDirectXFileDataReference ***/
1035 static HRESULT WINAPI IDirectXFileDataReferenceImpl_Resolve(IDirectXFileDataReference* iface, LPDIRECTXFILEDATA* ppDataObj)
1037 IDirectXFileDataReferenceImpl *This = impl_from_IDirectXFileDataReference(iface);
1038 IDirectXFileDataImpl *object;
1039 HRESULT hr;
1041 TRACE("(%p/%p)->(%p)\n", This, iface, ppDataObj);
1043 if (!ppDataObj)
1044 return DXFILEERR_BADVALUE;
1046 hr = IDirectXFileDataImpl_Create(&object);
1047 if (FAILED(hr))
1048 return hr;
1050 object->pobj = This->ptarget;
1051 object->cur_enum_object = 0;
1052 object->level = 0;
1053 object->from_ref = TRUE;
1055 *ppDataObj = (LPDIRECTXFILEDATA)object;
1057 return DXFILE_OK;
1060 static const IDirectXFileDataReferenceVtbl IDirectXFileDataReference_Vtbl =
1062 IDirectXFileDataReferenceImpl_QueryInterface,
1063 IDirectXFileDataReferenceImpl_AddRef,
1064 IDirectXFileDataReferenceImpl_Release,
1065 IDirectXFileDataReferenceImpl_GetName,
1066 IDirectXFileDataReferenceImpl_GetId,
1067 IDirectXFileDataReferenceImpl_Resolve
1070 static HRESULT IDirectXFileEnumObjectImpl_Create(IDirectXFileEnumObjectImpl** ppObj)
1072 IDirectXFileEnumObjectImpl* object;
1074 TRACE("(%p)\n", ppObj);
1076 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileEnumObjectImpl));
1077 if (!object)
1079 ERR("Out of memory\n");
1080 return DXFILEERR_BADALLOC;
1083 object->IDirectXFileEnumObject_iface.lpVtbl = &IDirectXFileEnumObject_Vtbl;
1084 object->ref = 1;
1086 *ppObj = object;
1088 return S_OK;
1091 static inline IDirectXFileEnumObjectImpl *impl_from_IDirectXFileEnumObject(IDirectXFileEnumObject *iface)
1093 return CONTAINING_RECORD(iface, IDirectXFileEnumObjectImpl, IDirectXFileEnumObject_iface);
1096 /*** IUnknown methods ***/
1097 static HRESULT WINAPI IDirectXFileEnumObjectImpl_QueryInterface(IDirectXFileEnumObject* iface, REFIID riid, void** ppvObject)
1099 IDirectXFileEnumObjectImpl *This = impl_from_IDirectXFileEnumObject(iface);
1101 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
1103 if (IsEqualGUID(riid, &IID_IUnknown)
1104 || IsEqualGUID(riid, &IID_IDirectXFileEnumObject))
1106 IUnknown_AddRef(iface);
1107 *ppvObject = &This->IDirectXFileEnumObject_iface;
1108 return S_OK;
1111 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1112 return E_NOINTERFACE;
1115 static ULONG WINAPI IDirectXFileEnumObjectImpl_AddRef(IDirectXFileEnumObject* iface)
1117 IDirectXFileEnumObjectImpl *This = impl_from_IDirectXFileEnumObject(iface);
1118 ULONG ref = InterlockedIncrement(&This->ref);
1120 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
1122 return ref;
1125 static ULONG WINAPI IDirectXFileEnumObjectImpl_Release(IDirectXFileEnumObject* iface)
1127 IDirectXFileEnumObjectImpl *This = impl_from_IDirectXFileEnumObject(iface);
1128 ULONG ref = InterlockedDecrement(&This->ref);
1130 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
1132 if (!ref)
1134 int i;
1135 for (i = 0; i < This->nb_xobjects; i++)
1136 IDirectXFileData_Release(This->pRefObjects[i]);
1137 if (This->source == DXFILELOAD_FROMFILE)
1139 UnmapViewOfFile(This->buffer);
1140 CloseHandle(This->file_mapping);
1141 CloseHandle(This->hFile);
1143 else if (This->source == DXFILELOAD_FROMRESOURCE)
1144 FreeResource(This->resource_data);
1145 HeapFree(GetProcessHeap(), 0, This->decomp_buffer);
1146 HeapFree(GetProcessHeap(), 0, This);
1149 return ref;
1152 /*** IDirectXFileEnumObject methods ***/
1153 static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileEnumObject* iface, LPDIRECTXFILEDATA* ppDataObj)
1155 IDirectXFileEnumObjectImpl *This = impl_from_IDirectXFileEnumObject(iface);
1156 IDirectXFileDataImpl* object;
1157 HRESULT hr;
1158 LPBYTE pstrings = NULL;
1160 TRACE("(%p/%p)->(%p)\n", This, iface, ppDataObj);
1162 if (This->nb_xobjects >= MAX_OBJECTS)
1164 ERR("Too many objects\n");
1165 return DXFILEERR_NOMOREOBJECTS;
1168 /* Check if there are templates defined before the object */
1169 while (This->buf.rem_bytes && is_template_available(&This->buf))
1171 if (!parse_template(&This->buf))
1173 WARN("Template is not correct\n");
1174 hr = DXFILEERR_BADVALUE;
1175 goto error;
1177 else
1179 TRACE("Template successfully parsed:\n");
1180 if (TRACE_ON(d3dxof))
1181 dump_template(This->pDirectXFile->xtemplates, &This->pDirectXFile->xtemplates[This->pDirectXFile->nb_xtemplates - 1]);
1185 if (!This->buf.rem_bytes)
1186 return DXFILEERR_NOMOREOBJECTS;
1188 hr = IDirectXFileDataImpl_Create(&object);
1189 if (FAILED(hr))
1190 return hr;
1192 This->buf.pxo_globals = This->xobjects;
1193 This->buf.nb_pxo_globals = This->nb_xobjects;
1194 This->buf.level = 0;
1196 This->buf.pxo_tab = HeapAlloc(GetProcessHeap(), 0, sizeof(xobject)*MAX_SUBOBJECTS);
1197 if (!This->buf.pxo_tab)
1199 ERR("Out of memory\n");
1200 hr = DXFILEERR_BADALLOC;
1201 goto error;
1203 This->buf.pxo = This->xobjects[This->nb_xobjects] = This->buf.pxo_tab;
1205 This->buf.pxo->pdata = This->buf.pdata = NULL;
1206 This->buf.capacity = 0;
1207 This->buf.cur_pos_data = 0;
1208 This->buf.pxo->nb_subobjects = 1;
1210 pstrings = HeapAlloc(GetProcessHeap(), 0, MAX_STRINGS_BUFFER);
1211 if (!pstrings)
1213 ERR("Out of memory\n");
1214 hr = DXFILEERR_BADALLOC;
1215 goto error;
1217 This->buf.cur_pstrings = This->buf.pstrings = object->pstrings = pstrings;
1219 if (!parse_object(&This->buf))
1221 WARN("Object is not correct\n");
1222 hr = DXFILEERR_PARSEERROR;
1223 goto error;
1226 object->pstrings = pstrings;
1227 object->pobj = This->buf.pxo;
1228 object->cur_enum_object = 0;
1229 object->level = 0;
1230 object->from_ref = FALSE;
1232 *ppDataObj = (LPDIRECTXFILEDATA)object;
1234 /* Get a reference to created object */
1235 This->pRefObjects[This->nb_xobjects] = (LPDIRECTXFILEDATA)object;
1236 IDirectXFileData_AddRef(This->pRefObjects[This->nb_xobjects]);
1238 This->nb_xobjects++;
1240 return DXFILE_OK;
1242 error:
1244 HeapFree(GetProcessHeap(), 0, This->buf.pxo_tab);
1245 HeapFree(GetProcessHeap(), 0, This->buf.pdata);
1246 HeapFree(GetProcessHeap(), 0, pstrings);
1248 return hr;
1251 static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetDataObjectById(IDirectXFileEnumObject* iface, REFGUID rguid, LPDIRECTXFILEDATA* ppDataObj)
1253 IDirectXFileEnumObjectImpl *This = impl_from_IDirectXFileEnumObject(iface);
1255 FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, rguid, ppDataObj);
1257 return DXFILEERR_BADVALUE;
1260 static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetDataObjectByName(IDirectXFileEnumObject* iface, LPCSTR szName, LPDIRECTXFILEDATA* ppDataObj)
1262 IDirectXFileEnumObjectImpl *This = impl_from_IDirectXFileEnumObject(iface);
1264 FIXME("(%p/%p)->(%s,%p) stub!\n", This, iface, szName, ppDataObj);
1266 return DXFILEERR_BADVALUE;
1269 static const IDirectXFileEnumObjectVtbl IDirectXFileEnumObject_Vtbl =
1271 IDirectXFileEnumObjectImpl_QueryInterface,
1272 IDirectXFileEnumObjectImpl_AddRef,
1273 IDirectXFileEnumObjectImpl_Release,
1274 IDirectXFileEnumObjectImpl_GetNextDataObject,
1275 IDirectXFileEnumObjectImpl_GetDataObjectById,
1276 IDirectXFileEnumObjectImpl_GetDataObjectByName
1279 static HRESULT IDirectXFileSaveObjectImpl_Create(IDirectXFileSaveObjectImpl** ppObj)
1281 IDirectXFileSaveObjectImpl* object;
1283 TRACE("(%p)\n", ppObj);
1285 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileSaveObjectImpl));
1286 if (!object)
1288 ERR("Out of memory\n");
1289 return DXFILEERR_BADALLOC;
1292 object->IDirectXFileSaveObject_iface.lpVtbl = &IDirectXFileSaveObject_Vtbl;
1293 object->ref = 1;
1295 *ppObj = object;
1297 return S_OK;
1300 static inline IDirectXFileSaveObjectImpl *impl_from_IDirectXFileSaveObject(IDirectXFileSaveObject *iface)
1302 return CONTAINING_RECORD(iface, IDirectXFileSaveObjectImpl, IDirectXFileSaveObject_iface);
1305 /*** IUnknown methods ***/
1306 static HRESULT WINAPI IDirectXFileSaveObjectImpl_QueryInterface(IDirectXFileSaveObject* iface, REFIID riid, void** ppvObject)
1308 IDirectXFileSaveObjectImpl *This = impl_from_IDirectXFileSaveObject(iface);
1310 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
1312 if (IsEqualGUID(riid, &IID_IUnknown)
1313 || IsEqualGUID(riid, &IID_IDirectXFileSaveObject))
1315 IUnknown_AddRef(iface);
1316 *ppvObject = &This->IDirectXFileSaveObject_iface;
1317 return S_OK;
1320 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1321 return E_NOINTERFACE;
1324 static ULONG WINAPI IDirectXFileSaveObjectImpl_AddRef(IDirectXFileSaveObject* iface)
1326 IDirectXFileSaveObjectImpl *This = impl_from_IDirectXFileSaveObject(iface);
1327 ULONG ref = InterlockedIncrement(&This->ref);
1329 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
1331 return ref;
1334 static ULONG WINAPI IDirectXFileSaveObjectImpl_Release(IDirectXFileSaveObject* iface)
1336 IDirectXFileSaveObjectImpl *This = impl_from_IDirectXFileSaveObject(iface);
1337 ULONG ref = InterlockedDecrement(&This->ref);
1339 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
1341 if (!ref)
1342 HeapFree(GetProcessHeap(), 0, This);
1344 return ref;
1347 static HRESULT WINAPI IDirectXFileSaveObjectImpl_SaveTemplates(IDirectXFileSaveObject* iface, DWORD cTemplates, const GUID** ppguidTemplates)
1349 IDirectXFileSaveObjectImpl *This = impl_from_IDirectXFileSaveObject(iface);
1351 FIXME("(%p/%p)->(%d,%p) stub!\n", This, iface, cTemplates, ppguidTemplates);
1353 return DXFILEERR_BADVALUE;
1356 static HRESULT WINAPI IDirectXFileSaveObjectImpl_CreateDataObject(IDirectXFileSaveObject* iface, REFGUID rguidTemplate, LPCSTR szName, const GUID* pguid, DWORD cbSize, LPVOID pvData, LPDIRECTXFILEDATA* ppDataObj)
1358 IDirectXFileSaveObjectImpl *This = impl_from_IDirectXFileSaveObject(iface);
1360 FIXME("(%p/%p)->(%p,%s,%p,%d,%p,%p) stub!\n", This, iface, rguidTemplate, szName, pguid, cbSize, pvData, ppDataObj);
1362 return DXFILEERR_BADVALUE;
1365 static HRESULT WINAPI IDirectXFileSaveObjectImpl_SaveData(IDirectXFileSaveObject* iface, LPDIRECTXFILEDATA ppDataObj)
1367 IDirectXFileSaveObjectImpl *This = impl_from_IDirectXFileSaveObject(iface);
1369 FIXME("(%p/%p)->(%p) stub!\n", This, iface, ppDataObj);
1371 return DXFILEERR_BADVALUE;
1374 static const IDirectXFileSaveObjectVtbl IDirectXFileSaveObject_Vtbl =
1376 IDirectXFileSaveObjectImpl_QueryInterface,
1377 IDirectXFileSaveObjectImpl_AddRef,
1378 IDirectXFileSaveObjectImpl_Release,
1379 IDirectXFileSaveObjectImpl_SaveTemplates,
1380 IDirectXFileSaveObjectImpl_CreateDataObject,
1381 IDirectXFileSaveObjectImpl_SaveData