1 /* IDirectMusicContainerImpl
3 * Copyright (C) 2003-2004 Rok Mandeljc
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Library General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "dmloader_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(dmloader
);
23 WINE_DECLARE_DEBUG_CHANNEL(dmfile
);
24 WINE_DECLARE_DEBUG_CHANNEL(dmdump
);
26 #define DMUS_MAX_CATEGORY_SIZE DMUS_MAX_CATEGORY*sizeof(WCHAR)
27 #define DMUS_MAX_NAME_SIZE DMUS_MAX_NAME*sizeof(WCHAR)
28 #define DMUS_MAX_FILENAME_SIZE DMUS_MAX_FILENAME*sizeof(WCHAR)
30 /*****************************************************************************
31 * IDirectMusicContainerImpl implementation
33 /* IUnknown/IDirectMusicContainer part: */
34 HRESULT WINAPI
IDirectMusicContainerImpl_IDirectMusicContainer_QueryInterface (LPDIRECTMUSICCONTAINER iface
, REFIID riid
, LPVOID
*ppobj
) {
35 ICOM_THIS_MULTI(IDirectMusicContainerImpl
, ContainerVtbl
, iface
);
37 TRACE("(%p, %s, %p)\n", This
, debugstr_dmguid(riid
), ppobj
);
38 if (IsEqualIID (riid
, &IID_IUnknown
) ||
39 IsEqualIID (riid
, &IID_IDirectMusicContainer
)) {
40 *ppobj
= (LPVOID
)&This
->ContainerVtbl
;
41 IDirectMusicContainerImpl_IDirectMusicContainer_AddRef ((LPDIRECTMUSICCONTAINER
)&This
->ContainerVtbl
);
43 } else if (IsEqualIID (riid
, &IID_IDirectMusicObject
)) {
44 *ppobj
= (LPVOID
)&This
->ObjectVtbl
;
45 IDirectMusicContainerImpl_IDirectMusicObject_AddRef ((LPDIRECTMUSICOBJECT
)&This
->ObjectVtbl
);
47 } else if (IsEqualIID (riid
, &IID_IPersistStream
)) {
48 *ppobj
= (LPVOID
)&This
->PersistStreamVtbl
;
49 IDirectMusicContainerImpl_IPersistStream_AddRef ((LPPERSISTSTREAM
)&This
->PersistStreamVtbl
);
53 WARN(": not found\n");
57 ULONG WINAPI
IDirectMusicContainerImpl_IDirectMusicContainer_AddRef (LPDIRECTMUSICCONTAINER iface
) {
58 ICOM_THIS_MULTI(IDirectMusicContainerImpl
, ContainerVtbl
, iface
);
59 TRACE("(%p): AddRef from %ld\n", This
, This
->dwRef
);
60 return InterlockedIncrement (&This
->dwRef
);
63 ULONG WINAPI
IDirectMusicContainerImpl_IDirectMusicContainer_Release (LPDIRECTMUSICCONTAINER iface
) {
64 ICOM_THIS_MULTI(IDirectMusicContainerImpl
, ContainerVtbl
, iface
);
66 DWORD dwRef
= InterlockedDecrement (&This
->dwRef
);
67 TRACE("(%p): ReleaseRef to %ld\n", This
, dwRef
);
69 DMUSIC_DestroyDirectMusicContainerImpl (iface
);
70 HeapFree(GetProcessHeap(), 0, This
);
76 HRESULT WINAPI
IDirectMusicContainerImpl_IDirectMusicContainer_EnumObject (LPDIRECTMUSICCONTAINER iface
, REFGUID rguidClass
, DWORD dwIndex
, LPDMUS_OBJECTDESC pDesc
, WCHAR
* pwszAlias
) {
77 ICOM_THIS_MULTI(IDirectMusicContainerImpl
, ContainerVtbl
, iface
);
79 LPWINE_CONTAINER_ENTRY pContainedObject
;
82 TRACE("(%p, %s, %ld, %p, %p)\n", This
, debugstr_dmguid(rguidClass
), dwIndex
, pDesc
, pwszAlias
);
84 /* check if we can write to whole pDesc */
86 if (IsBadReadPtr (pDesc
, sizeof(DWORD
))) {
87 ERR(": pDesc->dwSize bad read pointer\n");
90 if (pDesc
->dwSize
!= sizeof(DMUS_OBJECTDESC
)) {
91 ERR(": invalid pDesc->dwSize\n");
94 if (IsBadWritePtr (pDesc
, sizeof(DMUS_OBJECTDESC
))) {
95 ERR(": pDesc bad write pointer\n");
99 /* check if we wszAlias is big enough */
100 if (pwszAlias
&& IsBadWritePtr (pwszAlias
, DMUS_MAX_FILENAME_SIZE
)) {
101 ERR(": wszAlias bad write pointer\n");
105 DM_STRUCT_INIT(pDesc
);
107 LIST_FOR_EACH (pEntry
, This
->pContainedObjects
) {
108 pContainedObject
= LIST_ENTRY (pEntry
, WINE_CONTAINER_ENTRY
, entry
);
110 if (IsEqualGUID (rguidClass
, &GUID_DirectMusicAllTypes
) || IsEqualGUID (rguidClass
, &pContainedObject
->Desc
.guidClass
)) {
111 if (dwCount
== dwIndex
) {
112 HRESULT result
= S_OK
;
114 lstrcpynW (pwszAlias
, pContainedObject
->wszAlias
, DMUS_MAX_FILENAME
);
115 if (strlenW (pContainedObject
->wszAlias
) > DMUS_MAX_FILENAME
)
116 result
= DMUS_S_STRING_TRUNCATED
;
119 memcpy (pDesc
, &pContainedObject
->Desc
, sizeof(DMUS_OBJECTDESC
));
126 TRACE(": not found\n");
130 static const IDirectMusicContainerVtbl DirectMusicContainer_Container_Vtbl
= {
131 IDirectMusicContainerImpl_IDirectMusicContainer_QueryInterface
,
132 IDirectMusicContainerImpl_IDirectMusicContainer_AddRef
,
133 IDirectMusicContainerImpl_IDirectMusicContainer_Release
,
134 IDirectMusicContainerImpl_IDirectMusicContainer_EnumObject
137 /* IDirectMusicObject part: */
138 HRESULT WINAPI
IDirectMusicContainerImpl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface
, REFIID riid
, LPVOID
*ppobj
) {
139 ICOM_THIS_MULTI(IDirectMusicContainerImpl
, ObjectVtbl
, iface
);
140 return IDirectMusicContainerImpl_IDirectMusicContainer_QueryInterface ((LPDIRECTMUSICCONTAINER
)&This
->ContainerVtbl
, riid
, ppobj
);
143 ULONG WINAPI
IDirectMusicContainerImpl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface
) {
144 ICOM_THIS_MULTI(IDirectMusicContainerImpl
, ObjectVtbl
, iface
);
145 return IDirectMusicContainerImpl_IDirectMusicContainer_AddRef ((LPDIRECTMUSICCONTAINER
)&This
->ContainerVtbl
);
148 ULONG WINAPI
IDirectMusicContainerImpl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface
) {
149 ICOM_THIS_MULTI(IDirectMusicContainerImpl
, ObjectVtbl
, iface
);
150 return IDirectMusicContainerImpl_IDirectMusicContainer_Release ((LPDIRECTMUSICCONTAINER
)&This
->ContainerVtbl
);
153 HRESULT WINAPI
IDirectMusicContainerImpl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface
, LPDMUS_OBJECTDESC pDesc
) {
154 ICOM_THIS_MULTI(IDirectMusicContainerImpl
, ObjectVtbl
, iface
);
155 TRACE("(%p, %p):\n", This
, pDesc
);
157 /* check if whe can write to whole pDesc */
158 if (IsBadReadPtr (pDesc
, sizeof(DWORD
))) {
159 ERR(": pDesc->dwSize bad read pointer\n");
162 if (pDesc
->dwSize
!= sizeof(DMUS_OBJECTDESC
)) {
163 ERR(": invalid pDesc->dwSize\n");
166 if (IsBadWritePtr (pDesc
, sizeof(DMUS_OBJECTDESC
))) {
167 ERR(": pDesc bad write pointer\n");
171 DM_STRUCT_INIT(pDesc
);
172 memcpy (pDesc
, &This
->Desc
, sizeof(DMUS_OBJECTDESC
));
177 HRESULT WINAPI
IDirectMusicContainerImpl_IDirectMusicObject_SetDescriptor (LPDIRECTMUSICOBJECT iface
, LPDMUS_OBJECTDESC pDesc
) {
178 DWORD dwNewFlags
= 0;
179 DWORD dwFlagDifference
;
180 ICOM_THIS_MULTI(IDirectMusicContainerImpl
, ObjectVtbl
, iface
);
181 TRACE("(%p, %p):\n", This
, pDesc
);
183 /* check if whe can read whole pDesc */
184 if (IsBadReadPtr (pDesc
, sizeof(DWORD
))) {
185 ERR(": pDesc->dwSize bad read pointer\n");
188 if (pDesc
->dwSize
!= sizeof(DMUS_OBJECTDESC
)) {
189 ERR(": invalid pDesc->dwSize\n");
192 if (IsBadReadPtr (pDesc
, sizeof(DMUS_OBJECTDESC
))) {
193 ERR(": pDesc bad read pointer\n");
197 if (pDesc
->dwValidData
& DMUS_OBJ_OBJECT
) {
198 memcpy (&This
->Desc
.guidObject
, &pDesc
->guidObject
, sizeof(GUID
));
199 dwNewFlags
|= DMUS_OBJ_OBJECT
;
201 if (pDesc
->dwValidData
& DMUS_OBJ_NAME
) {
202 lstrcpynW (This
->Desc
.wszName
, pDesc
->wszName
, DMUS_MAX_NAME
);
203 dwNewFlags
|= DMUS_OBJ_NAME
;
205 if (pDesc
->dwValidData
& DMUS_OBJ_CATEGORY
) {
206 lstrcpynW (This
->Desc
.wszCategory
, pDesc
->wszCategory
, DMUS_MAX_CATEGORY
);
207 dwNewFlags
|= DMUS_OBJ_CATEGORY
;
209 if (pDesc
->dwValidData
& (DMUS_OBJ_FILENAME
| DMUS_OBJ_FULLPATH
)) {
210 lstrcpynW (This
->Desc
.wszFileName
, pDesc
->wszFileName
, DMUS_MAX_FILENAME
);
211 dwNewFlags
|= (pDesc
->dwValidData
& (DMUS_OBJ_FILENAME
| DMUS_OBJ_FULLPATH
));
213 if (pDesc
->dwValidData
& DMUS_OBJ_VERSION
) {
214 This
->Desc
.vVersion
.dwVersionLS
= pDesc
->vVersion
.dwVersionLS
;
215 This
->Desc
.vVersion
.dwVersionMS
= pDesc
->vVersion
.dwVersionMS
;
216 dwNewFlags
|= DMUS_OBJ_VERSION
;
218 if (pDesc
->dwValidData
& DMUS_OBJ_DATE
) {
219 This
->Desc
.ftDate
.dwHighDateTime
= pDesc
->ftDate
.dwHighDateTime
;
220 This
->Desc
.ftDate
.dwLowDateTime
= pDesc
->ftDate
.dwLowDateTime
;
221 dwNewFlags
|= DMUS_OBJ_DATE
;
224 This
->Desc
.dwValidData
|= dwNewFlags
;
226 dwFlagDifference
= pDesc
->dwValidData
- dwNewFlags
;
227 if (dwFlagDifference
) {
228 pDesc
->dwValidData
&= ~dwFlagDifference
; /* and with bitwise complement */
233 HRESULT WINAPI
IDirectMusicContainerImpl_IDirectMusicObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface
, LPSTREAM pStream
, LPDMUS_OBJECTDESC pDesc
) {
234 ICOM_THIS_MULTI(IDirectMusicContainerImpl
, ObjectVtbl
, iface
);
236 DWORD StreamSize
, StreamCount
, ListSize
[1], ListCount
[1];
237 LARGE_INTEGER liMove
; /* used when skipping chunks */
239 TRACE("(%p, %p, %p)\n", This
, pStream
, pDesc
);
241 /* check whether arguments are OK */
242 if (IsBadReadPtr (pStream
, sizeof(LPVOID
))) {
243 ERR(": pStream bad read pointer\n");
246 /* check whether pDesc is OK */
247 if (IsBadReadPtr (pDesc
, sizeof(DWORD
))) {
248 ERR(": pDesc->dwSize bad read pointer\n");
251 if (pDesc
->dwSize
!= sizeof(DMUS_OBJECTDESC
)) {
252 ERR(": invalid pDesc->dwSize\n");
255 if (IsBadWritePtr (pDesc
, sizeof(DMUS_OBJECTDESC
))) {
256 ERR(": pDesc bad write pointer\n");
260 DM_STRUCT_INIT(pDesc
);
263 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
264 TRACE_(dmfile
)(": %s chunk (size = 0x%08lX)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
265 switch (Chunk
.fccID
) {
267 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
268 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
269 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
271 if (Chunk
.fccID
== DMUS_FOURCC_CONTAINER_FORM
) {
272 TRACE_(dmfile
)(": container form\n");
274 pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
275 memcpy (&pDesc
->guidClass
, &CLSID_DirectMusicContainer
, sizeof(CLSID
));
277 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
278 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
279 TRACE_(dmfile
)(": %s chunk (size = 0x%08lX)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
280 switch (Chunk
.fccID
) {
281 case DMUS_FOURCC_GUID_CHUNK
: {
282 TRACE_(dmfile
)(": GUID chunk\n");
283 pDesc
->dwValidData
|= DMUS_OBJ_OBJECT
;
284 IStream_Read (pStream
, &pDesc
->guidObject
, Chunk
.dwSize
, NULL
);
285 TRACE_(dmdump
)(": GUID: %s\n", debugstr_guid(&pDesc
->guidObject
));
288 case DMUS_FOURCC_VERSION_CHUNK
: {
289 TRACE_(dmfile
)(": version chunk\n");
290 pDesc
->dwValidData
|= DMUS_OBJ_VERSION
;
291 IStream_Read (pStream
, &pDesc
->vVersion
, Chunk
.dwSize
, NULL
);
292 TRACE_(dmdump
)(": version: %s\n", debugstr_dmversion(&pDesc
->vVersion
));
295 case DMUS_FOURCC_DATE_CHUNK
: {
296 TRACE_(dmfile
)(": date chunk\n");
297 IStream_Read (pStream
, &pDesc
->ftDate
, Chunk
.dwSize
, NULL
);
298 pDesc
->dwValidData
|= DMUS_OBJ_DATE
;
299 TRACE_(dmdump
)(": date: %s\n", debugstr_filetime(&pDesc
->ftDate
));
302 case DMUS_FOURCC_CATEGORY_CHUNK
: {
303 TRACE_(dmfile
)(": category chunk\n");
304 /* if it happens that string is too long,
305 read what we can and skip the rest*/
306 if (Chunk
.dwSize
> DMUS_MAX_CATEGORY_SIZE
) {
307 IStream_Read (pStream
, pDesc
->wszCategory
, DMUS_MAX_CATEGORY_SIZE
, NULL
);
308 liMove
.QuadPart
= Chunk
.dwSize
- DMUS_MAX_CATEGORY_SIZE
;
309 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
311 IStream_Read (pStream
, pDesc
->wszCategory
, Chunk
.dwSize
, NULL
);
313 pDesc
->dwValidData
|= DMUS_OBJ_CATEGORY
;
314 TRACE_(dmdump
)(": category: %s\n", debugstr_w(pDesc
->wszCategory
));
318 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
319 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
320 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
322 switch (Chunk
.fccID
) {
323 /* evil M$ UNFO list, which can (!?) contain INFO elements */
324 case DMUS_FOURCC_UNFO_LIST
: {
325 TRACE_(dmfile
)(": UNFO list\n");
327 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
328 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
329 TRACE_(dmfile
)(": %s chunk (size = 0x%08lX)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
330 switch (Chunk
.fccID
) {
331 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
332 (though strings seem to be valid unicode) */
333 case mmioFOURCC('I','N','A','M'):
334 case DMUS_FOURCC_UNAM_CHUNK
: {
335 TRACE_(dmfile
)(": name chunk\n");
336 /* if it happens that string is too long,
337 read what we can and skip the rest*/
338 if (Chunk
.dwSize
> DMUS_MAX_NAME_SIZE
) {
339 IStream_Read (pStream
, pDesc
->wszName
, DMUS_MAX_NAME_SIZE
, NULL
);
340 liMove
.QuadPart
= Chunk
.dwSize
- DMUS_MAX_NAME_SIZE
;
341 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
343 IStream_Read (pStream
, pDesc
->wszName
, Chunk
.dwSize
, NULL
);
345 pDesc
->dwValidData
|= DMUS_OBJ_NAME
;
346 TRACE_(dmdump
)(": name: %s\n", debugstr_w(pDesc
->wszName
));
350 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
351 liMove
.QuadPart
= Chunk
.dwSize
;
352 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
356 TRACE_(dmfile
)(": ListCount[0] = 0x%08lX < ListSize[0] = 0x%08lX\n", ListCount
[0], ListSize
[0]);
357 } while (ListCount
[0] < ListSize
[0]);
361 TRACE_(dmfile
)(": unknown (skipping)\n");
362 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
363 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
370 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
371 liMove
.QuadPart
= Chunk
.dwSize
;
372 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
376 TRACE_(dmfile
)(": StreamCount[0] = 0x%08lX < StreamSize[0] = 0x%08lX\n", StreamCount
, StreamSize
);
377 } while (StreamCount
< StreamSize
);
379 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
380 liMove
.QuadPart
= StreamSize
;
381 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
385 TRACE_(dmfile
)(": reading finished\n");
389 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
390 liMove
.QuadPart
= Chunk
.dwSize
;
391 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
392 return DMUS_E_INVALIDFILE
;
396 TRACE(": returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC(pDesc
));
400 static const IDirectMusicObjectVtbl DirectMusicContainer_Object_Vtbl
= {
401 IDirectMusicContainerImpl_IDirectMusicObject_QueryInterface
,
402 IDirectMusicContainerImpl_IDirectMusicObject_AddRef
,
403 IDirectMusicContainerImpl_IDirectMusicObject_Release
,
404 IDirectMusicContainerImpl_IDirectMusicObject_GetDescriptor
,
405 IDirectMusicContainerImpl_IDirectMusicObject_SetDescriptor
,
406 IDirectMusicContainerImpl_IDirectMusicObject_ParseDescriptor
409 /* IPersistStream part: */
410 HRESULT WINAPI
IDirectMusicContainerImpl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface
, REFIID riid
, LPVOID
*ppobj
) {
411 ICOM_THIS_MULTI(IDirectMusicContainerImpl
, PersistStreamVtbl
, iface
);
412 return IDirectMusicContainerImpl_IDirectMusicContainer_QueryInterface ((LPDIRECTMUSICCONTAINER
)&This
->ContainerVtbl
, riid
, ppobj
);
415 ULONG WINAPI
IDirectMusicContainerImpl_IPersistStream_AddRef (LPPERSISTSTREAM iface
) {
416 ICOM_THIS_MULTI(IDirectMusicContainerImpl
, PersistStreamVtbl
, iface
);
417 return IDirectMusicContainerImpl_IDirectMusicContainer_AddRef ((LPDIRECTMUSICCONTAINER
)&This
->ContainerVtbl
);
420 ULONG WINAPI
IDirectMusicContainerImpl_IPersistStream_Release (LPPERSISTSTREAM iface
) {
421 ICOM_THIS_MULTI(IDirectMusicContainerImpl
, PersistStreamVtbl
, iface
);
422 return IDirectMusicContainerImpl_IDirectMusicContainer_Release ((LPDIRECTMUSICCONTAINER
)&This
->ContainerVtbl
);
425 HRESULT WINAPI
IDirectMusicContainerImpl_IPersistStream_GetClassID (LPPERSISTSTREAM iface
, CLSID
* pClassID
) {
426 ICOM_THIS_MULTI(IDirectMusicContainerImpl
, PersistStreamVtbl
, iface
);
428 TRACE("(%p, %p)\n", This
, pClassID
);
429 if (IsBadWritePtr (pClassID
, sizeof(CLSID
))) {
430 ERR(": pClassID bad write pointer\n");
434 *pClassID
= CLSID_DirectMusicContainer
;
438 HRESULT WINAPI
IDirectMusicContainerImpl_IPersistStream_IsDirty (LPPERSISTSTREAM iface
) {
439 /* FIXME: is implemented (somehow) */
443 HRESULT WINAPI
IDirectMusicContainerImpl_IPersistStream_Load (LPPERSISTSTREAM iface
, IStream
* pStm
) {
444 ICOM_THIS_MULTI(IDirectMusicContainerImpl
, PersistStreamVtbl
, iface
);
446 DWORD StreamSize
, StreamCount
, ListSize
[3], ListCount
[3];
447 LARGE_INTEGER liMove
; /* used when skipping chunks */
448 ULARGE_INTEGER uliPos
; /* needed when dealing with RIFF chunks */
449 LPDIRECTMUSICGETLOADER pGetLoader
;
450 LPDIRECTMUSICLOADER pLoader
;
451 HRESULT result
= S_OK
;
453 TRACE("(%p, %p):\n", This
, pStm
);
455 /* check whether pStm is valid read pointer */
456 if (IsBadReadPtr (pStm
, sizeof(LPVOID
))) {
457 ERR(": pStm bad read pointer\n");
460 /* if stream is already set, this means we're loaded already */
462 TRACE(": stream is already set, which means container is already loaded\n");
463 return DMUS_E_ALREADY_LOADED
;
466 /* get loader since it will be needed later */
467 if (FAILED(IStream_QueryInterface (pStm
, &IID_IDirectMusicGetLoader
, (LPVOID
*)&pGetLoader
))) {
468 ERR(": stream not supported\n");
469 return DMUS_E_UNSUPPORTED_STREAM
;
471 IDirectMusicGetLoader_GetLoader (pGetLoader
, &pLoader
);
472 IDirectMusicGetLoader_Release (pGetLoader
);
474 This
->pStream
= pStm
;
475 IStream_AddRef (pStm
); /* add count for later references */
477 /* start with load */
478 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
479 TRACE_(dmfile
)(": %s chunk (size = 0x%08lX)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
480 switch (Chunk
.fccID
) {
482 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
483 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
484 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
486 switch (Chunk
.fccID
) {
487 case DMUS_FOURCC_CONTAINER_FORM
: {
488 TRACE_(dmfile
)(": container form\n");
489 memcpy (&This
->Desc
.guidClass
, &CLSID_DirectMusicContainer
, sizeof(CLSID
));
490 This
->Desc
.dwValidData
|= DMUS_OBJ_CLASS
;
492 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
493 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
494 TRACE_(dmfile
)(": %s chunk (size = 0x%08lX)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
495 switch (Chunk
.fccID
) {
496 case DMUS_FOURCC_CONTAINER_CHUNK
: {
497 TRACE_(dmfile
)(": container header chunk\n");
498 IStream_Read (pStm
, &This
->Header
, Chunk
.dwSize
, NULL
);
499 TRACE_(dmdump
)(": container header chunk:\n%s", debugstr_DMUS_IO_CONTAINER_HEADER(&This
->Header
));
502 case DMUS_FOURCC_GUID_CHUNK
: {
503 TRACE_(dmfile
)(": GUID chunk\n");
504 IStream_Read (pStm
, &This
->Desc
.guidObject
, Chunk
.dwSize
, NULL
);
505 This
->Desc
.dwValidData
|= DMUS_OBJ_OBJECT
;
506 TRACE_(dmdump
)(": GUID: %s\n", debugstr_guid(&This
->Desc
.guidObject
));
509 case DMUS_FOURCC_VERSION_CHUNK
: {
510 TRACE_(dmfile
)(": version chunk\n");
511 IStream_Read (pStm
, &This
->Desc
.vVersion
, Chunk
.dwSize
, NULL
);
512 This
->Desc
.dwValidData
|= DMUS_OBJ_VERSION
;
513 TRACE_(dmdump
)(": version: %s\n", debugstr_dmversion(&This
->Desc
.vVersion
));
516 case DMUS_FOURCC_DATE_CHUNK
: {
517 TRACE_(dmfile
)(": date chunk\n");
518 IStream_Read (pStm
, &This
->Desc
.ftDate
, Chunk
.dwSize
, NULL
);
519 This
->Desc
.dwValidData
|= DMUS_OBJ_DATE
;
520 TRACE_(dmdump
)(": date: %s\n", debugstr_filetime(&This
->Desc
.ftDate
));
523 case DMUS_FOURCC_CATEGORY_CHUNK
: {
524 TRACE_(dmfile
)(": category chunk\n");
525 /* if it happens that string is too long,
526 read what we can and skip the rest*/
527 if (Chunk
.dwSize
> DMUS_MAX_CATEGORY_SIZE
) {
528 IStream_Read (pStm
, This
->Desc
.wszCategory
, DMUS_MAX_CATEGORY_SIZE
, NULL
);
529 liMove
.QuadPart
= Chunk
.dwSize
- DMUS_MAX_CATEGORY_SIZE
;
530 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
532 IStream_Read (pStm
, This
->Desc
.wszCategory
, Chunk
.dwSize
, NULL
);
534 This
->Desc
.dwValidData
|= DMUS_OBJ_CATEGORY
;
535 TRACE_(dmdump
)(": category: %s\n", debugstr_w(This
->Desc
.wszCategory
));
539 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
540 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
541 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
543 switch (Chunk
.fccID
) {
544 case DMUS_FOURCC_UNFO_LIST
: {
545 TRACE_(dmfile
)(": UNFO list\n");
547 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
548 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
549 TRACE_(dmfile
)(": %s chunk (size = 0x%08lX)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
550 switch (Chunk
.fccID
) {
551 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
552 (though strings seem to be valid unicode) */
553 case mmioFOURCC('I','N','A','M'):
554 case DMUS_FOURCC_UNAM_CHUNK
: {
555 TRACE_(dmfile
)(": name chunk\n");
556 /* if it happens that string is too long,
557 read what we can and skip the rest*/
558 if (Chunk
.dwSize
> DMUS_MAX_NAME_SIZE
) {
559 IStream_Read (pStm
, This
->Desc
.wszName
, DMUS_MAX_NAME_SIZE
, NULL
);
560 liMove
.QuadPart
= Chunk
.dwSize
- DMUS_MAX_NAME_SIZE
;
561 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
563 IStream_Read (pStm
, This
->Desc
.wszName
, Chunk
.dwSize
, NULL
);
565 This
->Desc
.dwValidData
|= DMUS_OBJ_NAME
;
566 TRACE_(dmdump
)(": name: %s\n", debugstr_w(This
->Desc
.wszName
));
570 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
571 liMove
.QuadPart
= Chunk
.dwSize
;
572 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
576 TRACE_(dmfile
)(": ListCount[0] = 0x%08lX < ListSize[0] = 0x%08lX\n", ListCount
[0], ListSize
[0]);
577 } while (ListCount
[0] < ListSize
[0]);
580 case DMUS_FOURCC_CONTAINED_OBJECTS_LIST
: {
581 TRACE_(dmfile
)(": contained objects list\n");
583 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
584 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
585 TRACE_(dmfile
)(": %s chunk (size = 0x%08lX)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
586 switch (Chunk
.fccID
) {
588 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
589 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
590 ListSize
[1] = Chunk
.dwSize
- sizeof(FOURCC
);
592 switch (Chunk
.fccID
) {
593 case DMUS_FOURCC_CONTAINED_OBJECT_LIST
: {
594 LPWINE_CONTAINER_ENTRY pNewEntry
;
595 TRACE_(dmfile
)(": contained object list\n");
596 pNewEntry
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(WINE_CONTAINER_ENTRY
));
597 DM_STRUCT_INIT(&pNewEntry
->Desc
);
599 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
600 ListCount
[1] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
601 TRACE_(dmfile
)(": %s chunk (size = 0x%08lX)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
602 switch (Chunk
.fccID
) {
603 case DMUS_FOURCC_CONTAINED_ALIAS_CHUNK
: {
604 TRACE_(dmfile
)(": alias chunk\n");
605 pNewEntry
->wszAlias
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, Chunk
.dwSize
);
606 IStream_Read (pStm
, pNewEntry
->wszAlias
, Chunk
.dwSize
, NULL
);
607 TRACE_(dmdump
)(": alias: %s\n", debugstr_w(pNewEntry
->wszAlias
));
610 case DMUS_FOURCC_CONTAINED_OBJECT_CHUNK
: {
611 DMUS_IO_CONTAINED_OBJECT_HEADER tmpObjectHeader
;
612 TRACE_(dmfile
)(": contained object header chunk\n");
613 IStream_Read (pStm
, &tmpObjectHeader
, Chunk
.dwSize
, NULL
);
614 TRACE_(dmdump
)(": contained object header: \n%s", debugstr_DMUS_IO_CONTAINED_OBJECT_HEADER(&tmpObjectHeader
));
616 pNewEntry
->Desc
.dwValidData
|= DMUS_OBJ_CLASS
;
617 memcpy (&pNewEntry
->Desc
.guidClass
, &tmpObjectHeader
.guidClassID
, sizeof(GUID
));
619 pNewEntry
->dwFlags
= tmpObjectHeader
.dwFlags
;
622 /* now read data... it may be safe to read everything after object header chunk,
623 but I'm not comfortable with MSDN's "the header is *normally* followed by ..." */
625 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
626 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
627 ListSize
[2] = Chunk
.dwSize
- sizeof(FOURCC
);
629 switch (Chunk
.fccID
) {
630 case DMUS_FOURCC_REF_LIST
: {
631 TRACE_(dmfile
)(": reference list\n");
632 pNewEntry
->bIsRIFF
= 0;
634 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
635 ListCount
[2] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
636 TRACE_(dmfile
)(": %s chunk (size = 0x%08lX)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
637 switch (Chunk
.fccID
) {
638 case DMUS_FOURCC_REF_CHUNK
: {
639 DMUS_IO_REFERENCE tmpReferenceHeader
; /* temporary structure */
640 TRACE_(dmfile
)(": reference header chunk\n");
641 memset (&tmpReferenceHeader
, 0, sizeof(DMUS_IO_REFERENCE
));
642 IStream_Read (pStm
, &tmpReferenceHeader
, Chunk
.dwSize
, NULL
);
643 /* copy retrieved data to DMUS_OBJECTDESC */
644 if (!IsEqualCLSID (&pNewEntry
->Desc
.guidClass
, &tmpReferenceHeader
.guidClassID
)) ERR(": object header declares different CLSID than reference header?\n");
645 /* it shouldn't be necessary to copy guidClass, since it was set in contained object header already...
646 yet if they happen to be different, I'd rather stick to this one */
647 memcpy (&pNewEntry
->Desc
.guidClass
, &tmpReferenceHeader
.guidClassID
, sizeof(GUID
));
648 pNewEntry
->Desc
.dwValidData
|= tmpReferenceHeader
.dwValidData
;
651 case DMUS_FOURCC_GUID_CHUNK
: {
652 TRACE_(dmfile
)(": guid chunk\n");
653 /* no need to set flags since they were copied from reference header */
654 IStream_Read (pStm
, &pNewEntry
->Desc
.guidObject
, Chunk
.dwSize
, NULL
);
657 case DMUS_FOURCC_DATE_CHUNK
: {
658 TRACE_(dmfile
)(": file date chunk\n");
659 /* no need to set flags since they were copied from reference header */
660 IStream_Read (pStm
, &pNewEntry
->Desc
.ftDate
, Chunk
.dwSize
, NULL
);
663 case DMUS_FOURCC_NAME_CHUNK
: {
664 TRACE_(dmfile
)(": name chunk\n");
665 /* no need to set flags since they were copied from reference header */
666 IStream_Read (pStm
, pNewEntry
->Desc
.wszName
, Chunk
.dwSize
, NULL
);
669 case DMUS_FOURCC_FILE_CHUNK
: {
670 TRACE_(dmfile
)(": file name chunk\n");
671 /* no need to set flags since they were copied from reference header */
672 IStream_Read (pStm
, pNewEntry
->Desc
.wszFileName
, Chunk
.dwSize
, NULL
);
675 case DMUS_FOURCC_CATEGORY_CHUNK
: {
676 TRACE_(dmfile
)(": category chunk\n");
677 /* no need to set flags since they were copied from reference header */
678 IStream_Read (pStm
, pNewEntry
->Desc
.wszCategory
, Chunk
.dwSize
, NULL
);
681 case DMUS_FOURCC_VERSION_CHUNK
: {
682 TRACE_(dmfile
)(": version chunk\n");
683 /* no need to set flags since they were copied from reference header */
684 IStream_Read (pStm
, &pNewEntry
->Desc
.vVersion
, Chunk
.dwSize
, NULL
);
688 TRACE_(dmfile
)(": unknown chunk (skipping)\n");
689 liMove
.QuadPart
= Chunk
.dwSize
;
690 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip this chunk */
694 TRACE_(dmfile
)(": ListCount[2] = 0x%08lX < ListSize[2] = 0x%08lX\n", ListCount
[2], ListSize
[2]);
695 } while (ListCount
[2] < ListSize
[2]);
699 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
707 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
708 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
709 if (IS_VALID_DMFORM (Chunk
.fccID
)) {
710 TRACE_(dmfile
)(": valid DMUSIC form\n");
711 pNewEntry
->bIsRIFF
= 1;
712 /* we'll have to skip whole RIFF chunk after SetObject is called */
714 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, &uliPos
);
715 uliPos
.QuadPart
+= (Chunk
.dwSize
- sizeof(FOURCC
)); /* set uliPos at the end of RIFF chunk */
716 /* move at the beginning of RIFF chunk */
718 liMove
.QuadPart
-= (sizeof(FOURCC
)+sizeof(DWORD
)+sizeof(FOURCC
));
719 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
720 /* put pointer to stream in descriptor */
721 pNewEntry
->Desc
.dwValidData
|= DMUS_OBJ_STREAM
;
722 pNewEntry
->Desc
.pStream
= pStm
; /* we don't have to worry about cloning, since SetObject will perform it */
723 /* wait till we get on the end of object list */
725 TRACE_(dmfile
)(": invalid DMUSIC form (skipping)\n");
726 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
727 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
728 /* FIXME: should we return E_FAIL? */
733 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
734 liMove
.QuadPart
= Chunk
.dwSize
;
735 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
739 TRACE_(dmfile
)(": ListCount[1] = 0x%08lX < ListSize[1] = 0x%08lX\n", ListCount
[1], ListSize
[1]);
740 } while (ListCount
[1] < ListSize
[1]);
741 /* SetObject: this will fill descriptor with additional info and add alias in loader's cache */
742 IDirectMusicLoader_SetObject (pLoader
, &pNewEntry
->Desc
);
743 /* now that SetObject collected appropriate info into descriptor we can live happily ever after;
744 or not, since we have to clean evidence of loading through stream... *sigh*
745 and we have to skip rest of the chunk, if we loaded through RIFF */
746 if (pNewEntry
->bIsRIFF
) {
747 liMove
.QuadPart
= uliPos
.QuadPart
;
748 IStream_Seek (pStm
, liMove
, STREAM_SEEK_SET
, NULL
);
749 pNewEntry
->Desc
.dwValidData
&= ~DMUS_OBJ_STREAM
; /* clear flag (and with bitwise complement) */
750 pNewEntry
->Desc
.pStream
= NULL
;
752 /* add entry to list of objects */
753 list_add_tail (This
->pContainedObjects
, &pNewEntry
->entry
);
757 TRACE_(dmfile
)(": unknown (skipping)\n");
758 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
759 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
766 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
767 liMove
.QuadPart
= Chunk
.dwSize
;
768 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
772 TRACE_(dmfile
)(": ListCount[0] = 0x%08lX < ListSize[0] = 0x%08lX\n", ListCount
[0], ListSize
[0]);
773 } while (ListCount
[0] < ListSize
[0]);
777 TRACE_(dmfile
)(": unknown (skipping)\n");
778 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
779 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
786 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
787 liMove
.QuadPart
= Chunk
.dwSize
;
788 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
792 TRACE_(dmfile
)(": StreamCount[0] = 0x%08lX < StreamSize[0] = 0x%08lX\n", StreamCount
, StreamSize
);
793 } while (StreamCount
< StreamSize
);
797 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
798 liMove
.QuadPart
= StreamSize
;
799 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
803 TRACE_(dmfile
)(": reading finished\n");
804 This
->Desc
.dwValidData
|= DMUS_OBJ_LOADED
;
808 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
809 liMove
.QuadPart
= Chunk
.dwSize
;
810 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
815 /* now, if DMUS_CONTAINER_NOLOADS is not set, we are supposed to load contained objects;
816 so when we call GetObject later, they'll already be in cache */
817 if (!(This
->Header
.dwFlags
& DMUS_CONTAINER_NOLOADS
)) {
819 LPWINE_CONTAINER_ENTRY pContainedObject
;
821 TRACE(": DMUS_CONTAINER_NOLOADS not set... load all objects\n");
823 LIST_FOR_EACH (pEntry
, This
->pContainedObjects
) {
824 IDirectMusicObject
* pObject
;
825 pContainedObject
= LIST_ENTRY (pEntry
, WINE_CONTAINER_ENTRY
, entry
);
826 /* get object from loader and then release it */
827 if (SUCCEEDED(IDirectMusicLoader_GetObject (pLoader
, &pContainedObject
->Desc
, &IID_IDirectMusicObject
, (LPVOID
*)&pObject
))) {
828 pContainedObject
->pObject
= pObject
; /* for final release */
829 IDirectMusicObject_Release (pObject
); /* we don't really need this one */
831 WARN(": failed to load contained object\n");
832 result
= DMUS_S_PARTIALLOAD
;
837 IDirectMusicLoader_Release (pLoader
); /* release loader */
840 /* DEBUG: dumps whole container object tree: */
841 if (TRACE_ON(dmloader
)) {
843 LPWINE_CONTAINER_ENTRY tmpEntry
;
844 struct list
*listEntry
;
846 TRACE("*** IDirectMusicContainer (%p) ***\n", This
->ContainerVtbl
);
847 TRACE(" - Objects:\n");
848 LIST_FOR_EACH (listEntry
, This
->pContainedObjects
) {
849 tmpEntry
= LIST_ENTRY( listEntry
, WINE_CONTAINER_ENTRY
, entry
);
850 TRACE(" - Object[%i]:\n", r
);
851 TRACE(" - wszAlias: %s\n", debugstr_w(tmpEntry
->wszAlias
));
852 TRACE(" - Object descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC(&tmpEntry
->Desc
));
861 HRESULT WINAPI
IDirectMusicContainerImpl_IPersistStream_Save (LPPERSISTSTREAM iface
, IStream
* pStm
, BOOL fClearDirty
) {
862 ERR(": should not be needed\n");
866 HRESULT WINAPI
IDirectMusicContainerImpl_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface
, ULARGE_INTEGER
* pcbSize
) {
867 ERR(": should not be needed\n");
871 static const IPersistStreamVtbl DirectMusicContainer_PersistStream_Vtbl
= {
872 IDirectMusicContainerImpl_IPersistStream_QueryInterface
,
873 IDirectMusicContainerImpl_IPersistStream_AddRef
,
874 IDirectMusicContainerImpl_IPersistStream_Release
,
875 IDirectMusicContainerImpl_IPersistStream_GetClassID
,
876 IDirectMusicContainerImpl_IPersistStream_IsDirty
,
877 IDirectMusicContainerImpl_IPersistStream_Load
,
878 IDirectMusicContainerImpl_IPersistStream_Save
,
879 IDirectMusicContainerImpl_IPersistStream_GetSizeMax
882 /* for ClassFactory */
883 HRESULT WINAPI
DMUSIC_CreateDirectMusicContainerImpl (LPCGUID lpcGUID
, LPVOID
* ppobj
, LPUNKNOWN pUnkOuter
) {
884 IDirectMusicContainerImpl
* obj
;
886 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicContainerImpl
));
889 return E_OUTOFMEMORY
;
891 obj
->ContainerVtbl
= &DirectMusicContainer_Container_Vtbl
;
892 obj
->ObjectVtbl
= &DirectMusicContainer_Object_Vtbl
;
893 obj
->PersistStreamVtbl
= &DirectMusicContainer_PersistStream_Vtbl
;
894 obj
->dwRef
= 0; /* will be inited by QueryInterface */
895 obj
->pContainedObjects
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(struct list
));
896 list_init (obj
->pContainedObjects
);
898 /* increase number of instances */
899 InterlockedIncrement (&dwDirectMusicContainer
);
901 return IDirectMusicContainerImpl_IDirectMusicContainer_QueryInterface ((LPDIRECTMUSICCONTAINER
)&obj
->ContainerVtbl
, lpcGUID
, ppobj
);
904 HRESULT WINAPI
DMUSIC_DestroyDirectMusicContainerImpl (LPDIRECTMUSICCONTAINER iface
) {
905 ICOM_THIS_MULTI(IDirectMusicContainerImpl
, ContainerVtbl
, iface
);
906 LPDIRECTMUSICLOADER pLoader
;
907 LPDIRECTMUSICGETLOADER pGetLoader
;
909 LPWINE_CONTAINER_ENTRY pContainedObject
;
911 /* get loader (from stream we loaded from) */
912 TRACE(": getting loader\n");
913 IStream_QueryInterface (This
->pStream
, &IID_IDirectMusicGetLoader
, (LPVOID
*)&pGetLoader
);
914 IDirectMusicGetLoader_GetLoader (pGetLoader
, &pLoader
);
915 IDirectMusicGetLoader_Release (pGetLoader
);
917 /* release objects from loader's cache (if appropriate) */
918 TRACE(": releasing objects from loader's cache\n");
919 LIST_FOR_EACH (pEntry
, This
->pContainedObjects
) {
920 pContainedObject
= LIST_ENTRY (pEntry
, WINE_CONTAINER_ENTRY
, entry
);
921 /* my tests indicate that container releases objects *only*
922 if they were loaded at it's load-time (makes sense, it doesn't
923 have pointers to objects otherwise); BTW: native container seems
924 ti ignore the flags (I won't) */
925 if (pContainedObject
->pObject
&& !(pContainedObject
->dwFlags
& DMUS_CONTAINED_OBJF_KEEP
)) {
926 /* flags say it shouldn't be kept in loader's cache */
927 IDirectMusicLoader_ReleaseObject (pLoader
, pContainedObject
->pObject
);
930 IDirectMusicLoader_Release (pLoader
);
932 /* release stream we loaded from */
933 IStream_Release (This
->pStream
);
935 /* FIXME: release allocated entries */
937 /* decrease number of instances */
938 InterlockedDecrement (&dwDirectMusicContainer
);