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