Add DDCAPS_OVERLAY and DDCAPS_OVERLAYSTRETCH to GetCaps().
[wine] / dlls / dmusic / collection.c
1 /* IDirectMusicCollection Implementation
2  *
3  * Copyright (C) 2003-2004 Rok Mandeljc
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 #include "dmusic_private.h"
21
22 WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
23 WINE_DECLARE_DEBUG_CHANNEL(dmfile);
24
25 /*****************************************************************************
26  * IDirectMusicCollectionImpl implementation
27  */
28 /* IDirectMusicCollectionImpl IUnknown part: */
29 HRESULT WINAPI IDirectMusicCollectionImpl_IUnknown_QueryInterface (LPUNKNOWN iface, REFIID riid, LPVOID *ppobj) {
30         ICOM_THIS_MULTI(IDirectMusicCollectionImpl, UnknownVtbl, iface);
31         TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
32
33         if (IsEqualIID (riid, &IID_IUnknown)) {
34                 *ppobj = (LPVOID)&This->UnknownVtbl;
35                 IDirectMusicCollectionImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
36                 return S_OK;    
37         } else if (IsEqualIID (riid, &IID_IDirectMusicCollection)) {
38                 *ppobj = (LPVOID)&This->CollectionVtbl;
39                 IDirectMusicCollectionImpl_IDirectMusicCollection_AddRef ((LPDIRECTMUSICCOLLECTION)&This->CollectionVtbl);
40                 return S_OK;
41         } else if (IsEqualIID (riid, &IID_IDirectMusicObject)) {
42                 *ppobj = (LPVOID)&This->ObjectVtbl;
43                 IDirectMusicCollectionImpl_IDirectMusicObject_AddRef ((LPDIRECTMUSICOBJECT)&This->ObjectVtbl);          
44                 return S_OK;
45         } else if (IsEqualIID (riid, &IID_IPersistStream)) {
46                 *ppobj = (LPVOID)&This->PersistStreamVtbl;
47                 IDirectMusicCollectionImpl_IPersistStream_AddRef ((LPPERSISTSTREAM)&This->PersistStreamVtbl);           
48                 return S_OK;
49         }
50         
51         WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
52         return E_NOINTERFACE;
53 }
54
55 ULONG WINAPI IDirectMusicCollectionImpl_IUnknown_AddRef (LPUNKNOWN iface) {
56         ICOM_THIS_MULTI(IDirectMusicCollectionImpl, UnknownVtbl, iface);
57         ULONG refCount = InterlockedIncrement(&This->ref);
58
59         TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
60
61         DMUSIC_LockModule();
62
63         return refCount;
64 }
65
66 ULONG WINAPI IDirectMusicCollectionImpl_IUnknown_Release (LPUNKNOWN iface) {
67         ICOM_THIS_MULTI(IDirectMusicCollectionImpl, UnknownVtbl, iface);
68         ULONG refCount = InterlockedDecrement(&This->ref);
69
70         TRACE("(%p)->(ref before=%lu)\n", This, refCount + 1);
71
72         if (!refCount) {
73                 HeapFree(GetProcessHeap(), 0, This);
74         }
75
76         DMUSIC_UnlockModule();
77
78         return refCount;
79 }
80
81 IUnknownVtbl DirectMusicCollection_Unknown_Vtbl = {
82         IDirectMusicCollectionImpl_IUnknown_QueryInterface,
83         IDirectMusicCollectionImpl_IUnknown_AddRef,
84         IDirectMusicCollectionImpl_IUnknown_Release
85 };
86
87 /* IDirectMusicCollectionImpl IDirectMusicCollection part: */
88 HRESULT WINAPI IDirectMusicCollectionImpl_IDirectMusicCollection_QueryInterface (LPDIRECTMUSICCOLLECTION iface, REFIID riid, LPVOID *ppobj) {
89         ICOM_THIS_MULTI(IDirectMusicCollectionImpl, CollectionVtbl, iface);
90         return IDirectMusicCollectionImpl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
91 }
92
93 ULONG WINAPI IDirectMusicCollectionImpl_IDirectMusicCollection_AddRef (LPDIRECTMUSICCOLLECTION iface) {
94         ICOM_THIS_MULTI(IDirectMusicCollectionImpl, CollectionVtbl, iface);
95         return IDirectMusicCollectionImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
96 }
97
98 ULONG WINAPI IDirectMusicCollectionImpl_IDirectMusicCollection_Release (LPDIRECTMUSICCOLLECTION iface) {
99         ICOM_THIS_MULTI(IDirectMusicCollectionImpl, CollectionVtbl, iface);
100         return IDirectMusicCollectionImpl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
101 }
102
103 /* IDirectMusicCollection Interface follow: */
104 HRESULT WINAPI IDirectMusicCollectionImpl_IDirectMusicCollection_GetInstrument (LPDIRECTMUSICCOLLECTION iface, DWORD dwPatch, IDirectMusicInstrument** ppInstrument) {
105         ICOM_THIS_MULTI(IDirectMusicCollectionImpl, CollectionVtbl, iface);
106         DMUS_PRIVATE_INSTRUMENTENTRY *tmpEntry;
107         struct list *listEntry;
108         DWORD dwInstPatch;
109
110         TRACE("(%p, %ld, %p)\n", This, dwPatch, ppInstrument);
111         
112         LIST_FOR_EACH (listEntry, &This->Instruments) {
113                 tmpEntry = LIST_ENTRY(listEntry, DMUS_PRIVATE_INSTRUMENTENTRY, entry);
114                 IDirectMusicInstrument_GetPatch (tmpEntry->pInstrument, &dwInstPatch);
115                 if (dwPatch == dwInstPatch) {
116                         *ppInstrument = (LPDIRECTMUSICINSTRUMENT)tmpEntry->pInstrument;
117                         IDirectMusicInstrument_AddRef (tmpEntry->pInstrument);
118                         IDirectMusicInstrumentImpl_Custom_Load (tmpEntry->pInstrument, This->pStm); /* load instrument before returning it */
119                         TRACE(": returning instrument %p\n", *ppInstrument);
120                         return S_OK;
121                 }
122                         
123         }
124         TRACE(": instrument not found\n");
125         
126         return DMUS_E_INVALIDPATCH;
127 }
128
129 HRESULT WINAPI IDirectMusicCollectionImpl_IDirectMusicCollection_EnumInstrument (LPDIRECTMUSICCOLLECTION iface, DWORD dwIndex, DWORD* pdwPatch, LPWSTR pwszName, DWORD dwNameLen) {
130         ICOM_THIS_MULTI(IDirectMusicCollectionImpl, CollectionVtbl, iface);
131         unsigned int r = 0;
132         DMUS_PRIVATE_INSTRUMENTENTRY *tmpEntry;
133         struct list *listEntry;
134                 
135         TRACE("(%p, %ld, %p, %p, %ld)\n", This, dwIndex, pdwPatch, pwszName, dwNameLen);
136         LIST_FOR_EACH (listEntry, &This->Instruments) {
137                 tmpEntry = LIST_ENTRY(listEntry, DMUS_PRIVATE_INSTRUMENTENTRY, entry);
138                 if (r == dwIndex) {
139                         ICOM_NAME_MULTI (IDirectMusicInstrumentImpl, InstrumentVtbl, tmpEntry->pInstrument, pInstrument);
140                         IDirectMusicInstrument_GetPatch (tmpEntry->pInstrument, pdwPatch);
141                         dwNameLen = strlenW (pInstrument->wszName);
142                         strncpyW (pwszName, pInstrument->wszName, dwNameLen);
143                         return S_OK;
144                 }
145                 r++;            
146         }
147         
148         return S_FALSE;
149 }
150
151 IDirectMusicCollectionVtbl DirectMusicCollection_Collection_Vtbl = {
152         IDirectMusicCollectionImpl_IDirectMusicCollection_QueryInterface,
153         IDirectMusicCollectionImpl_IDirectMusicCollection_AddRef,
154         IDirectMusicCollectionImpl_IDirectMusicCollection_Release,
155         IDirectMusicCollectionImpl_IDirectMusicCollection_GetInstrument,
156         IDirectMusicCollectionImpl_IDirectMusicCollection_EnumInstrument
157 };
158
159 /* IDirectMusicCollectionImpl IDirectMusicObject part: */
160 HRESULT WINAPI IDirectMusicCollectionImpl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface, REFIID riid, LPVOID *ppobj) {
161         ICOM_THIS_MULTI(IDirectMusicCollectionImpl, ObjectVtbl, iface);
162         return IDirectMusicCollectionImpl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
163 }
164
165 ULONG WINAPI IDirectMusicCollectionImpl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface) {
166         ICOM_THIS_MULTI(IDirectMusicCollectionImpl, ObjectVtbl, iface);
167         return IDirectMusicCollectionImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
168 }
169
170 ULONG WINAPI IDirectMusicCollectionImpl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface) {
171         ICOM_THIS_MULTI(IDirectMusicCollectionImpl, ObjectVtbl, iface);
172         return IDirectMusicCollectionImpl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
173 }
174
175 HRESULT WINAPI IDirectMusicCollectionImpl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
176         ICOM_THIS_MULTI(IDirectMusicCollectionImpl, ObjectVtbl, iface);
177         TRACE("(%p, %p)\n", This, pDesc);
178         /* I think we shouldn't return pointer here since then values can be changed; it'd be a mess */
179         memcpy (pDesc, This->pDesc, This->pDesc->dwSize);
180         return S_OK;
181 }
182
183 HRESULT WINAPI IDirectMusicCollectionImpl_IDirectMusicObject_SetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
184         ICOM_THIS_MULTI(IDirectMusicCollectionImpl, ObjectVtbl, iface);
185         TRACE("(%p, %p): setting descriptor:\n%s\n", This, pDesc, debugstr_DMUS_OBJECTDESC (pDesc));
186         
187         /* According to MSDN, we should copy only given values, not whole struct */     
188         if (pDesc->dwValidData & DMUS_OBJ_OBJECT)
189                 memcpy (&This->pDesc->guidObject, &pDesc->guidObject, sizeof (pDesc->guidObject));
190         if (pDesc->dwValidData & DMUS_OBJ_CLASS)
191                 memcpy (&This->pDesc->guidClass, &pDesc->guidClass, sizeof (pDesc->guidClass));         
192         if (pDesc->dwValidData & DMUS_OBJ_NAME)
193                 strncpyW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
194         if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
195                 strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);             
196         if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
197                 strncpyW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);             
198         if (pDesc->dwValidData & DMUS_OBJ_VERSION)
199                 memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion));                            
200         if (pDesc->dwValidData & DMUS_OBJ_DATE)
201                 memcpy (&This->pDesc->ftDate, &pDesc->ftDate, sizeof (pDesc->ftDate));                          
202         if (pDesc->dwValidData & DMUS_OBJ_MEMORY) {
203                 memcpy (&This->pDesc->llMemLength, &pDesc->llMemLength, sizeof (pDesc->llMemLength));                           
204                 memcpy (This->pDesc->pbMemData, pDesc->pbMemData, sizeof (pDesc->pbMemData));
205         }
206         if (pDesc->dwValidData & DMUS_OBJ_STREAM) {
207                 /* according to MSDN, we copy the stream */
208                 IStream_Clone (pDesc->pStream, &This->pDesc->pStream);  
209         }
210         
211         /* add new flags */
212         This->pDesc->dwValidData |= pDesc->dwValidData;
213
214         return S_OK;
215 }
216
217 HRESULT WINAPI IDirectMusicCollectionImpl_IDirectMusicObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface, LPSTREAM pStream, LPDMUS_OBJECTDESC pDesc) {
218         ICOM_THIS_MULTI(IDirectMusicCollectionImpl, ObjectVtbl, iface);
219         DMUS_PRIVATE_CHUNK Chunk;
220         DWORD StreamSize, StreamCount, ListSize[1], ListCount[1];
221         LARGE_INTEGER liMove; /* used when skipping chunks */
222
223         TRACE("(%p, %p, %p)\n", This, pStream, pDesc);
224         
225         /* FIXME: should this be determined from stream? */
226         pDesc->dwValidData |= DMUS_OBJ_CLASS;
227         memcpy (&pDesc->guidClass, &CLSID_DirectMusicCollection, sizeof(CLSID));
228         
229         IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
230         TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
231         switch (Chunk.fccID) {  
232                 case FOURCC_RIFF: {
233                         IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);                             
234                         TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
235                         StreamSize = Chunk.dwSize - sizeof(FOURCC);
236                         StreamCount = 0;
237                         if (Chunk.fccID == mmioFOURCC('D','L','S',' ')) {
238                                 TRACE_(dmfile)(": collection form\n");
239                                 do {
240                                         IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
241                                         StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
242                                         TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
243                                         switch (Chunk.fccID) {
244                                                 case FOURCC_DLID: {
245                                                         TRACE_(dmfile)(": GUID chunk\n");
246                                                         pDesc->dwValidData |= DMUS_OBJ_OBJECT;
247                                                         IStream_Read (pStream, &pDesc->guidObject, Chunk.dwSize, NULL);
248                                                         break;
249                                                 }
250                                                 case DMUS_FOURCC_VERSION_CHUNK: {
251                                                         TRACE_(dmfile)(": version chunk\n");
252                                                         pDesc->dwValidData |= DMUS_OBJ_VERSION;
253                                                         IStream_Read (pStream, &pDesc->vVersion, Chunk.dwSize, NULL);
254                                                         break;
255                                                 }
256                                                 case DMUS_FOURCC_CATEGORY_CHUNK: {
257                                                         TRACE_(dmfile)(": category chunk\n");
258                                                         pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
259                                                         IStream_Read (pStream, pDesc->wszCategory, Chunk.dwSize, NULL);
260                                                         break;
261                                                 }
262                                                 case FOURCC_LIST: {
263                                                         IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);                             
264                                                         TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
265                                                         ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
266                                                         ListCount[0] = 0;
267                                                         switch (Chunk.fccID) {
268                                                                 /* pure INFO list, such can be found in dls collections */
269                                                                 case mmioFOURCC('I','N','F','O'): {
270                                                                         TRACE_(dmfile)(": INFO list\n");
271                                                                         do {
272                                                                                 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
273                                                                                 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
274                                                                                 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
275                                                                                 switch (Chunk.fccID) {
276                                                                                         case mmioFOURCC('I','N','A','M'):{
277                                                                                                 CHAR szName[DMUS_MAX_NAME];                                                                                             
278                                                                                                 TRACE_(dmfile)(": name chunk\n");
279                                                                                                 pDesc->dwValidData |= DMUS_OBJ_NAME;
280                                                                                                 IStream_Read (pStream, szName, Chunk.dwSize, NULL);
281                                                                                                 MultiByteToWideChar (CP_ACP, 0, szName, -1, pDesc->wszName, DMUS_MAX_NAME);
282                                                                                                 if (even_or_odd(Chunk.dwSize)) {
283                                                                                                         ListCount[0] ++;
284                                                                                                         liMove.QuadPart = 1;
285                                                                                                         IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
286                                                                                                 }
287                                                                                                 break;
288                                                                                         }
289                                                                                         case mmioFOURCC('I','A','R','T'): {
290                                                                                                 TRACE_(dmfile)(": artist chunk (ignored)\n");
291                                                                                                 if (even_or_odd(Chunk.dwSize)) {
292                                                                                                         ListCount[0] ++;
293                                                                                                         Chunk.dwSize++;
294                                                                                                 }
295                                                                                                 liMove.QuadPart = Chunk.dwSize;
296                                                                                                 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
297                                                                                                 break;
298                                                                                         }
299                                                                                         case mmioFOURCC('I','C','O','P'): {
300                                                                                                 TRACE_(dmfile)(": copyright chunk (ignored)\n");
301                                                                                                 if (even_or_odd(Chunk.dwSize)) {
302                                                                                                         ListCount[0] ++;
303                                                                                                         Chunk.dwSize++;
304                                                                                                 }
305                                                                                                 liMove.QuadPart = Chunk.dwSize;
306                                                                                                 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
307                                                                                                 break;
308                                                                                         }
309                                                                                         case mmioFOURCC('I','S','B','J'): {
310                                                                                                 TRACE_(dmfile)(": subject chunk (ignored)\n");
311                                                                                                 if (even_or_odd(Chunk.dwSize)) {
312                                                                                                         ListCount[0] ++;
313                                                                                                         Chunk.dwSize++;
314                                                                                                 }
315                                                                                                 liMove.QuadPart = Chunk.dwSize;
316                                                                                                 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
317                                                                                                 break;
318                                                                                         }
319                                                                                         case mmioFOURCC('I','C','M','T'): {
320                                                                                                 TRACE_(dmfile)(": comment chunk (ignored)\n");
321                                                                                                 if (even_or_odd(Chunk.dwSize)) {
322                                                                                                         ListCount[0] ++;
323                                                                                                         Chunk.dwSize++;
324                                                                                                 }
325                                                                                                 liMove.QuadPart = Chunk.dwSize;
326                                                                                                 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
327                                                                                                 break;
328                                                                                         }
329                                                                                         default: {
330                                                                                                 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
331                                                                                                 if (even_or_odd(Chunk.dwSize)) {
332                                                                                                         ListCount[0] ++;
333                                                                                                         Chunk.dwSize++;
334                                                                                                 }
335                                                                                                 liMove.QuadPart = Chunk.dwSize;
336                                                                                                 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
337                                                                                                 break;                                          
338                                                                                         }
339                                                                                 }
340                                                                                 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
341                                                                         } while (ListCount[0] < ListSize[0]);
342                                                                         break;
343                                                                 }
344                                                                 default: {
345                                                                         TRACE_(dmfile)(": unknown (skipping)\n");
346                                                                         liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
347                                                                         IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
348                                                                         break;                                          
349                                                                 }
350                                                         }
351                                                         break;
352                                                 }       
353                                                 default: {
354                                                         TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
355                                                         liMove.QuadPart = Chunk.dwSize;
356                                                         IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
357                                                         break;                                          
358                                                 }
359                                         }
360                                         TRACE_(dmfile)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount, StreamSize);
361                                 } while (StreamCount < StreamSize);
362                         } else {
363                                 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
364                                 liMove.QuadPart = StreamSize;
365                                 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
366                                 return E_FAIL;
367                         }
368                 
369                         TRACE_(dmfile)(": reading finished\n");
370                         break;
371                 }
372                 default: {
373                         TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
374                         liMove.QuadPart = Chunk.dwSize;
375                         IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
376                         return DMUS_E_INVALIDFILE;
377                 }
378         }       
379         
380         TRACE(": returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (pDesc));
381         
382         return S_OK;
383 }
384
385 IDirectMusicObjectVtbl DirectMusicCollection_Object_Vtbl = {
386         IDirectMusicCollectionImpl_IDirectMusicObject_QueryInterface,
387         IDirectMusicCollectionImpl_IDirectMusicObject_AddRef,
388         IDirectMusicCollectionImpl_IDirectMusicObject_Release,
389         IDirectMusicCollectionImpl_IDirectMusicObject_GetDescriptor,
390         IDirectMusicCollectionImpl_IDirectMusicObject_SetDescriptor,
391         IDirectMusicCollectionImpl_IDirectMusicObject_ParseDescriptor
392 };
393
394 /* IDirectMusicCollectionImpl IPersistStream part: */
395 HRESULT WINAPI IDirectMusicCollectionImpl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
396         ICOM_THIS_MULTI(IDirectMusicCollectionImpl, PersistStreamVtbl, iface);
397         return IDirectMusicCollectionImpl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
398 }
399
400 ULONG WINAPI IDirectMusicCollectionImpl_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
401         ICOM_THIS_MULTI(IDirectMusicCollectionImpl, PersistStreamVtbl, iface);
402         return IDirectMusicCollectionImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
403 }
404
405 ULONG WINAPI IDirectMusicCollectionImpl_IPersistStream_Release (LPPERSISTSTREAM iface) {
406         ICOM_THIS_MULTI(IDirectMusicCollectionImpl, PersistStreamVtbl, iface);
407         return IDirectMusicCollectionImpl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
408 }
409
410 HRESULT WINAPI IDirectMusicCollectionImpl_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
411         return E_NOTIMPL;
412 }
413
414 HRESULT WINAPI IDirectMusicCollectionImpl_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
415         return E_NOTIMPL;
416 }
417
418 HRESULT WINAPI IDirectMusicCollectionImpl_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
419         ICOM_THIS_MULTI(IDirectMusicCollectionImpl, PersistStreamVtbl, iface);
420
421         DMUS_PRIVATE_CHUNK Chunk;
422         DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
423         LARGE_INTEGER liMove; /* used when skipping chunks */
424         ULARGE_INTEGER dlibCollectionPosition, dlibInstrumentPosition, dlibWavePoolPosition;
425         
426         IStream_AddRef (pStm); /* add count for later references */
427         liMove.QuadPart = 0;
428         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, &dlibCollectionPosition); /* store offset, in case it'll be needed later */
429         This->liCollectionPosition.QuadPart = dlibCollectionPosition.QuadPart;
430         This->pStm = pStm;
431         
432         IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
433         TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
434         switch (Chunk.fccID) {  
435                 case FOURCC_RIFF: {
436                         IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);                                
437                         TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
438                         StreamSize = Chunk.dwSize - sizeof(FOURCC);
439                         StreamCount = 0;
440                         switch (Chunk.fccID) {
441                                 case FOURCC_DLS: {
442                                         TRACE_(dmfile)(": collection form\n");
443                                         do {
444                                                 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
445                                                 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
446                                                 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
447                                                 switch (Chunk.fccID) {
448                                                         case FOURCC_COLH: {
449                                                                 TRACE_(dmfile)(": collection header chunk\n");
450                                                                 This->pHeader = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, Chunk.dwSize);
451                                                                 IStream_Read (pStm, This->pHeader, Chunk.dwSize, NULL);
452                                                                 break;                                                          
453                                                         }
454                                                         case FOURCC_DLID: {
455                                                                 TRACE_(dmfile)(": DLID (GUID) chunk\n");
456                                                                 This->pDesc->dwValidData |= DMUS_OBJ_OBJECT;
457                                                                 IStream_Read (pStm, &This->pDesc->guidObject, Chunk.dwSize, NULL);
458                                                                 break;
459                                                         }
460                                                         case FOURCC_VERS: {
461                                                                 TRACE_(dmfile)(": version chunk\n");
462                                                                 This->pDesc->dwValidData |= DMUS_OBJ_VERSION;
463                                                                 IStream_Read (pStm, &This->pDesc->vVersion, Chunk.dwSize, NULL);
464                                                                 break;
465                                                         }
466                                                         case FOURCC_PTBL: {
467                                                                 TRACE_(dmfile)(": pool table chunk\n");
468                                                                 This->pPoolTable = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(POOLTABLE));
469                                                                 IStream_Read (pStm, This->pPoolTable, sizeof(POOLTABLE), NULL);
470                                                                 Chunk.dwSize -= sizeof(POOLTABLE);
471                                                                 This->pPoolCues = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, This->pPoolTable->cCues*sizeof(POOLCUE));
472                                                                 IStream_Read (pStm, This->pPoolCues, Chunk.dwSize, NULL);
473                                                                 break;
474                                                         }
475                                                         case FOURCC_LIST: {
476                                                                 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);                                
477                                                                 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
478                                                                 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
479                                                                 ListCount[0] = 0;
480                                                                 switch (Chunk.fccID) {
481                                                                         case mmioFOURCC('I','N','F','O'): {
482                                                                                 TRACE_(dmfile)(": INFO list\n");
483                                                                                 do {
484                                                                                         IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
485                                                                                         ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
486                                                                                         TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
487                                                                                         switch (Chunk.fccID) {
488                                                                                                 case mmioFOURCC('I','N','A','M'): {
489                                                                                                         CHAR szName[DMUS_MAX_NAME];
490                                                                                                         TRACE_(dmfile)(": name chunk\n");
491                                                                                                         This->pDesc->dwValidData |= DMUS_OBJ_NAME;
492                                                                                                         IStream_Read (pStm, szName, Chunk.dwSize, NULL);
493                                                                                                         MultiByteToWideChar (CP_ACP, 0, szName, -1, This->pDesc->wszName, DMUS_MAX_NAME);
494                                                                                                         if (even_or_odd(Chunk.dwSize)) {
495                                                                                                                 ListCount[0] ++;
496                                                                                                                 liMove.QuadPart = 1;
497                                                                                                                 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
498                                                                                                         }
499                                                                                                         break;
500                                                                                                 }
501                                                                                                 case mmioFOURCC('I','A','R','T'): {
502                                                                                                         TRACE_(dmfile)(": artist chunk (ignored)\n");
503                                                                                                         if (even_or_odd(Chunk.dwSize)) {
504                                                                                                                 ListCount[0] ++;
505                                                                                                                 Chunk.dwSize++;
506                                                                                                         }
507                                                                                                         liMove.QuadPart = Chunk.dwSize;
508                                                                                                         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
509                                                                                                         break;
510                                                                                                 }
511                                                                                                 case mmioFOURCC('I','C','O','P'): {
512                                                                                                         TRACE_(dmfile)(": copyright chunk\n");
513                                                                                                         This->szCopyright = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, Chunk.dwSize);
514                                                                                                         IStream_Read (pStm, This->szCopyright, Chunk.dwSize, NULL);
515                                                                                                         if (even_or_odd(Chunk.dwSize)) {
516                                                                                                                 ListCount[0] ++;
517                                                                                                                 liMove.QuadPart = 1;
518                                                                                                                 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
519                                                                                                         }
520                                                                                                         break;
521                                                                                                 }
522                                                                                                 case mmioFOURCC('I','S','B','J'): {
523                                                                                                         TRACE_(dmfile)(": subject chunk (ignored)\n");
524                                                                                                         if (even_or_odd(Chunk.dwSize)) {
525                                                                                                                 ListCount[0] ++;
526                                                                                                                 Chunk.dwSize++;
527                                                                                                         }
528                                                                                                         liMove.QuadPart = Chunk.dwSize;
529                                                                                                         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
530                                                                                                         break;
531                                                                                                 }
532                                                                                                 case mmioFOURCC('I','C','M','T'): {
533                                                                                                         TRACE_(dmfile)(": comment chunk (ignored)\n");
534                                                                                                         if (even_or_odd(Chunk.dwSize)) {
535                                                                                                                 ListCount[0] ++;
536                                                                                                                 Chunk.dwSize++;
537                                                                                                         }
538                                                                                                         liMove.QuadPart = Chunk.dwSize;
539                                                                                                         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
540                                                                                                         break;
541                                                                                                 }
542                                                                                                 default: {
543                                                                                                         TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
544                                                                                                         if (even_or_odd(Chunk.dwSize)) {
545                                                                                                                 ListCount[0] ++;
546                                                                                                                 Chunk.dwSize++;
547                                                                                                         }
548                                                                                                         liMove.QuadPart = Chunk.dwSize;
549                                                                                                         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
550                                                                                                         break;                                          
551                                                                                                 }
552                                                                                         }
553                                                                                         TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
554                                                                                 } while (ListCount[0] < ListSize[0]);
555                                                                                 break;
556                                                                         }
557                                                                         case FOURCC_WVPL: {
558                                                                                 TRACE_(dmfile)(": wave pool list (mark & skip)\n");
559                                                                                 liMove.QuadPart = 0;
560                                                                                 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, &dlibWavePoolPosition); /* store position */
561                                                                                 This->liWavePoolTablePosition.QuadPart = dlibWavePoolPosition.QuadPart;
562                                                                                 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
563                                                                                 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
564                                                                                 break;  
565                                                                         }
566                                                                         case FOURCC_LINS: {
567                                                                                 TRACE_(dmfile)(": instruments list\n");
568                                                                                 do {
569                                                                                         IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
570                                                                                         ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
571                                                                                         TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
572                                                                                         switch (Chunk.fccID) {
573                                                                                                 case FOURCC_LIST: {
574                                                                                                         IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);                                
575                                                                                                         TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
576                                                                                                         ListSize[1] = Chunk.dwSize - sizeof(FOURCC);
577                                                                                                         ListCount[1] = 0;                                                                                                       
578                                                                                                         switch (Chunk.fccID) {
579                                                                                                                 case FOURCC_INS: {
580                                                                                                                         LPDMUS_PRIVATE_INSTRUMENTENTRY pNewInstrument = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_INSTRUMENTENTRY));
581                                                                                                                         TRACE_(dmfile)(": instrument list\n");
582                                                                                                                         DMUSIC_CreateDirectMusicInstrumentImpl (&IID_IDirectMusicInstrument, (LPVOID*)&pNewInstrument->pInstrument, NULL); /* only way to create this one... even M$ does it discretly */
583                                                                                                                         {
584                                                                                                                             ICOM_NAME_MULTI (IDirectMusicInstrumentImpl, InstrumentVtbl, pNewInstrument->pInstrument, pInstrument);
585                                                                                                                             liMove.QuadPart = 0;
586                                                                                                                             IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, &dlibInstrumentPosition);
587                                                                                                                             pInstrument->liInstrumentPosition.QuadPart = dlibInstrumentPosition.QuadPart - (2*sizeof(FOURCC) + sizeof(DWORD)); /* store offset, it'll be needed later */
588
589                                                                                                                             do {
590                                                                                                                                 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
591                                                                                                                                 ListCount[1] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
592                                                                                                                                 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
593                                                                                                                                 switch (Chunk.fccID) {
594                                                                                                                                         case FOURCC_INSH: {
595                                                                                                                                                 TRACE_(dmfile)(": instrument header chunk\n");
596                                                                                                                                                 pInstrument->pHeader = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, Chunk.dwSize);
597                                                                                                                                                 IStream_Read (pStm, pInstrument->pHeader, Chunk.dwSize, NULL);
598                                                                                                                                                 break;  
599                                                                                                                                         }
600                                                                                                                                         case FOURCC_DLID: {
601                                                                                                                                                 TRACE_(dmfile)(": DLID (GUID) chunk\n");
602                                                                                                                                                 pInstrument->pInstrumentID = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, Chunk.dwSize);
603                                                                                                                                                 IStream_Read (pStm, pInstrument->pInstrumentID, Chunk.dwSize, NULL);
604                                                                                                                                                 break;
605                                                                                                                                         }
606                                                                                                                                         case FOURCC_LIST: {
607                                                                                                                                                 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);                                
608                                                                                                                                                 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
609                                                                                                                                                 ListSize[2] = Chunk.dwSize - sizeof(FOURCC);
610                                                                                                                                                 ListCount[2] = 0;
611                                                                                                                                                 switch (Chunk.fccID) {
612                                                                                                                                                         default: {
613                                                                                                                                                                 TRACE_(dmfile)(": unknown (skipping)\n");
614                                                                                                                                                                 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
615                                                                                                                                                                 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
616                                                                                                                                                                 break;                                          
617                                                                                                                                                         }
618                                                                                                                                                 }
619                                                                                                                                                 break;
620                                                                                                                                         }                               
621                                                                                                                                         default: {
622                                                                                                                                                 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
623                                                                                                                                                 liMove.QuadPart = Chunk.dwSize;
624                                                                                                                                                 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
625                                                                                                                                                 break;                                          
626                                                                                                                                         }
627                                                                                                                                 }
628                                                                                                                                 TRACE_(dmfile)(": ListCount[1] = %ld < ListSize[1] = %ld\n", ListCount[1], ListSize[1]);
629                                                                                                                             } while (ListCount[1] < ListSize[1]);
630                                                                                                                             /* DEBUG: dumps whole instrument object tree: */
631                                                                                                                             if (TRACE_ON(dmusic)) {
632                                                                                                                                 TRACE("*** IDirectMusicInstrument (%p) ***\n", pInstrument);
633                                                                                                                                 if (pInstrument->pInstrumentID)
634                                                                                                                                         TRACE(" - GUID = %s\n", debugstr_dmguid(pInstrument->pInstrumentID));
635                                                                                                                                 
636                                                                                                                                 TRACE(" - Instrument header:\n");
637                                                                                                                                 TRACE("    - cRegions: %ld\n", pInstrument->pHeader->cRegions);
638                                                                                                                                 TRACE("    - Locale:\n");
639                                                                                                                                 TRACE("       - ulBank: %ld\n", pInstrument->pHeader->Locale.ulBank);
640                                                                                                                                 TRACE("       - ulInstrument: %ld\n", pInstrument->pHeader->Locale.ulInstrument);
641                                                                                                                                 TRACE("       => dwPatch: %ld\n", MIDILOCALE2Patch(&pInstrument->pHeader->Locale));             
642                                                                                                                             }
643                                                                                                                             list_add_tail (&This->Instruments, &pNewInstrument->entry);
644                                                                                                                         }
645                                                                                                                         break;
646                                                                                                                 }
647                                                                                                         }
648                                                                                                         break;
649                                                                                                 }
650                                                                                                 default: {
651                                                                                                         TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
652                                                                                                         liMove.QuadPart = Chunk.dwSize;
653                                                                                                         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
654                                                                                                         break;                                          
655                                                                                                 }
656                                                                                         }
657                                                                                         TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
658                                                                                 } while (ListCount[0] < ListSize[0]);
659                                                                                 break;
660                                                                         }
661                                                                         default: {
662                                                                                 TRACE_(dmfile)(": unknown (skipping)\n");
663                                                                                 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
664                                                                                 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
665                                                                                 break;                                          
666                                                                         }
667                                                                 }
668                                                                 break;
669                                                         }       
670                                                         default: {
671                                                                 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
672                                                                 liMove.QuadPart = Chunk.dwSize;
673                                                                 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
674                                                                 break;                                          
675                                                         }
676                                                 }
677                                                 TRACE_(dmfile)(": StreamCount = %ld < StreamSize = %ld\n", StreamCount, StreamSize);
678                                         } while (StreamCount < StreamSize);
679                                         break;
680                                 }
681                                 default: {
682                                         TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
683                                         liMove.QuadPart = StreamSize;
684                                         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
685                                         return E_FAIL;
686                                 }
687                         }
688                         TRACE_(dmfile)(": reading finished\n");
689                         break;
690                 }
691                 default: {
692                         TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
693                         liMove.QuadPart = Chunk.dwSize;
694                         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
695                         return E_FAIL;
696                 }
697         }
698
699         /* DEBUG: dumps whole collection object tree: */
700         if (TRACE_ON(dmusic)) {
701                 int r = 0;
702                 DMUS_PRIVATE_INSTRUMENTENTRY *tmpEntry;
703                 struct list *listEntry;
704
705                 TRACE("*** IDirectMusicCollection (%p) ***\n", This->CollectionVtbl);
706                 if (This->pDesc->dwValidData & DMUS_OBJ_OBJECT)
707                         TRACE(" - GUID = %s\n", debugstr_dmguid(&This->pDesc->guidObject));
708                 if (This->pDesc->dwValidData & DMUS_OBJ_VERSION)
709                         TRACE(" - Version = %i,%i,%i,%i\n", (This->pDesc->vVersion.dwVersionMS >> 8) && 0x0000FFFF, This->pDesc->vVersion.dwVersionMS && 0x0000FFFF, \
710                                 (This->pDesc->vVersion.dwVersionLS >> 8) && 0x0000FFFF, This->pDesc->vVersion.dwVersionLS && 0x0000FFFF);
711                 if (This->pDesc->dwValidData & DMUS_OBJ_NAME)
712                         TRACE(" - Name = %s\n", debugstr_w(This->pDesc->wszName));
713                 
714                 TRACE(" - Collection header:\n");
715                 TRACE("    - cInstruments: %ld\n", This->pHeader->cInstruments);
716                 TRACE(" - Instruments:\n");
717                 
718                 LIST_FOR_EACH (listEntry, &This->Instruments) {
719                         tmpEntry = LIST_ENTRY( listEntry, DMUS_PRIVATE_INSTRUMENTENTRY, entry );
720                         TRACE("    - Instrument[%i]: %p\n", r, tmpEntry->pInstrument);
721                         r++;
722                 }
723         }
724         
725         return S_OK;
726 }
727
728 HRESULT WINAPI IDirectMusicCollectionImpl_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
729         return E_NOTIMPL;
730 }
731
732 HRESULT WINAPI IDirectMusicCollectionImpl_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
733         return E_NOTIMPL;
734 }
735
736 IPersistStreamVtbl DirectMusicCollection_PersistStream_Vtbl = {
737         IDirectMusicCollectionImpl_IPersistStream_QueryInterface,
738         IDirectMusicCollectionImpl_IPersistStream_AddRef,
739         IDirectMusicCollectionImpl_IPersistStream_Release,
740         IDirectMusicCollectionImpl_IPersistStream_GetClassID,
741         IDirectMusicCollectionImpl_IPersistStream_IsDirty,
742         IDirectMusicCollectionImpl_IPersistStream_Load,
743         IDirectMusicCollectionImpl_IPersistStream_Save,
744         IDirectMusicCollectionImpl_IPersistStream_GetSizeMax
745 };
746
747
748 /* for ClassFactory */
749 HRESULT WINAPI DMUSIC_CreateDirectMusicCollectionImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
750         IDirectMusicCollectionImpl* obj;
751         
752         obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicCollectionImpl));
753         if (NULL == obj) {
754                 *ppobj = NULL;
755                 return E_OUTOFMEMORY;
756         }
757         obj->UnknownVtbl = &DirectMusicCollection_Unknown_Vtbl;
758         obj->CollectionVtbl = &DirectMusicCollection_Collection_Vtbl;
759         obj->ObjectVtbl = &DirectMusicCollection_Object_Vtbl;
760         obj->PersistStreamVtbl = &DirectMusicCollection_PersistStream_Vtbl;
761         obj->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
762         DM_STRUCT_INIT(obj->pDesc);
763         obj->pDesc->dwValidData |= DMUS_OBJ_CLASS;
764         memcpy (&obj->pDesc->guidClass, &CLSID_DirectMusicCollection, sizeof (CLSID));
765         obj->ref = 0; /* will be inited by QueryInterface */
766         list_init (&obj->Instruments);
767         
768         return IDirectMusicCollectionImpl_IUnknown_QueryInterface ((LPUNKNOWN)&obj->UnknownVtbl, lpcGUID, ppobj);
769 }