kernel: Load QueueUserWorkItem function dynamically.
[wine] / dlls / dmcompos / chordmap.c
1 /* IDirectMusicChordMap 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 "dmcompos_private.h"
21
22 WINE_DEFAULT_DEBUG_CHANNEL(dmcompos);
23 WINE_DECLARE_DEBUG_CHANNEL(dmfile);
24
25 /*****************************************************************************
26  * IDirectMusicChordMapImpl implementation
27  */
28 /* IDirectMusicChordMapImpl IUnknown part: */
29 static HRESULT WINAPI IDirectMusicChordMapImpl_IUnknown_QueryInterface (LPUNKNOWN iface, REFIID riid, LPVOID *ppobj) {
30         ICOM_THIS_MULTI(IDirectMusicChordMapImpl, 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                 IDirectMusicChordMapImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
36                 return S_OK;    
37         } else if (IsEqualIID (riid, &IID_IDirectMusicChordMap)) {
38                 *ppobj = (LPVOID)&This->ChordMapVtbl;
39                 IDirectMusicChordMapImpl_IDirectMusicChordMap_AddRef ((LPDIRECTMUSICCHORDMAP)&This->ChordMapVtbl);
40                 return S_OK;
41         } else if (IsEqualIID (riid, &IID_IDirectMusicObject)) {
42                 *ppobj = (LPVOID)&This->ObjectVtbl;
43                 IDirectMusicChordMapImpl_IDirectMusicObject_AddRef ((LPDIRECTMUSICOBJECT)&This->ObjectVtbl);            
44                 return S_OK;
45         } else if (IsEqualIID (riid, &IID_IPersistStream)) {
46                 *ppobj = (LPVOID)&This->PersistStreamVtbl;
47                 IDirectMusicChordMapImpl_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 IDirectMusicChordMapImpl_IUnknown_AddRef (LPUNKNOWN iface) {
56         ICOM_THIS_MULTI(IDirectMusicChordMapImpl, UnknownVtbl, iface);
57         ULONG ref = InterlockedIncrement(&This->ref);
58
59         TRACE("(%p): AddRef from %ld\n", This, ref - 1);
60         
61         DMCOMPOS_LockModule();
62         
63         return ref;
64 }
65
66 static ULONG WINAPI IDirectMusicChordMapImpl_IUnknown_Release (LPUNKNOWN iface) {
67         ICOM_THIS_MULTI(IDirectMusicChordMapImpl, UnknownVtbl, iface);
68         ULONG ref = InterlockedDecrement(&This->ref);
69
70         TRACE("(%p): ReleaseRef to %ld\n", This, ref);
71         
72         if (ref == 0) {
73                 HeapFree(GetProcessHeap(), 0, This);
74         }
75         
76         DMCOMPOS_UnlockModule();
77         
78         return ref;
79 }
80
81 static const IUnknownVtbl DirectMusicChordMap_Unknown_Vtbl = {
82         IDirectMusicChordMapImpl_IUnknown_QueryInterface,
83         IDirectMusicChordMapImpl_IUnknown_AddRef,
84         IDirectMusicChordMapImpl_IUnknown_Release
85 };
86
87 /* IDirectMusicChordMapImpl IDirectMusicChordMap part: */
88 static HRESULT WINAPI IDirectMusicChordMapImpl_IDirectMusicChordMap_QueryInterface (LPDIRECTMUSICCHORDMAP iface, REFIID riid, LPVOID *ppobj) {
89         ICOM_THIS_MULTI(IDirectMusicChordMapImpl, ChordMapVtbl, iface);
90         return IDirectMusicChordMapImpl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
91 }
92
93 ULONG WINAPI IDirectMusicChordMapImpl_IDirectMusicChordMap_AddRef (LPDIRECTMUSICCHORDMAP iface) {
94         ICOM_THIS_MULTI(IDirectMusicChordMapImpl, ChordMapVtbl, iface);
95         return IDirectMusicChordMapImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
96 }
97
98 static ULONG WINAPI IDirectMusicChordMapImpl_IDirectMusicChordMap_Release (LPDIRECTMUSICCHORDMAP iface) {
99         ICOM_THIS_MULTI(IDirectMusicChordMapImpl, ChordMapVtbl, iface);
100         return IDirectMusicChordMapImpl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
101 }
102
103 static HRESULT WINAPI IDirectMusicChordMapImpl_IDirectMusicChordMap_GetScale (LPDIRECTMUSICCHORDMAP iface, DWORD* pdwScale) {
104         ICOM_THIS_MULTI(IDirectMusicChordMapImpl, ChordMapVtbl, iface);
105         FIXME("(%p, %p): stub\n", This, pdwScale);
106         return S_OK;
107 }
108
109 static const IDirectMusicChordMapVtbl DirectMusicChordMap_ChordMap_Vtbl = {
110         IDirectMusicChordMapImpl_IDirectMusicChordMap_QueryInterface,
111         IDirectMusicChordMapImpl_IDirectMusicChordMap_AddRef,
112         IDirectMusicChordMapImpl_IDirectMusicChordMap_Release,
113         IDirectMusicChordMapImpl_IDirectMusicChordMap_GetScale
114 };
115
116 /* IDirectMusicChordMapImpl IDirectMusicObject part: */
117 static HRESULT WINAPI IDirectMusicChordMapImpl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface, REFIID riid, LPVOID *ppobj) {
118         ICOM_THIS_MULTI(IDirectMusicChordMapImpl, ObjectVtbl, iface);
119         return IDirectMusicChordMapImpl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
120 }
121
122 ULONG WINAPI IDirectMusicChordMapImpl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface) {
123         ICOM_THIS_MULTI(IDirectMusicChordMapImpl, ObjectVtbl, iface);
124         return IDirectMusicChordMapImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
125 }
126
127 static ULONG WINAPI IDirectMusicChordMapImpl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface) {
128         ICOM_THIS_MULTI(IDirectMusicChordMapImpl, ObjectVtbl, iface);
129         return IDirectMusicChordMapImpl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
130 }
131
132 static HRESULT WINAPI IDirectMusicChordMapImpl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
133         ICOM_THIS_MULTI(IDirectMusicChordMapImpl, ObjectVtbl, iface);
134         TRACE("(%p, %p)\n", This, pDesc);
135         /* I think we shouldn't return pointer here since then values can be changed; it'd be a mess */
136         memcpy (pDesc, This->pDesc, This->pDesc->dwSize);
137         return S_OK;
138 }
139
140 static HRESULT WINAPI IDirectMusicChordMapImpl_IDirectMusicObject_SetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
141         ICOM_THIS_MULTI(IDirectMusicChordMapImpl, ObjectVtbl, iface);
142         TRACE("(%p, %p): setting descriptor:\n%s\n", This, pDesc, debugstr_DMUS_OBJECTDESC (pDesc));
143         
144         /* According to MSDN, we should copy only given values, not whole struct */     
145         if (pDesc->dwValidData & DMUS_OBJ_OBJECT)
146                 memcpy (&This->pDesc->guidObject, &pDesc->guidObject, sizeof (pDesc->guidObject));
147         if (pDesc->dwValidData & DMUS_OBJ_CLASS)
148                 memcpy (&This->pDesc->guidClass, &pDesc->guidClass, sizeof (pDesc->guidClass));         
149         if (pDesc->dwValidData & DMUS_OBJ_NAME)
150                 lstrcpynW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
151         if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
152                 lstrcpynW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
153         if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
154                 lstrcpynW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
155         if (pDesc->dwValidData & DMUS_OBJ_VERSION)
156                 memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion));                            
157         if (pDesc->dwValidData & DMUS_OBJ_DATE)
158                 memcpy (&This->pDesc->ftDate, &pDesc->ftDate, sizeof (pDesc->ftDate));                          
159         if (pDesc->dwValidData & DMUS_OBJ_MEMORY) {
160                 memcpy (&This->pDesc->llMemLength, &pDesc->llMemLength, sizeof (pDesc->llMemLength));                           
161                 memcpy (This->pDesc->pbMemData, pDesc->pbMemData, sizeof (pDesc->pbMemData));
162         }
163         if (pDesc->dwValidData & DMUS_OBJ_STREAM) {
164                 /* according to MSDN, we copy the stream */
165                 IStream_Clone (pDesc->pStream, &This->pDesc->pStream);  
166         }
167         
168         /* add new flags */
169         This->pDesc->dwValidData |= pDesc->dwValidData;
170
171         return S_OK;
172 }
173
174 static HRESULT WINAPI IDirectMusicChordMapImpl_IDirectMusicObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface, LPSTREAM pStream, LPDMUS_OBJECTDESC pDesc) {
175         DMUS_PRIVATE_CHUNK Chunk;
176         DWORD StreamSize, StreamCount, ListSize[1], ListCount[1];
177         LARGE_INTEGER liMove; /* used when skipping chunks */
178
179         TRACE("(%p, %p)\n", pStream, pDesc);
180         
181         /* FIXME: should this be determined from stream? */
182         pDesc->dwValidData |= DMUS_OBJ_CLASS;
183         memcpy (&pDesc->guidClass, &CLSID_DirectMusicChordMap, sizeof(CLSID));
184         
185         IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
186         TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
187         switch (Chunk.fccID) {  
188                 case FOURCC_RIFF: {
189                         IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);                             
190                         TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
191                         StreamSize = Chunk.dwSize - sizeof(FOURCC);
192                         StreamCount = 0;
193                         if (Chunk.fccID == DMUS_FOURCC_CHORDMAP_FORM) {
194                                 TRACE_(dmfile)(": chord map form\n");
195                                 do {
196                                         IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
197                                         StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
198                                         TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
199                                         switch (Chunk.fccID) {
200                                                 case DMUS_FOURCC_GUID_CHUNK: {
201                                                         TRACE_(dmfile)(": GUID chunk\n");
202                                                         pDesc->dwValidData |= DMUS_OBJ_OBJECT;
203                                                         IStream_Read (pStream, &pDesc->guidObject, Chunk.dwSize, NULL);
204                                                         break;
205                                                 }
206                                                 case DMUS_FOURCC_VERSION_CHUNK: {
207                                                         TRACE_(dmfile)(": version chunk\n");
208                                                         pDesc->dwValidData |= DMUS_OBJ_VERSION;
209                                                         IStream_Read (pStream, &pDesc->vVersion, Chunk.dwSize, NULL);
210                                                         break;
211                                                 }
212                                                 case DMUS_FOURCC_CATEGORY_CHUNK: {
213                                                         TRACE_(dmfile)(": category chunk\n");
214                                                         pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
215                                                         IStream_Read (pStream, pDesc->wszCategory, Chunk.dwSize, NULL);
216                                                         break;
217                                                 }
218                                                 case FOURCC_LIST: {
219                                                         IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);                             
220                                                         TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
221                                                         ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
222                                                         ListCount[0] = 0;
223                                                         switch (Chunk.fccID) {
224                                                                 /* evil M$ UNFO list, which can (!?) contain INFO elements */
225                                                                 case DMUS_FOURCC_UNFO_LIST: {
226                                                                         TRACE_(dmfile)(": UNFO list\n");
227                                                                         do {
228                                                                                 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
229                                                                                 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
230                                                                                 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
231                                                                                 switch (Chunk.fccID) {
232                                                                                         /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
233                                              (though strings seem to be valid unicode) */
234                                                                                         case mmioFOURCC('I','N','A','M'):
235                                                                                         case DMUS_FOURCC_UNAM_CHUNK: {
236                                                                                                 TRACE_(dmfile)(": name chunk\n");
237                                                                                                 pDesc->dwValidData |= DMUS_OBJ_NAME;
238                                                                                                 IStream_Read (pStream, pDesc->wszName, Chunk.dwSize, NULL);
239                                                                                                 break;
240                                                                                         }
241                                                                                         case mmioFOURCC('I','A','R','T'):
242                                                                                         case DMUS_FOURCC_UART_CHUNK: {
243                                                                                                 TRACE_(dmfile)(": artist chunk (ignored)\n");
244                                                                                                 liMove.QuadPart = Chunk.dwSize;
245                                                                                                 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
246                                                                                                 break;
247                                                                                         }
248                                                                                         case mmioFOURCC('I','C','O','P'):
249                                                                                         case DMUS_FOURCC_UCOP_CHUNK: {
250                                                                                                 TRACE_(dmfile)(": copyright chunk (ignored)\n");
251                                                                                                 liMove.QuadPart = Chunk.dwSize;
252                                                                                                 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
253                                                                                                 break;
254                                                                                         }
255                                                                                         case mmioFOURCC('I','S','B','J'):
256                                                                                         case DMUS_FOURCC_USBJ_CHUNK: {
257                                                                                                 TRACE_(dmfile)(": subject chunk (ignored)\n");
258                                                                                                 liMove.QuadPart = Chunk.dwSize;
259                                                                                                 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
260                                                                                                 break;
261                                                                                         }
262                                                                                         case mmioFOURCC('I','C','M','T'):
263                                                                                         case DMUS_FOURCC_UCMT_CHUNK: {
264                                                                                                 TRACE_(dmfile)(": comment chunk (ignored)\n");
265                                                                                                 liMove.QuadPart = Chunk.dwSize;
266                                                                                                 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
267                                                                                                 break;
268                                                                                         }
269                                                                                         default: {
270                                                                                                 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
271                                                                                                 liMove.QuadPart = Chunk.dwSize;
272                                                                                                 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
273                                                                                                 break;                                          
274                                                                                         }
275                                                                                 }
276                                                                                 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
277                                                                         } while (ListCount[0] < ListSize[0]);
278                                                                         break;
279                                                                 }
280                                                                 default: {
281                                                                         TRACE_(dmfile)(": unknown (skipping)\n");
282                                                                         liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
283                                                                         IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
284                                                                         break;                                          
285                                                                 }
286                                                         }
287                                                         break;
288                                                 }       
289                                                 default: {
290                                                         TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
291                                                         liMove.QuadPart = Chunk.dwSize;
292                                                         IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
293                                                         break;                                          
294                                                 }
295                                         }
296                                         TRACE_(dmfile)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount, StreamSize);
297                                 } while (StreamCount < StreamSize);
298                         } else {
299                                 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
300                                 liMove.QuadPart = StreamSize;
301                                 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
302                                 return E_FAIL;
303                         }
304                 
305                         TRACE_(dmfile)(": reading finished\n");
306                         break;
307                 }
308                 default: {
309                         TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
310                         liMove.QuadPart = Chunk.dwSize;
311                         IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
312                         return DMUS_E_INVALIDFILE;
313                 }
314         }       
315         
316         TRACE(": returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (pDesc));
317         
318         return S_OK;
319 }
320
321 static const IDirectMusicObjectVtbl DirectMusicChordMap_Object_Vtbl = {
322         IDirectMusicChordMapImpl_IDirectMusicObject_QueryInterface,
323         IDirectMusicChordMapImpl_IDirectMusicObject_AddRef,
324         IDirectMusicChordMapImpl_IDirectMusicObject_Release,
325         IDirectMusicChordMapImpl_IDirectMusicObject_GetDescriptor,
326         IDirectMusicChordMapImpl_IDirectMusicObject_SetDescriptor,
327         IDirectMusicChordMapImpl_IDirectMusicObject_ParseDescriptor
328 };
329
330         
331 /* IDirectMusicChordMapImpl IPersistStream part: */
332 static HRESULT WINAPI IDirectMusicChordMapImpl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
333         ICOM_THIS_MULTI(IDirectMusicChordMapImpl, PersistStreamVtbl, iface);
334         return IDirectMusicChordMapImpl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
335 }
336
337 ULONG WINAPI IDirectMusicChordMapImpl_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
338         ICOM_THIS_MULTI(IDirectMusicChordMapImpl, PersistStreamVtbl, iface);
339         return IDirectMusicChordMapImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
340 }
341
342 static ULONG WINAPI IDirectMusicChordMapImpl_IPersistStream_Release (LPPERSISTSTREAM iface) {
343         ICOM_THIS_MULTI(IDirectMusicChordMapImpl, PersistStreamVtbl, iface);
344         return IDirectMusicChordMapImpl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
345 }
346
347 static HRESULT WINAPI IDirectMusicChordMapImpl_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
348         return E_NOTIMPL;
349 }
350
351 static HRESULT WINAPI IDirectMusicChordMapImpl_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
352         return E_NOTIMPL;
353 }
354
355 static HRESULT WINAPI IDirectMusicChordMapImpl_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
356         ICOM_THIS_MULTI(IDirectMusicChordMapImpl, PersistStreamVtbl, iface);
357
358         FOURCC chunkID;
359         DWORD chunkSize, StreamSize, StreamCount, ListSize[3], ListCount[3];
360         LARGE_INTEGER liMove; /* used when skipping chunks */
361
362         FIXME("(%p, %p): Loading not implemented yet\n", This, pStm);
363         IStream_Read (pStm, &chunkID, sizeof(FOURCC), NULL);
364         IStream_Read (pStm, &chunkSize, sizeof(DWORD), NULL);
365         TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (chunkID), chunkSize);
366         switch (chunkID) {      
367                 case FOURCC_RIFF: {
368                         IStream_Read (pStm, &chunkID, sizeof(FOURCC), NULL);                            
369                         TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(chunkID));
370                         StreamSize = chunkSize - sizeof(FOURCC);
371                         StreamCount = 0;
372                         switch (chunkID) {
373                                 case DMUS_FOURCC_CHORDMAP_FORM: {
374                                         TRACE_(dmfile)(": chordmap form\n");
375                                         do {
376                                                 IStream_Read (pStm, &chunkID, sizeof(FOURCC), NULL);
377                                                 IStream_Read (pStm, &chunkSize, sizeof(FOURCC), NULL);
378                                                 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + chunkSize;
379                                                 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (chunkID), chunkSize);
380                                                 switch (chunkID) {
381                                                         case DMUS_FOURCC_GUID_CHUNK: {
382                                                                 TRACE_(dmfile)(": GUID chunk\n");
383                                                                 This->pDesc->dwValidData |= DMUS_OBJ_OBJECT;
384                                                                 IStream_Read (pStm, &This->pDesc->guidObject, chunkSize, NULL);
385                                                                 break;
386                                                         }
387                                                         case DMUS_FOURCC_VERSION_CHUNK: {
388                                                                 TRACE_(dmfile)(": version chunk\n");
389                                                                 This->pDesc->dwValidData |= DMUS_OBJ_VERSION;
390                                                                 IStream_Read (pStm, &This->pDesc->vVersion, chunkSize, NULL);
391                                                                 break;
392                                                         }
393                                                         case DMUS_FOURCC_CATEGORY_CHUNK: {
394                                                                 TRACE_(dmfile)(": category chunk\n");
395                                                                 This->pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
396                                                                 IStream_Read (pStm, This->pDesc->wszCategory, chunkSize, NULL);
397                                                                 break;
398                                                         }
399                                                         case FOURCC_LIST: {
400                                                                 IStream_Read (pStm, &chunkID, sizeof(FOURCC), NULL);                            
401                                                                 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(chunkID));
402                                                                 ListSize[0] = chunkSize - sizeof(FOURCC);
403                                                                 ListCount[0] = 0;
404                                                                 switch (chunkID) {
405                                                                         case DMUS_FOURCC_UNFO_LIST: {
406                                                                                 TRACE_(dmfile)(": UNFO list\n");
407                                                                                 do {
408                                                                                         IStream_Read (pStm, &chunkID, sizeof(FOURCC), NULL);
409                                                                                         IStream_Read (pStm, &chunkSize, sizeof(FOURCC), NULL);
410                                                                                         ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + chunkSize;
411                                                                                         TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (chunkID), chunkSize);
412                                                                                         switch (chunkID) {
413                                                                                                 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
414                                               (though strings seem to be valid unicode) */
415                                                                                                 case mmioFOURCC('I','N','A','M'):
416                                                                                                 case DMUS_FOURCC_UNAM_CHUNK: {
417                                                                                                         TRACE_(dmfile)(": name chunk\n");
418                                                                                                         This->pDesc->dwValidData |= DMUS_OBJ_NAME;
419                                                                                                         IStream_Read (pStm, This->pDesc->wszName, chunkSize, NULL);
420                                                                                                         break;
421                                                                                                 }
422                                                                                                 case mmioFOURCC('I','A','R','T'):
423                                                                                                 case DMUS_FOURCC_UART_CHUNK: {
424                                                                                                         TRACE_(dmfile)(": artist chunk (ignored)\n");
425                                                                                                         liMove.QuadPart = chunkSize;
426                                                                                                         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
427                                                                                                         break;
428                                                                                                 }
429                                                                                                 case mmioFOURCC('I','C','O','P'):
430                                                                                                 case DMUS_FOURCC_UCOP_CHUNK: {
431                                                                                                         TRACE_(dmfile)(": copyright chunk (ignored)\n");
432                                                                                                         liMove.QuadPart = chunkSize;
433                                                                                                         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
434                                                                                                         break;
435                                                                                                 }
436                                                                                                 case mmioFOURCC('I','S','B','J'):
437                                                                                                 case DMUS_FOURCC_USBJ_CHUNK: {
438                                                                                                         TRACE_(dmfile)(": subject chunk (ignored)\n");
439                                                                                                         liMove.QuadPart = chunkSize;
440                                                                                                         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
441                                                                                                         break;
442                                                                                                 }
443                                                                                                 case mmioFOURCC('I','C','M','T'):
444                                                                                                 case DMUS_FOURCC_UCMT_CHUNK: {
445                                                                                                         TRACE_(dmfile)(": comment chunk (ignored)\n");
446                                                                                                         liMove.QuadPart = chunkSize;
447                                                                                                         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
448                                                                                                         break;
449                                                                                                 }
450                                                                                                 default: {
451                                                                                                         TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
452                                                                                                         liMove.QuadPart = chunkSize;
453                                                                                                         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
454                                                                                                         break;                                          
455                                                                                                 }
456                                                                                         }
457                                                                                         TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
458                                                                                 } while (ListCount[0] < ListSize[0]);
459                                                                                 break;
460                                                                         }
461                                                                         default: {
462                                                                                 TRACE_(dmfile)(": unknown (skipping)\n");
463                                                                                 liMove.QuadPart = chunkSize - sizeof(FOURCC);
464                                                                                 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
465                                                                                 break;                                          
466                                                                         }
467                                                                 }
468                                                                 break;
469                                                         }       
470                                                         default: {
471                                                                 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
472                                                                 liMove.QuadPart = chunkSize;
473                                                                 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
474                                                                 break;                                          
475                                                         }
476                                                 }
477                                                 TRACE_(dmfile)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount, StreamSize);
478                                         } while (StreamCount < StreamSize);
479                                         break;
480                                 }
481                                 default: {
482                                         TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
483                                         liMove.QuadPart = StreamSize;
484                                         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
485                                         return E_FAIL;
486                                 }
487                         }
488                         TRACE_(dmfile)(": reading finished\n");
489                         break;
490                 }
491                 default: {
492                         TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
493                         liMove.QuadPart = chunkSize;
494                         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
495                         return E_FAIL;
496                 }
497         }
498
499         return S_OK;
500 }
501
502 static HRESULT WINAPI IDirectMusicChordMapImpl_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
503         return E_NOTIMPL;
504 }
505
506 static HRESULT WINAPI IDirectMusicChordMapImpl_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
507         return E_NOTIMPL;
508 }
509
510 static const IPersistStreamVtbl DirectMusicChordMap_PersistStream_Vtbl = {
511         IDirectMusicChordMapImpl_IPersistStream_QueryInterface,
512         IDirectMusicChordMapImpl_IPersistStream_AddRef,
513         IDirectMusicChordMapImpl_IPersistStream_Release,
514         IDirectMusicChordMapImpl_IPersistStream_GetClassID,
515         IDirectMusicChordMapImpl_IPersistStream_IsDirty,
516         IDirectMusicChordMapImpl_IPersistStream_Load,
517         IDirectMusicChordMapImpl_IPersistStream_Save,
518         IDirectMusicChordMapImpl_IPersistStream_GetSizeMax
519 };
520
521 /* for ClassFactory */
522 HRESULT WINAPI DMUSIC_CreateDirectMusicChordMapImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
523         IDirectMusicChordMapImpl* obj;
524         
525         obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicChordMapImpl));
526         if (NULL == obj) {
527                 *ppobj = NULL;
528                 return E_OUTOFMEMORY;
529         }
530         obj->UnknownVtbl = &DirectMusicChordMap_Unknown_Vtbl;
531         obj->ChordMapVtbl = &DirectMusicChordMap_ChordMap_Vtbl;
532         obj->ObjectVtbl = &DirectMusicChordMap_Object_Vtbl;
533         obj->PersistStreamVtbl = &DirectMusicChordMap_PersistStream_Vtbl;
534         obj->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
535         DM_STRUCT_INIT(obj->pDesc);
536         obj->pDesc->dwValidData |= DMUS_OBJ_CLASS;
537         memcpy (&obj->pDesc->guidClass, &CLSID_DirectMusicChordMap, sizeof (CLSID));
538         obj->ref = 0; /* will be inited by QueryInterface */
539         
540         return IDirectMusicChordMapImpl_IUnknown_QueryInterface ((LPUNKNOWN)&obj->UnknownVtbl, lpcGUID, ppobj);
541 }