Properly implement DllCanUnloadNow ref counting.
[wine] / dlls / dswave / dswave_main.c
1 /* DirectMusic Wave Main
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 <stdio.h>
21
22 #include "dswave_private.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(dswave);
25
26 LONG DSWAVE_refCount = 0;
27
28 typedef struct {
29     IClassFactoryVtbl          *lpVtbl;
30 } IClassFactoryImpl;
31
32 /******************************************************************
33  *              DirectMusicWave ClassFactory
34  */
35 static HRESULT WINAPI WaveCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
36         FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
37
38         if (ppobj == NULL) return E_POINTER;
39         
40         return E_NOINTERFACE;
41 }
42
43 static ULONG WINAPI WaveCF_AddRef(LPCLASSFACTORY iface) {
44         DSWAVE_LockModule();
45
46         return 2; /* non-heap based object */
47 }
48
49 static ULONG WINAPI WaveCF_Release(LPCLASSFACTORY iface) {
50         DSWAVE_UnlockModule();
51
52         return 1; /* non-heap based object */
53 }
54
55 static HRESULT WINAPI WaveCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
56         TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
57         
58         return DMUSIC_CreateDirectMusicWaveImpl (riid, ppobj, pOuter);
59 }
60
61 static HRESULT WINAPI WaveCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
62         TRACE("(%d)\n", dolock);
63
64         if (dolock)
65                 DSWAVE_LockModule();
66         else
67                 DSWAVE_UnlockModule();
68         
69         return S_OK;
70 }
71
72 static IClassFactoryVtbl WaveCF_Vtbl = {
73         WaveCF_QueryInterface,
74         WaveCF_AddRef,
75         WaveCF_Release,
76         WaveCF_CreateInstance,
77         WaveCF_LockServer
78 };
79
80 static IClassFactoryImpl Wave_CF = {&WaveCF_Vtbl};
81
82 /******************************************************************
83  *              DllMain
84  *
85  *
86  */
87 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
88         if (fdwReason == DLL_PROCESS_ATTACH) {
89             DisableThreadLibraryCalls(hinstDLL);
90                 /* FIXME: Initialisation */
91         } else if (fdwReason == DLL_PROCESS_DETACH) {
92                 /* FIXME: Cleanup */
93         }
94
95         return TRUE;
96 }
97
98
99 /******************************************************************
100  *              DllCanUnloadNow (DSWAVE.1)
101  *
102  *
103  */
104 HRESULT WINAPI DSWAVE_DllCanUnloadNow(void) {
105         return DSWAVE_refCount != 0 ? S_FALSE : S_OK;
106 }
107
108
109 /******************************************************************
110  *              DllGetClassObject (DSWAVE.2)
111  *
112  *
113  */
114 HRESULT WINAPI DSWAVE_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv) {
115         TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
116         if (IsEqualCLSID (rclsid, &CLSID_DirectSoundWave) && IsEqualIID (riid, &IID_IClassFactory)) {
117                 *ppv = (LPVOID) &Wave_CF;
118                 IClassFactory_AddRef((IClassFactory*)*ppv);
119                 return S_OK;
120         }
121         
122     WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
123     return CLASS_E_CLASSNOTAVAILABLE;
124 }
125
126 /******************************************************************
127  *              Helper functions
128  *
129  *
130  */
131 /* check whether the given DWORD is even (return 0) or odd (return 1) */
132 int even_or_odd (DWORD number) {
133         return (number & 0x1); /* basically, check if bit 0 is set ;) */
134 }
135
136 /* FOURCC to string conversion for debug messages */
137 const char *debugstr_fourcc (DWORD fourcc) {
138     if (!fourcc) return "'null'";
139     return wine_dbg_sprintf ("\'%c%c%c%c\'",
140                 (char)(fourcc), (char)(fourcc >> 8),
141         (char)(fourcc >> 16), (char)(fourcc >> 24));
142 }
143
144 /* DMUS_VERSION struct to string conversion for debug messages */
145 const char *debugstr_dmversion (LPDMUS_VERSION version) {
146         if (!version) return "'null'";
147         return wine_dbg_sprintf ("\'%i,%i,%i,%i\'",
148                 (int)((version->dwVersionMS && 0xFFFF0000) >> 8), (int)(version->dwVersionMS && 0x0000FFFF), 
149                 (int)((version->dwVersionLS && 0xFFFF0000) >> 8), (int)(version->dwVersionLS && 0x0000FFFF));
150 }
151
152 /* returns name of given GUID */
153 const char *debugstr_dmguid (const GUID *id) {
154         static const guid_info guids[] = {
155                 /* CLSIDs */
156                 GE(CLSID_AudioVBScript),
157                 GE(CLSID_DirectMusic),
158                 GE(CLSID_DirectMusicAudioPath),
159                 GE(CLSID_DirectMusicAudioPathConfig),
160                 GE(CLSID_DirectMusicAuditionTrack),
161                 GE(CLSID_DirectMusicBand),
162                 GE(CLSID_DirectMusicBandTrack),
163                 GE(CLSID_DirectMusicChordMapTrack),
164                 GE(CLSID_DirectMusicChordMap),
165                 GE(CLSID_DirectMusicChordTrack),
166                 GE(CLSID_DirectMusicCollection),
167                 GE(CLSID_DirectMusicCommandTrack),
168                 GE(CLSID_DirectMusicComposer),
169                 GE(CLSID_DirectMusicContainer),
170                 GE(CLSID_DirectMusicGraph),
171                 GE(CLSID_DirectMusicLoader),
172                 GE(CLSID_DirectMusicLyricsTrack),
173                 GE(CLSID_DirectMusicMarkerTrack),
174                 GE(CLSID_DirectMusicMelodyFormulationTrack),
175                 GE(CLSID_DirectMusicMotifTrack),
176                 GE(CLSID_DirectMusicMuteTrack),
177                 GE(CLSID_DirectMusicParamControlTrack),
178                 GE(CLSID_DirectMusicPatternTrack),
179                 GE(CLSID_DirectMusicPerformance),
180                 GE(CLSID_DirectMusicScript),
181                 GE(CLSID_DirectMusicScriptAutoImpSegment),
182                 GE(CLSID_DirectMusicScriptAutoImpPerformance),
183                 GE(CLSID_DirectMusicScriptAutoImpSegmentState),
184                 GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig),
185                 GE(CLSID_DirectMusicScriptAutoImpAudioPath),
186                 GE(CLSID_DirectMusicScriptAutoImpSong),
187                 GE(CLSID_DirectMusicScriptSourceCodeLoader),
188                 GE(CLSID_DirectMusicScriptTrack),
189                 GE(CLSID_DirectMusicSection),
190                 GE(CLSID_DirectMusicSegment),
191                 GE(CLSID_DirectMusicSegmentState),
192                 GE(CLSID_DirectMusicSegmentTriggerTrack),
193                 GE(CLSID_DirectMusicSegTriggerTrack),
194                 GE(CLSID_DirectMusicSeqTrack),
195                 GE(CLSID_DirectMusicSignPostTrack),
196                 GE(CLSID_DirectMusicSong),
197                 GE(CLSID_DirectMusicStyle),
198                 GE(CLSID_DirectMusicStyleTrack),
199                 GE(CLSID_DirectMusicSynth),
200                 GE(CLSID_DirectMusicSynthSink),
201                 GE(CLSID_DirectMusicSysExTrack),
202                 GE(CLSID_DirectMusicTemplate),
203                 GE(CLSID_DirectMusicTempoTrack),
204                 GE(CLSID_DirectMusicTimeSigTrack),
205                 GE(CLSID_DirectMusicWaveTrack),
206                 GE(CLSID_DirectSoundWave),
207                 /* IIDs */
208                 GE(IID_IDirectMusic),
209                 GE(IID_IDirectMusic2),
210                 GE(IID_IDirectMusic8),
211                 GE(IID_IDirectMusicAudioPath),
212                 GE(IID_IDirectMusicBand),
213                 GE(IID_IDirectMusicBuffer),
214                 GE(IID_IDirectMusicChordMap),
215                 GE(IID_IDirectMusicCollection),
216                 GE(IID_IDirectMusicComposer),
217                 GE(IID_IDirectMusicContainer),
218                 GE(IID_IDirectMusicDownload),
219                 GE(IID_IDirectMusicDownloadedInstrument),
220                 GE(IID_IDirectMusicGetLoader),
221                 GE(IID_IDirectMusicGraph),
222                 GE(IID_IDirectMusicInstrument),
223                 GE(IID_IDirectMusicLoader),
224                 GE(IID_IDirectMusicLoader8),
225                 GE(IID_IDirectMusicObject),
226                 GE(IID_IDirectMusicPatternTrack),
227                 GE(IID_IDirectMusicPerformance),
228                 GE(IID_IDirectMusicPerformance2),
229                 GE(IID_IDirectMusicPerformance8),
230                 GE(IID_IDirectMusicPort),
231                 GE(IID_IDirectMusicPortDownload),
232                 GE(IID_IDirectMusicScript),
233                 GE(IID_IDirectMusicSegment),
234                 GE(IID_IDirectMusicSegment2),
235                 GE(IID_IDirectMusicSegment8),
236                 GE(IID_IDirectMusicSegmentState),
237                 GE(IID_IDirectMusicSegmentState8),
238                 GE(IID_IDirectMusicStyle),
239                 GE(IID_IDirectMusicStyle8),
240                 GE(IID_IDirectMusicSynth),
241                 GE(IID_IDirectMusicSynth8),
242                 GE(IID_IDirectMusicSynthSink),
243                 GE(IID_IDirectMusicThru),
244                 GE(IID_IDirectMusicTool),
245                 GE(IID_IDirectMusicTool8),
246                 GE(IID_IDirectMusicTrack),
247                 GE(IID_IDirectMusicTrack8),
248                 GE(IID_IUnknown),
249                 GE(IID_IPersistStream),
250                 GE(IID_IStream),
251                 GE(IID_IClassFactory),
252                 /* GUIDs */
253                 GE(GUID_DirectMusicAllTypes),
254                 GE(GUID_NOTIFICATION_CHORD),
255                 GE(GUID_NOTIFICATION_COMMAND),
256                 GE(GUID_NOTIFICATION_MEASUREANDBEAT),
257                 GE(GUID_NOTIFICATION_PERFORMANCE),
258                 GE(GUID_NOTIFICATION_RECOMPOSE),
259                 GE(GUID_NOTIFICATION_SEGMENT),
260                 GE(GUID_BandParam),
261                 GE(GUID_ChordParam),
262                 GE(GUID_CommandParam),
263                 GE(GUID_CommandParam2),
264                 GE(GUID_CommandParamNext),
265                 GE(GUID_IDirectMusicBand),
266                 GE(GUID_IDirectMusicChordMap),
267                 GE(GUID_IDirectMusicStyle),
268                 GE(GUID_MuteParam),
269                 GE(GUID_Play_Marker),
270                 GE(GUID_RhythmParam),
271                 GE(GUID_TempoParam),
272                 GE(GUID_TimeSignature),
273                 GE(GUID_Valid_Start_Time),
274                 GE(GUID_Clear_All_Bands),
275                 GE(GUID_ConnectToDLSCollection),
276                 GE(GUID_Disable_Auto_Download),
277                 GE(GUID_DisableTempo),
278                 GE(GUID_DisableTimeSig),
279                 GE(GUID_Download),
280                 GE(GUID_DownloadToAudioPath),
281                 GE(GUID_Enable_Auto_Download),
282                 GE(GUID_EnableTempo),
283                 GE(GUID_EnableTimeSig),
284                 GE(GUID_IgnoreBankSelectForGM),
285                 GE(GUID_SeedVariations),
286                 GE(GUID_StandardMIDIFile),
287                 GE(GUID_Unload),
288                 GE(GUID_UnloadFromAudioPath),
289                 GE(GUID_Variations),
290                 GE(GUID_PerfMasterTempo),
291                 GE(GUID_PerfMasterVolume),
292                 GE(GUID_PerfMasterGrooveLevel),
293                 GE(GUID_PerfAutoDownload),
294                 GE(GUID_DefaultGMCollection),
295                 GE(GUID_Synth_Default),
296                 GE(GUID_Buffer_Reverb),
297                 GE(GUID_Buffer_EnvReverb),
298                 GE(GUID_Buffer_Stereo),
299                 GE(GUID_Buffer_3D_Dry),
300                 GE(GUID_Buffer_Mono),
301                 GE(GUID_DMUS_PROP_GM_Hardware),
302                 GE(GUID_DMUS_PROP_GS_Capable),
303                 GE(GUID_DMUS_PROP_GS_Hardware),
304                 GE(GUID_DMUS_PROP_DLS1),
305                 GE(GUID_DMUS_PROP_DLS2),
306                 GE(GUID_DMUS_PROP_Effects),
307                 GE(GUID_DMUS_PROP_INSTRUMENT2),
308                 GE(GUID_DMUS_PROP_LegacyCaps),
309                 GE(GUID_DMUS_PROP_MemorySize),
310                 GE(GUID_DMUS_PROP_SampleMemorySize),
311                 GE(GUID_DMUS_PROP_SamplePlaybackRate),
312                 GE(GUID_DMUS_PROP_SetSynthSink),
313                 GE(GUID_DMUS_PROP_SinkUsesDSound),
314                 GE(GUID_DMUS_PROP_SynthSink_DSOUND),
315                 GE(GUID_DMUS_PROP_SynthSink_WAVE),
316                 GE(GUID_DMUS_PROP_Volume),
317                 GE(GUID_DMUS_PROP_WavesReverb),
318                 GE(GUID_DMUS_PROP_WriteLatency),
319                 GE(GUID_DMUS_PROP_WritePeriod),
320                 GE(GUID_DMUS_PROP_XG_Capable),
321                 GE(GUID_DMUS_PROP_XG_Hardware)
322         };
323
324         unsigned int i;
325
326         if (!id) return "(null)";
327
328         for (i = 0; i < sizeof(guids)/sizeof(guids[0]); i++) {
329                 if (IsEqualGUID(id, &guids[i].guid))
330                         return guids[i].name;
331         }
332         /* if we didn't find it, act like standard debugstr_guid */     
333         return debugstr_guid(id);
334 }       
335
336 /* returns name of given error code */
337 const char *debugstr_dmreturn (DWORD code) {
338         static const flag_info codes[] = {
339                 FE(S_OK),
340                 FE(S_FALSE),
341                 FE(DMUS_S_PARTIALLOAD),
342                 FE(DMUS_S_PARTIALDOWNLOAD),
343                 FE(DMUS_S_REQUEUE),
344                 FE(DMUS_S_FREE),
345                 FE(DMUS_S_END),
346                 FE(DMUS_S_STRING_TRUNCATED),
347                 FE(DMUS_S_LAST_TOOL),
348                 FE(DMUS_S_OVER_CHORD),
349                 FE(DMUS_S_UP_OCTAVE),
350                 FE(DMUS_S_DOWN_OCTAVE),
351                 FE(DMUS_S_NOBUFFERCONTROL),
352                 FE(DMUS_S_GARBAGE_COLLECTED),
353                 FE(DMUS_E_DRIVER_FAILED),
354                 FE(DMUS_E_PORTS_OPEN),
355                 FE(DMUS_E_DEVICE_IN_USE),
356                 FE(DMUS_E_INSUFFICIENTBUFFER),
357                 FE(DMUS_E_BUFFERNOTSET),
358                 FE(DMUS_E_BUFFERNOTAVAILABLE),
359                 FE(DMUS_E_NOTADLSCOL),
360                 FE(DMUS_E_INVALIDOFFSET),
361                 FE(DMUS_E_ALREADY_LOADED),
362                 FE(DMUS_E_INVALIDPOS),
363                 FE(DMUS_E_INVALIDPATCH),
364                 FE(DMUS_E_CANNOTSEEK),
365                 FE(DMUS_E_CANNOTWRITE),
366                 FE(DMUS_E_CHUNKNOTFOUND),
367                 FE(DMUS_E_INVALID_DOWNLOADID),
368                 FE(DMUS_E_NOT_DOWNLOADED_TO_PORT),
369                 FE(DMUS_E_ALREADY_DOWNLOADED),
370                 FE(DMUS_E_UNKNOWN_PROPERTY),
371                 FE(DMUS_E_SET_UNSUPPORTED),
372                 FE(DMUS_E_GET_UNSUPPORTED),
373                 FE(DMUS_E_NOTMONO),
374                 FE(DMUS_E_BADARTICULATION),
375                 FE(DMUS_E_BADINSTRUMENT),
376                 FE(DMUS_E_BADWAVELINK),
377                 FE(DMUS_E_NOARTICULATION),
378                 FE(DMUS_E_NOTPCM),
379                 FE(DMUS_E_BADWAVE),
380                 FE(DMUS_E_BADOFFSETTABLE),
381                 FE(DMUS_E_UNKNOWNDOWNLOAD),
382                 FE(DMUS_E_NOSYNTHSINK),
383                 FE(DMUS_E_ALREADYOPEN),
384                 FE(DMUS_E_ALREADYCLOSED),
385                 FE(DMUS_E_SYNTHNOTCONFIGURED),
386                 FE(DMUS_E_SYNTHACTIVE),
387                 FE(DMUS_E_CANNOTREAD),
388                 FE(DMUS_E_DMUSIC_RELEASED),
389                 FE(DMUS_E_BUFFER_EMPTY),
390                 FE(DMUS_E_BUFFER_FULL),
391                 FE(DMUS_E_PORT_NOT_CAPTURE),
392                 FE(DMUS_E_PORT_NOT_RENDER),
393                 FE(DMUS_E_DSOUND_NOT_SET),
394                 FE(DMUS_E_ALREADY_ACTIVATED),
395                 FE(DMUS_E_INVALIDBUFFER),
396                 FE(DMUS_E_WAVEFORMATNOTSUPPORTED),
397                 FE(DMUS_E_SYNTHINACTIVE),
398                 FE(DMUS_E_DSOUND_ALREADY_SET),
399                 FE(DMUS_E_INVALID_EVENT),
400                 FE(DMUS_E_UNSUPPORTED_STREAM),
401                 FE(DMUS_E_ALREADY_INITED),
402                 FE(DMUS_E_INVALID_BAND),
403                 FE(DMUS_E_TRACK_HDR_NOT_FIRST_CK),
404                 FE(DMUS_E_TOOL_HDR_NOT_FIRST_CK),
405                 FE(DMUS_E_INVALID_TRACK_HDR),
406                 FE(DMUS_E_INVALID_TOOL_HDR),
407                 FE(DMUS_E_ALL_TOOLS_FAILED),
408                 FE(DMUS_E_ALL_TRACKS_FAILED),
409                 FE(DMUS_E_NOT_FOUND),
410                 FE(DMUS_E_NOT_INIT),
411                 FE(DMUS_E_TYPE_DISABLED),
412                 FE(DMUS_E_TYPE_UNSUPPORTED),
413                 FE(DMUS_E_TIME_PAST),
414                 FE(DMUS_E_TRACK_NOT_FOUND),
415                 FE(DMUS_E_TRACK_NO_CLOCKTIME_SUPPORT),
416                 FE(DMUS_E_NO_MASTER_CLOCK),
417                 FE(DMUS_E_LOADER_NOCLASSID),
418                 FE(DMUS_E_LOADER_BADPATH),
419                 FE(DMUS_E_LOADER_FAILEDOPEN),
420                 FE(DMUS_E_LOADER_FORMATNOTSUPPORTED),
421                 FE(DMUS_E_LOADER_FAILEDCREATE),
422                 FE(DMUS_E_LOADER_OBJECTNOTFOUND),
423                 FE(DMUS_E_LOADER_NOFILENAME),
424                 FE(DMUS_E_INVALIDFILE),
425                 FE(DMUS_E_ALREADY_EXISTS),
426                 FE(DMUS_E_OUT_OF_RANGE),
427                 FE(DMUS_E_SEGMENT_INIT_FAILED),
428                 FE(DMUS_E_ALREADY_SENT),
429                 FE(DMUS_E_CANNOT_FREE),
430                 FE(DMUS_E_CANNOT_OPEN_PORT),
431                 FE(DMUS_E_CANNOT_CONVERT),
432                 FE(DMUS_E_DESCEND_CHUNK_FAIL),
433                 FE(DMUS_E_NOT_LOADED),
434                 FE(DMUS_E_SCRIPT_LANGUAGE_INCOMPATIBLE),
435                 FE(DMUS_E_SCRIPT_UNSUPPORTED_VARTYPE),
436                 FE(DMUS_E_SCRIPT_ERROR_IN_SCRIPT),
437                 FE(DMUS_E_SCRIPT_CANTLOAD_OLEAUT32),
438                 FE(DMUS_E_SCRIPT_LOADSCRIPT_ERROR),
439                 FE(DMUS_E_SCRIPT_INVALID_FILE),
440                 FE(DMUS_E_INVALID_SCRIPTTRACK),
441                 FE(DMUS_E_SCRIPT_VARIABLE_NOT_FOUND),
442                 FE(DMUS_E_SCRIPT_ROUTINE_NOT_FOUND),
443                 FE(DMUS_E_SCRIPT_CONTENT_READONLY),
444                 FE(DMUS_E_SCRIPT_NOT_A_REFERENCE),
445                 FE(DMUS_E_SCRIPT_VALUE_NOT_SUPPORTED),
446                 FE(DMUS_E_INVALID_SEGMENTTRIGGERTRACK),
447                 FE(DMUS_E_INVALID_LYRICSTRACK),
448                 FE(DMUS_E_INVALID_PARAMCONTROLTRACK),
449                 FE(DMUS_E_AUDIOVBSCRIPT_SYNTAXERROR),
450                 FE(DMUS_E_AUDIOVBSCRIPT_RUNTIMEERROR),
451                 FE(DMUS_E_AUDIOVBSCRIPT_OPERATIONFAILURE),
452                 FE(DMUS_E_AUDIOPATHS_NOT_VALID),
453                 FE(DMUS_E_AUDIOPATHS_IN_USE),
454                 FE(DMUS_E_NO_AUDIOPATH_CONFIG),
455                 FE(DMUS_E_AUDIOPATH_INACTIVE),
456                 FE(DMUS_E_AUDIOPATH_NOBUFFER),
457                 FE(DMUS_E_AUDIOPATH_NOPORT),
458                 FE(DMUS_E_NO_AUDIOPATH),
459                 FE(DMUS_E_INVALIDCHUNK),
460                 FE(DMUS_E_AUDIOPATH_NOGLOBALFXBUFFER),
461                 FE(DMUS_E_INVALID_CONTAINER_OBJECT)
462         };
463         unsigned int i;
464         for (i = 0; i < sizeof(codes)/sizeof(codes[0]); i++) {
465                 if (code == codes[i].val)
466                         return codes[i].name;
467         }
468         /* if we didn't find it, return value */
469         return wine_dbg_sprintf("0x%08lx", code);
470 }
471
472 /* generic flag-dumping function */
473 const char* debugstr_flags (DWORD flags, const flag_info* names, size_t num_names){
474         char buffer[128] = "", *ptr = &buffer[0];
475         unsigned int i, size = sizeof(buffer);
476         
477         for (i=0; i < num_names; i++)
478         {
479                 if ((flags & names[i].val) ||   /* standard flag*/
480                         ((!flags) && (!names[i].val))) { /* zero value only */
481                                 int cnt = snprintf(ptr, size, "%s ", names[i].name);
482                                 if (cnt < 0 || cnt >= size) break;
483                                 size -= cnt;
484                                 ptr += cnt;
485                 }
486         }
487         
488         return wine_dbg_sprintf("%s", buffer);
489 }
490
491 /* dump DMUS_OBJ flags */
492 const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask) {
493     static const flag_info flags[] = {
494             FE(DMUS_OBJ_OBJECT),
495             FE(DMUS_OBJ_CLASS),
496             FE(DMUS_OBJ_NAME),
497             FE(DMUS_OBJ_CATEGORY),
498             FE(DMUS_OBJ_FILENAME),
499             FE(DMUS_OBJ_FULLPATH),
500             FE(DMUS_OBJ_URL),
501             FE(DMUS_OBJ_VERSION),
502             FE(DMUS_OBJ_DATE),
503             FE(DMUS_OBJ_LOADED),
504             FE(DMUS_OBJ_MEMORY),
505             FE(DMUS_OBJ_STREAM)
506         };
507     return debugstr_flags (flagmask, flags, sizeof(flags)/sizeof(flags[0]));
508 }
509
510 /* dump whole DMUS_OBJECTDESC struct */
511 const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc) {
512         if (pDesc) {
513                 char buffer[1024] = "", *ptr = &buffer[0];
514                 
515                 ptr += sprintf(ptr, "DMUS_OBJECTDESC (%p):\n", pDesc);
516                 ptr += sprintf(ptr, " - dwSize = %ld\n", pDesc->dwSize);
517                 ptr += sprintf(ptr, " - dwValidData = %s\n", debugstr_DMUS_OBJ_FLAGS (pDesc->dwValidData));
518                 if (pDesc->dwValidData & DMUS_OBJ_CLASS) ptr += sprintf(ptr, " - guidClass = %s\n", debugstr_dmguid(&pDesc->guidClass));
519                 if (pDesc->dwValidData & DMUS_OBJ_OBJECT) ptr += sprintf(ptr, " - guidObject = %s\n", debugstr_guid(&pDesc->guidObject));
520                 if (pDesc->dwValidData & DMUS_OBJ_DATE) ptr += sprintf(ptr, " - ftDate = FIXME\n");
521                 if (pDesc->dwValidData & DMUS_OBJ_VERSION) ptr += sprintf(ptr, " - vVersion = %s\n", debugstr_dmversion(&pDesc->vVersion));
522                 if (pDesc->dwValidData & DMUS_OBJ_NAME) ptr += sprintf(ptr, " - wszName = %s\n", debugstr_w(pDesc->wszName));
523                 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) ptr += sprintf(ptr, " - wszCategory = %s\n", debugstr_w(pDesc->wszCategory));
524                 if (pDesc->dwValidData & DMUS_OBJ_FILENAME) ptr += sprintf(ptr, " - wszFileName = %s\n", debugstr_w(pDesc->wszFileName));
525                 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) ptr += sprintf(ptr, " - llMemLength = %lli\n  - pbMemData = %p\n", pDesc->llMemLength, pDesc->pbMemData);
526                 if (pDesc->dwValidData & DMUS_OBJ_STREAM) ptr += sprintf(ptr, " - pStream = %p", pDesc->pStream);
527
528                 return wine_dbg_sprintf("%s", buffer);
529         } else {
530                 return wine_dbg_sprintf("(NULL)");
531         }
532 }