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