msvcrt: Implement _mbslwr_s.
[wine] / dlls / dmscript / dmscript_main.c
1 /* DirectMusicScript Main
2  *
3  * Copyright (C) 2003-2004 Rok Mandeljc
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License 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 "config.h"
21 #include "wine/port.h"
22
23 #include "dmscript_private.h"
24 #include "rpcproxy.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(dmscript);
27
28 static HINSTANCE instance;
29 LONG DMSCRIPT_refCount = 0;
30
31 typedef struct {
32     const IClassFactoryVtbl *lpVtbl;
33 } IClassFactoryImpl;
34
35 /******************************************************************
36  *              DirectMusicScriptAutoImplSegment ClassFactory
37  */
38 static HRESULT WINAPI ScriptAutoImplSegmentCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
39         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
40
41         if (ppobj == NULL) return E_POINTER;
42         
43         return E_NOINTERFACE;
44 }
45
46 static ULONG WINAPI ScriptAutoImplSegmentCF_AddRef(LPCLASSFACTORY iface) {
47         DMSCRIPT_LockModule();
48
49         return 2; /* non-heap based object */
50 }
51
52 static ULONG WINAPI ScriptAutoImplSegmentCF_Release(LPCLASSFACTORY iface) {
53         DMSCRIPT_UnlockModule();
54
55         return 1; /* non-heap based object */
56 }
57
58 static HRESULT WINAPI ScriptAutoImplSegmentCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
59         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
60
61         if (ppobj == NULL) return E_POINTER;
62         
63         return E_NOINTERFACE;
64 }
65
66 static HRESULT WINAPI ScriptAutoImplSegmentCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
67         TRACE("(%d)\n", dolock);
68
69         if (dolock)
70                 DMSCRIPT_LockModule();
71         else
72                 DMSCRIPT_UnlockModule();
73         
74         return S_OK;
75 }
76
77 static const IClassFactoryVtbl ScriptAutoImplSegmentCF_Vtbl = {
78         ScriptAutoImplSegmentCF_QueryInterface,
79         ScriptAutoImplSegmentCF_AddRef,
80         ScriptAutoImplSegmentCF_Release,
81         ScriptAutoImplSegmentCF_CreateInstance,
82         ScriptAutoImplSegmentCF_LockServer
83 };
84
85 static IClassFactoryImpl ScriptAutoImplSegment_CF = {&ScriptAutoImplSegmentCF_Vtbl};
86
87 /******************************************************************
88  *              DirectMusicScriptTrack ClassFactory
89  */
90 static HRESULT WINAPI ScriptTrackCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
91         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
92
93         if (ppobj == NULL) return E_POINTER;
94         
95         return E_NOINTERFACE;
96 }
97
98 static ULONG WINAPI ScriptTrackCF_AddRef(LPCLASSFACTORY iface) {
99         DMSCRIPT_LockModule();
100
101         return 2; /* non-heap based object */
102 }
103
104 static ULONG WINAPI ScriptTrackCF_Release(LPCLASSFACTORY iface) {
105         DMSCRIPT_UnlockModule();
106
107         return 1; /* non-heap based object */
108 }
109
110 static HRESULT WINAPI ScriptTrackCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
111         TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
112         return DMUSIC_CreateDirectMusicScriptTrack (riid, ppobj, pOuter);
113 }
114
115 static HRESULT WINAPI ScriptTrackCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
116         TRACE("(%d)\n", dolock);
117
118         if (dolock)
119                 DMSCRIPT_LockModule();
120         else
121                 DMSCRIPT_UnlockModule();
122         
123         return S_OK;
124 }
125
126 static const IClassFactoryVtbl ScriptTrackCF_Vtbl = {
127         ScriptTrackCF_QueryInterface,
128         ScriptTrackCF_AddRef,
129         ScriptTrackCF_Release,
130         ScriptTrackCF_CreateInstance,
131         ScriptTrackCF_LockServer
132 };
133
134 static IClassFactoryImpl ScriptTrack_CF = {&ScriptTrackCF_Vtbl};
135
136 /******************************************************************
137  *              DirectMusicAudioVBScript ClassFactory
138  */
139 static HRESULT WINAPI AudioVBScriptCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
140         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
141
142         if (ppobj == NULL) return E_POINTER;
143         
144         return E_NOINTERFACE;
145 }
146
147 static ULONG WINAPI AudioVBScriptCF_AddRef(LPCLASSFACTORY iface) {
148         DMSCRIPT_LockModule();
149
150         return 2; /* non-heap based object */
151 }
152
153 static ULONG WINAPI AudioVBScriptCF_Release(LPCLASSFACTORY iface) {
154         DMSCRIPT_UnlockModule();
155
156         return 1; /* non-heap based object */
157 }
158
159 static HRESULT WINAPI AudioVBScriptCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
160         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
161
162         if (ppobj == NULL) return E_POINTER;
163         
164         return E_NOINTERFACE;
165 }
166
167 static HRESULT WINAPI AudioVBScriptCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
168         TRACE("(%d)\n", dolock);
169
170         if (dolock)
171                 DMSCRIPT_LockModule();
172         else
173                 DMSCRIPT_UnlockModule();
174         
175         return S_OK;
176 }
177
178 static const IClassFactoryVtbl AudioVBScriptCF_Vtbl = {
179         AudioVBScriptCF_QueryInterface,
180         AudioVBScriptCF_AddRef,
181         AudioVBScriptCF_Release,
182         AudioVBScriptCF_CreateInstance,
183         AudioVBScriptCF_LockServer
184 };
185
186 static IClassFactoryImpl AudioVBScript_CF = {&AudioVBScriptCF_Vtbl};
187
188 /******************************************************************
189  *              DirectMusicScript ClassFactory
190  */
191 static HRESULT WINAPI ScriptCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
192         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
193
194         if (ppobj == NULL) return E_POINTER;
195         
196         return E_NOINTERFACE;
197 }
198
199 static ULONG WINAPI ScriptCF_AddRef(LPCLASSFACTORY iface) {
200         DMSCRIPT_LockModule();
201
202         return 2; /* non-heap based object */
203 }
204
205 static ULONG WINAPI ScriptCF_Release(LPCLASSFACTORY iface) {
206         DMSCRIPT_UnlockModule();
207
208         return 1; /* non-heap based object */
209 }
210
211 static HRESULT WINAPI ScriptCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
212         TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
213         
214         return DMUSIC_CreateDirectMusicScriptImpl (riid, ppobj, pOuter);
215 }
216
217 static HRESULT WINAPI ScriptCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
218         TRACE("(%d)\n", dolock);
219
220         if (dolock)
221                 DMSCRIPT_LockModule();
222         else
223                 DMSCRIPT_UnlockModule();
224         
225         return S_OK;
226 }
227
228 static const IClassFactoryVtbl ScriptCF_Vtbl = {
229         ScriptCF_QueryInterface,
230         ScriptCF_AddRef,
231         ScriptCF_Release,
232         ScriptCF_CreateInstance,
233         ScriptCF_LockServer
234 };
235
236 static IClassFactoryImpl Script_CF = {&ScriptCF_Vtbl};
237
238 /******************************************************************
239  *              DirectMusicScriptAutoImplPerformance ClassFactory
240  */
241 static HRESULT WINAPI ScriptAutoImplPerformanceCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
242         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
243
244         if (ppobj == NULL) return E_POINTER;
245         
246         return E_NOINTERFACE;
247 }
248
249 static ULONG WINAPI ScriptAutoImplPerformanceCF_AddRef(LPCLASSFACTORY iface) {
250         DMSCRIPT_LockModule();
251
252         return 2; /* non-heap based object */
253 }
254
255 static ULONG WINAPI ScriptAutoImplPerformanceCF_Release(LPCLASSFACTORY iface) {
256         DMSCRIPT_UnlockModule();
257
258         return 1; /* non-heap based object */
259 }
260
261 static HRESULT WINAPI ScriptAutoImplPerformanceCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
262         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
263
264         if (ppobj == NULL) return E_POINTER;
265         
266         return E_NOINTERFACE;
267 }
268
269 static HRESULT WINAPI ScriptAutoImplPerformanceCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
270         TRACE("(%d)\n", dolock);
271
272         if (dolock)
273                 DMSCRIPT_LockModule();
274         else
275                 DMSCRIPT_UnlockModule();
276         
277         return S_OK;
278 }
279
280 static const IClassFactoryVtbl ScriptAutoImplPerformanceCF_Vtbl = {
281         ScriptAutoImplPerformanceCF_QueryInterface,
282         ScriptAutoImplPerformanceCF_AddRef,
283         ScriptAutoImplPerformanceCF_Release,
284         ScriptAutoImplPerformanceCF_CreateInstance,
285         ScriptAutoImplPerformanceCF_LockServer
286 };
287
288 static IClassFactoryImpl ScriptAutoImplPerformance_CF = {&ScriptAutoImplPerformanceCF_Vtbl};
289
290 /******************************************************************
291  *              DirectMusicScriptSourceCodeLoader ClassFactory
292  */
293 static HRESULT WINAPI ScriptSourceCodeLoaderCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
294         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
295
296         if (ppobj == NULL) return E_POINTER;
297         
298         return E_NOINTERFACE;
299 }
300
301 static ULONG WINAPI ScriptSourceCodeLoaderCF_AddRef(LPCLASSFACTORY iface) {
302         DMSCRIPT_LockModule();
303
304         return 2; /* non-heap based object */
305 }
306
307 static ULONG WINAPI ScriptSourceCodeLoaderCF_Release(LPCLASSFACTORY iface) {
308         DMSCRIPT_UnlockModule();
309
310         return 1; /* non-heap based object */
311 }
312
313 static HRESULT WINAPI ScriptSourceCodeLoaderCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
314         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
315
316         if (ppobj == NULL) return E_POINTER;
317         
318         return E_NOINTERFACE;
319 }
320
321 static HRESULT WINAPI ScriptSourceCodeLoaderCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
322         TRACE("(%d)\n", dolock);
323
324         if (dolock)
325                 DMSCRIPT_LockModule();
326         else
327                 DMSCRIPT_UnlockModule();
328         
329         return S_OK;
330 }
331
332 static const IClassFactoryVtbl ScriptSourceCodeLoaderCF_Vtbl = {
333         ScriptSourceCodeLoaderCF_QueryInterface,
334         ScriptSourceCodeLoaderCF_AddRef,
335         ScriptSourceCodeLoaderCF_Release,
336         ScriptSourceCodeLoaderCF_CreateInstance,
337         ScriptSourceCodeLoaderCF_LockServer
338 };
339
340 static IClassFactoryImpl ScriptSourceCodeLoader_CF = {&ScriptSourceCodeLoaderCF_Vtbl};
341
342 /******************************************************************
343  *              DirectMusicScriptAutoImplSegmentState ClassFactory
344  */
345 static HRESULT WINAPI ScriptAutoImplSegmentStateCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
346         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
347
348         if (ppobj == NULL) return E_POINTER;
349         
350         return E_NOINTERFACE;
351 }
352
353 static ULONG WINAPI ScriptAutoImplSegmentStateCF_AddRef(LPCLASSFACTORY iface) {
354         DMSCRIPT_LockModule();
355
356         return 2; /* non-heap based object */
357 }
358
359 static ULONG WINAPI ScriptAutoImplSegmentStateCF_Release(LPCLASSFACTORY iface) {
360         DMSCRIPT_UnlockModule();
361
362         return 1; /* non-heap based object */
363 }
364
365 static HRESULT WINAPI ScriptAutoImplSegmentStateCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
366         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
367
368         if (ppobj == NULL) return E_POINTER;
369         
370         return E_NOINTERFACE;
371 }
372
373 static HRESULT WINAPI ScriptAutoImplSegmentStateCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
374         TRACE("(%d)\n", dolock);
375
376         if (dolock)
377                 DMSCRIPT_LockModule();
378         else
379                 DMSCRIPT_UnlockModule();
380         
381         return S_OK;
382 }
383
384 static const IClassFactoryVtbl ScriptAutoImplSegmentStateCF_Vtbl = {
385         ScriptAutoImplSegmentStateCF_QueryInterface,
386         ScriptAutoImplSegmentStateCF_AddRef,
387         ScriptAutoImplSegmentStateCF_Release,
388         ScriptAutoImplSegmentStateCF_CreateInstance,
389         ScriptAutoImplSegmentStateCF_LockServer
390 };
391
392 static IClassFactoryImpl ScriptAutoImplSegmentState_CF = {&ScriptAutoImplSegmentStateCF_Vtbl};
393
394 /******************************************************************
395  *              DirectMusicScriptAutoImplAudioPathConfig ClassFactory
396  */
397 static HRESULT WINAPI ScriptAutoImplAudioPathConfigCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
398         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
399
400         if (ppobj == NULL) return E_POINTER;
401         
402         return E_NOINTERFACE;
403 }
404
405 static ULONG WINAPI ScriptAutoImplAudioPathConfigCF_AddRef(LPCLASSFACTORY iface) {
406         DMSCRIPT_LockModule();
407
408         return 2; /* non-heap based object */
409 }
410
411 static ULONG WINAPI ScriptAutoImplAudioPathConfigCF_Release(LPCLASSFACTORY iface) {
412         DMSCRIPT_UnlockModule();
413
414         return 1; /* non-heap based object */
415 }
416
417 static HRESULT WINAPI ScriptAutoImplAudioPathConfigCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
418         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
419
420         if (ppobj == NULL) return E_POINTER;
421         
422         return E_NOINTERFACE;
423 }
424
425 static HRESULT WINAPI ScriptAutoImplAudioPathConfigCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
426         TRACE("(%d)\n", dolock);
427
428         if (dolock)
429                 DMSCRIPT_LockModule();
430         else
431                 DMSCRIPT_UnlockModule();
432         
433         return S_OK;
434 }
435
436 static const IClassFactoryVtbl ScriptAutoImplAudioPathConfigCF_Vtbl = {
437         ScriptAutoImplAudioPathConfigCF_QueryInterface,
438         ScriptAutoImplAudioPathConfigCF_AddRef,
439         ScriptAutoImplAudioPathConfigCF_Release,
440         ScriptAutoImplAudioPathConfigCF_CreateInstance,
441         ScriptAutoImplAudioPathConfigCF_LockServer
442 };
443
444 static IClassFactoryImpl ScriptAutoImplAudioPathConfig_CF = {&ScriptAutoImplAudioPathConfigCF_Vtbl};
445
446 /******************************************************************
447  *              DirectMusicScriptAutoImplAudioPath ClassFactory
448  */
449 static HRESULT WINAPI ScriptAutoImplAudioPathCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
450         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
451
452         if (ppobj == NULL) return E_POINTER;
453         
454         return E_NOINTERFACE;
455 }
456
457 static ULONG WINAPI ScriptAutoImplAudioPathCF_AddRef(LPCLASSFACTORY iface) {
458         DMSCRIPT_LockModule();
459
460         return 2; /* non-heap based object */
461 }
462
463 static ULONG WINAPI ScriptAutoImplAudioPathCF_Release(LPCLASSFACTORY iface) {
464         DMSCRIPT_UnlockModule();
465
466         return 1; /* non-heap based object */
467 }
468
469 static HRESULT WINAPI ScriptAutoImplAudioPathCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
470         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
471
472         if (ppobj == NULL) return E_POINTER;
473         
474         return E_NOINTERFACE;
475 }
476
477 static HRESULT WINAPI ScriptAutoImplAudioPathCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
478         TRACE("(%d)\n", dolock);
479
480         if (dolock)
481                 DMSCRIPT_LockModule();
482         else
483                 DMSCRIPT_UnlockModule();
484         
485         return S_OK;
486 }
487
488 static const IClassFactoryVtbl ScriptAutoImplAudioPathCF_Vtbl = {
489         ScriptAutoImplAudioPathCF_QueryInterface,
490         ScriptAutoImplAudioPathCF_AddRef,
491         ScriptAutoImplAudioPathCF_Release,
492         ScriptAutoImplAudioPathCF_CreateInstance,
493         ScriptAutoImplAudioPathCF_LockServer
494 };
495
496 static IClassFactoryImpl ScriptAutoImplAudioPath_CF = {&ScriptAutoImplAudioPathCF_Vtbl};
497
498 /******************************************************************
499  *              DirectMusicScriptAutoImplSong ClassFactory
500  */
501 static HRESULT WINAPI ScriptAutoImplSongCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
502         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
503
504         if (ppobj == NULL) return E_POINTER;
505         
506         return E_NOINTERFACE;
507 }
508
509 static ULONG WINAPI ScriptAutoImplSongCF_AddRef(LPCLASSFACTORY iface) {
510         DMSCRIPT_LockModule();
511
512         return 2; /* non-heap based */
513 }
514
515 static ULONG WINAPI ScriptAutoImplSongCF_Release(LPCLASSFACTORY iface) {
516         DMSCRIPT_UnlockModule();
517
518         return 1; /* non-heap based object */
519 }
520
521 static HRESULT WINAPI ScriptAutoImplSongCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
522         FIXME("- no interface IID: %s\n", debugstr_guid(riid));
523
524         if (ppobj == NULL) return E_POINTER;
525         
526         return E_NOINTERFACE;
527 }
528
529 static HRESULT WINAPI ScriptAutoImplSongCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
530         TRACE("(%d)\n", dolock);
531
532         if (dolock)
533                 DMSCRIPT_LockModule();
534         else
535                 DMSCRIPT_UnlockModule();
536         
537         return S_OK;
538 }
539
540 static const IClassFactoryVtbl ScriptAutoImplSongCF_Vtbl = {
541         ScriptAutoImplSongCF_QueryInterface,
542         ScriptAutoImplSongCF_AddRef,
543         ScriptAutoImplSongCF_Release,
544         ScriptAutoImplSongCF_CreateInstance,
545         ScriptAutoImplSongCF_LockServer
546 };
547
548 static IClassFactoryImpl ScriptAutoImplSong_CF = {&ScriptAutoImplSongCF_Vtbl};
549
550 /******************************************************************
551  *              DllMain
552  *
553  *
554  */
555 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
556         if (fdwReason == DLL_PROCESS_ATTACH) {
557             instance = hinstDLL;
558             DisableThreadLibraryCalls(hinstDLL);
559                 /* FIXME: Initialisation */
560         } else if (fdwReason == DLL_PROCESS_DETACH) {
561                 /* FIXME: Cleanup */
562         }
563
564         return TRUE;
565 }
566
567
568 /******************************************************************
569  *              DllCanUnloadNow (DMSCRIPT.@)
570  *
571  *
572  */
573 HRESULT WINAPI DllCanUnloadNow(void)
574 {
575         return DMSCRIPT_refCount != 0 ? S_FALSE : S_OK;
576 }
577
578
579 /******************************************************************
580  *              DllGetClassObject (DMSCRIPT.@)
581  *
582  *
583  */
584 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
585 {
586     TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
587     if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpSegment) && IsEqualIID (riid, &IID_IClassFactory)) {
588       *ppv = &ScriptAutoImplSegment_CF;
589       IClassFactory_AddRef((IClassFactory*)*ppv);
590       return S_OK;
591         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
592       *ppv = &ScriptTrack_CF;
593       IClassFactory_AddRef((IClassFactory*)*ppv);
594       return S_OK;
595         } else if (IsEqualCLSID (rclsid, &CLSID_AudioVBScript) && IsEqualIID (riid, &IID_IClassFactory)) {
596       *ppv = &AudioVBScript_CF;
597       IClassFactory_AddRef((IClassFactory*)*ppv);
598       return S_OK;
599         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScript) && IsEqualIID (riid, &IID_IClassFactory)) {
600       *ppv = &Script_CF;
601       IClassFactory_AddRef((IClassFactory*)*ppv);
602       return S_OK;
603         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpPerformance) && IsEqualIID (riid, &IID_IClassFactory)) {
604       *ppv = &ScriptAutoImplPerformance_CF;
605       IClassFactory_AddRef((IClassFactory*)*ppv);
606       return S_OK;
607         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptSourceCodeLoader) && IsEqualIID (riid, &IID_IClassFactory)) {
608       *ppv = &ScriptSourceCodeLoader_CF;
609       IClassFactory_AddRef((IClassFactory*)*ppv);
610       return S_OK;
611         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpSegmentState) && IsEqualIID (riid, &IID_IClassFactory)) {
612       *ppv = &ScriptAutoImplSegmentState_CF;
613       IClassFactory_AddRef((IClassFactory*)*ppv);
614       return S_OK;
615         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpAudioPathConfig) && IsEqualIID (riid, &IID_IClassFactory)) {
616       *ppv = &ScriptAutoImplAudioPathConfig_CF;
617       IClassFactory_AddRef((IClassFactory*)*ppv);
618       return S_OK;
619         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpAudioPath) && IsEqualIID (riid, &IID_IClassFactory)) {
620       *ppv = &ScriptAutoImplAudioPath_CF;
621       IClassFactory_AddRef((IClassFactory*)*ppv);
622       return S_OK;
623         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpSong) && IsEqualIID (riid, &IID_IClassFactory)) {
624       *ppv = &ScriptAutoImplSong_CF;
625       IClassFactory_AddRef((IClassFactory*)*ppv);
626       return S_OK;
627         }               
628
629     WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
630     return CLASS_E_CLASSNOTAVAILABLE;
631 }
632
633
634 /***********************************************************************
635  *              DllRegisterServer (DMSCRIPT.@)
636  */
637 HRESULT WINAPI DllRegisterServer(void)
638 {
639     return __wine_register_resources( instance, NULL );
640 }
641
642 /***********************************************************************
643  *              DllUnregisterServer (DMSCRIPT.@)
644  */
645 HRESULT WINAPI DllUnregisterServer(void)
646 {
647     return __wine_unregister_resources( instance, NULL );
648 }
649
650 /******************************************************************
651  *              Helper functions
652  *
653  *
654  */
655
656 /* FOURCC to string conversion for debug messages */
657 const char *debugstr_fourcc (DWORD fourcc) {
658     if (!fourcc) return "'null'";
659     return wine_dbg_sprintf ("\'%c%c%c%c\'",
660                 (char)(fourcc), (char)(fourcc >> 8),
661         (char)(fourcc >> 16), (char)(fourcc >> 24));
662 }
663
664 /* DMUS_VERSION struct to string conversion for debug messages */
665 static const char *debugstr_dmversion (const DMUS_VERSION *version) {
666         if (!version) return "'null'";
667         return wine_dbg_sprintf ("\'%i,%i,%i,%i\'",
668                 (int)((version->dwVersionMS & 0xFFFF0000) >> 8), (int)(version->dwVersionMS & 0x0000FFFF), 
669                 (int)((version->dwVersionLS & 0xFFFF0000) >> 8), (int)(version->dwVersionLS & 0x0000FFFF));
670 }
671
672 /* returns name of given GUID */
673 const char *debugstr_dmguid (const GUID *id) {
674         static const guid_info guids[] = {
675                 /* CLSIDs */
676                 GE(CLSID_AudioVBScript),
677                 GE(CLSID_DirectMusic),
678                 GE(CLSID_DirectMusicAudioPath),
679                 GE(CLSID_DirectMusicAudioPathConfig),
680                 GE(CLSID_DirectMusicAuditionTrack),
681                 GE(CLSID_DirectMusicBand),
682                 GE(CLSID_DirectMusicBandTrack),
683                 GE(CLSID_DirectMusicChordMapTrack),
684                 GE(CLSID_DirectMusicChordMap),
685                 GE(CLSID_DirectMusicChordTrack),
686                 GE(CLSID_DirectMusicCollection),
687                 GE(CLSID_DirectMusicCommandTrack),
688                 GE(CLSID_DirectMusicComposer),
689                 GE(CLSID_DirectMusicContainer),
690                 GE(CLSID_DirectMusicGraph),
691                 GE(CLSID_DirectMusicLoader),
692                 GE(CLSID_DirectMusicLyricsTrack),
693                 GE(CLSID_DirectMusicMarkerTrack),
694                 GE(CLSID_DirectMusicMelodyFormulationTrack),
695                 GE(CLSID_DirectMusicMotifTrack),
696                 GE(CLSID_DirectMusicMuteTrack),
697                 GE(CLSID_DirectMusicParamControlTrack),
698                 GE(CLSID_DirectMusicPatternTrack),
699                 GE(CLSID_DirectMusicPerformance),
700                 GE(CLSID_DirectMusicScript),
701                 GE(CLSID_DirectMusicScriptAutoImpSegment),
702                 GE(CLSID_DirectMusicScriptAutoImpPerformance),
703                 GE(CLSID_DirectMusicScriptAutoImpSegmentState),
704                 GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig),
705                 GE(CLSID_DirectMusicScriptAutoImpAudioPath),
706                 GE(CLSID_DirectMusicScriptAutoImpSong),
707                 GE(CLSID_DirectMusicScriptSourceCodeLoader),
708                 GE(CLSID_DirectMusicScriptTrack),
709                 GE(CLSID_DirectMusicSection),
710                 GE(CLSID_DirectMusicSegment),
711                 GE(CLSID_DirectMusicSegmentState),
712                 GE(CLSID_DirectMusicSegmentTriggerTrack),
713                 GE(CLSID_DirectMusicSegTriggerTrack),
714                 GE(CLSID_DirectMusicSeqTrack),
715                 GE(CLSID_DirectMusicSignPostTrack),
716                 GE(CLSID_DirectMusicSong),
717                 GE(CLSID_DirectMusicStyle),
718                 GE(CLSID_DirectMusicStyleTrack),
719                 GE(CLSID_DirectMusicSynth),
720                 GE(CLSID_DirectMusicSynthSink),
721                 GE(CLSID_DirectMusicSysExTrack),
722                 GE(CLSID_DirectMusicTemplate),
723                 GE(CLSID_DirectMusicTempoTrack),
724                 GE(CLSID_DirectMusicTimeSigTrack),
725                 GE(CLSID_DirectMusicWaveTrack),
726                 GE(CLSID_DirectSoundWave),
727                 /* IIDs */
728                 GE(IID_IDirectMusic),
729                 GE(IID_IDirectMusic2),
730                 GE(IID_IDirectMusic8),
731                 GE(IID_IDirectMusicAudioPath),
732                 GE(IID_IDirectMusicBand),
733                 GE(IID_IDirectMusicBuffer),
734                 GE(IID_IDirectMusicChordMap),
735                 GE(IID_IDirectMusicCollection),
736                 GE(IID_IDirectMusicComposer),
737                 GE(IID_IDirectMusicContainer),
738                 GE(IID_IDirectMusicDownload),
739                 GE(IID_IDirectMusicDownloadedInstrument),
740                 GE(IID_IDirectMusicGetLoader),
741                 GE(IID_IDirectMusicGraph),
742                 GE(IID_IDirectMusicInstrument),
743                 GE(IID_IDirectMusicLoader),
744                 GE(IID_IDirectMusicLoader8),
745                 GE(IID_IDirectMusicObject),
746                 GE(IID_IDirectMusicPatternTrack),
747                 GE(IID_IDirectMusicPerformance),
748                 GE(IID_IDirectMusicPerformance2),
749                 GE(IID_IDirectMusicPerformance8),
750                 GE(IID_IDirectMusicPort),
751                 GE(IID_IDirectMusicPortDownload),
752                 GE(IID_IDirectMusicScript),
753                 GE(IID_IDirectMusicSegment),
754                 GE(IID_IDirectMusicSegment2),
755                 GE(IID_IDirectMusicSegment8),
756                 GE(IID_IDirectMusicSegmentState),
757                 GE(IID_IDirectMusicSegmentState8),
758                 GE(IID_IDirectMusicStyle),
759                 GE(IID_IDirectMusicStyle8),
760                 GE(IID_IDirectMusicSynth),
761                 GE(IID_IDirectMusicSynth8),
762                 GE(IID_IDirectMusicSynthSink),
763                 GE(IID_IDirectMusicThru),
764                 GE(IID_IDirectMusicTool),
765                 GE(IID_IDirectMusicTool8),
766                 GE(IID_IDirectMusicTrack),
767                 GE(IID_IDirectMusicTrack8),
768                 GE(IID_IUnknown),
769                 GE(IID_IPersistStream),
770                 GE(IID_IStream),
771                 GE(IID_IClassFactory),
772                 /* GUIDs */
773                 GE(GUID_DirectMusicAllTypes),
774                 GE(GUID_NOTIFICATION_CHORD),
775                 GE(GUID_NOTIFICATION_COMMAND),
776                 GE(GUID_NOTIFICATION_MEASUREANDBEAT),
777                 GE(GUID_NOTIFICATION_PERFORMANCE),
778                 GE(GUID_NOTIFICATION_RECOMPOSE),
779                 GE(GUID_NOTIFICATION_SEGMENT),
780                 GE(GUID_BandParam),
781                 GE(GUID_ChordParam),
782                 GE(GUID_CommandParam),
783                 GE(GUID_CommandParam2),
784                 GE(GUID_CommandParamNext),
785                 GE(GUID_IDirectMusicBand),
786                 GE(GUID_IDirectMusicChordMap),
787                 GE(GUID_IDirectMusicStyle),
788                 GE(GUID_MuteParam),
789                 GE(GUID_Play_Marker),
790                 GE(GUID_RhythmParam),
791                 GE(GUID_TempoParam),
792                 GE(GUID_TimeSignature),
793                 GE(GUID_Valid_Start_Time),
794                 GE(GUID_Clear_All_Bands),
795                 GE(GUID_ConnectToDLSCollection),
796                 GE(GUID_Disable_Auto_Download),
797                 GE(GUID_DisableTempo),
798                 GE(GUID_DisableTimeSig),
799                 GE(GUID_Download),
800                 GE(GUID_DownloadToAudioPath),
801                 GE(GUID_Enable_Auto_Download),
802                 GE(GUID_EnableTempo),
803                 GE(GUID_EnableTimeSig),
804                 GE(GUID_IgnoreBankSelectForGM),
805                 GE(GUID_SeedVariations),
806                 GE(GUID_StandardMIDIFile),
807                 GE(GUID_Unload),
808                 GE(GUID_UnloadFromAudioPath),
809                 GE(GUID_Variations),
810                 GE(GUID_PerfMasterTempo),
811                 GE(GUID_PerfMasterVolume),
812                 GE(GUID_PerfMasterGrooveLevel),
813                 GE(GUID_PerfAutoDownload),
814                 GE(GUID_DefaultGMCollection),
815                 GE(GUID_Synth_Default),
816                 GE(GUID_Buffer_Reverb),
817                 GE(GUID_Buffer_EnvReverb),
818                 GE(GUID_Buffer_Stereo),
819                 GE(GUID_Buffer_3D_Dry),
820                 GE(GUID_Buffer_Mono),
821                 GE(GUID_DMUS_PROP_GM_Hardware),
822                 GE(GUID_DMUS_PROP_GS_Capable),
823                 GE(GUID_DMUS_PROP_GS_Hardware),
824                 GE(GUID_DMUS_PROP_DLS1),
825                 GE(GUID_DMUS_PROP_DLS2),
826                 GE(GUID_DMUS_PROP_Effects),
827                 GE(GUID_DMUS_PROP_INSTRUMENT2),
828                 GE(GUID_DMUS_PROP_LegacyCaps),
829                 GE(GUID_DMUS_PROP_MemorySize),
830                 GE(GUID_DMUS_PROP_SampleMemorySize),
831                 GE(GUID_DMUS_PROP_SamplePlaybackRate),
832                 GE(GUID_DMUS_PROP_SetSynthSink),
833                 GE(GUID_DMUS_PROP_SinkUsesDSound),
834                 GE(GUID_DMUS_PROP_SynthSink_DSOUND),
835                 GE(GUID_DMUS_PROP_SynthSink_WAVE),
836                 GE(GUID_DMUS_PROP_Volume),
837                 GE(GUID_DMUS_PROP_WavesReverb),
838                 GE(GUID_DMUS_PROP_WriteLatency),
839                 GE(GUID_DMUS_PROP_WritePeriod),
840                 GE(GUID_DMUS_PROP_XG_Capable),
841                 GE(GUID_DMUS_PROP_XG_Hardware)
842         };
843
844         unsigned int i;
845
846         if (!id) return "(null)";
847
848         for (i = 0; i < sizeof(guids)/sizeof(guids[0]); i++) {
849                 if (IsEqualGUID(id, guids[i].guid))
850                         return guids[i].name;
851         }
852         /* if we didn't find it, act like standard debugstr_guid */     
853         return debugstr_guid(id);
854 }       
855
856 /* generic flag-dumping function */
857 static const char* debugstr_flags (DWORD flags, const flag_info* names, size_t num_names){
858         char buffer[128] = "", *ptr = &buffer[0];
859         unsigned int i;
860         int size = sizeof(buffer);
861         
862         for (i=0; i < num_names; i++)
863         {
864                 if ((flags & names[i].val) ||   /* standard flag*/
865                         ((!flags) && (!names[i].val))) { /* zero value only */
866                                 int cnt = snprintf(ptr, size, "%s ", names[i].name);
867                                 if (cnt < 0 || cnt >= size) break;
868                                 size -= cnt;
869                                 ptr += cnt;
870                 }
871         }
872         
873         return wine_dbg_sprintf("%s", buffer);
874 }
875
876 /* dump DMUS_OBJ flags */
877 static const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask) {
878     static const flag_info flags[] = {
879             FE(DMUS_OBJ_OBJECT),
880             FE(DMUS_OBJ_CLASS),
881             FE(DMUS_OBJ_NAME),
882             FE(DMUS_OBJ_CATEGORY),
883             FE(DMUS_OBJ_FILENAME),
884             FE(DMUS_OBJ_FULLPATH),
885             FE(DMUS_OBJ_URL),
886             FE(DMUS_OBJ_VERSION),
887             FE(DMUS_OBJ_DATE),
888             FE(DMUS_OBJ_LOADED),
889             FE(DMUS_OBJ_MEMORY),
890             FE(DMUS_OBJ_STREAM)
891         };
892     return debugstr_flags (flagmask, flags, sizeof(flags)/sizeof(flags[0]));
893 }
894
895 /* dump whole DMUS_OBJECTDESC struct */
896 const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc) {
897         if (pDesc) {
898                 char buffer[1024] = "", *ptr = &buffer[0];
899                 
900                 ptr += sprintf(ptr, "DMUS_OBJECTDESC (%p):\n", pDesc);
901                 ptr += sprintf(ptr, " - dwSize = %d\n", pDesc->dwSize);
902                 ptr += sprintf(ptr, " - dwValidData = %s\n", debugstr_DMUS_OBJ_FLAGS (pDesc->dwValidData));
903                 if (pDesc->dwValidData & DMUS_OBJ_CLASS) ptr += sprintf(ptr, " - guidClass = %s\n", debugstr_dmguid(&pDesc->guidClass));
904                 if (pDesc->dwValidData & DMUS_OBJ_OBJECT) ptr += sprintf(ptr, " - guidObject = %s\n", debugstr_guid(&pDesc->guidObject));
905                 if (pDesc->dwValidData & DMUS_OBJ_DATE) ptr += sprintf(ptr, " - ftDate = FIXME\n");
906                 if (pDesc->dwValidData & DMUS_OBJ_VERSION) ptr += sprintf(ptr, " - vVersion = %s\n", debugstr_dmversion(&pDesc->vVersion));
907                 if (pDesc->dwValidData & DMUS_OBJ_NAME) ptr += sprintf(ptr, " - wszName = %s\n", debugstr_w(pDesc->wszName));
908                 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) ptr += sprintf(ptr, " - wszCategory = %s\n", debugstr_w(pDesc->wszCategory));
909                 if (pDesc->dwValidData & DMUS_OBJ_FILENAME) ptr += sprintf(ptr, " - wszFileName = %s\n", debugstr_w(pDesc->wszFileName));
910                 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) ptr += sprintf(ptr, " - llMemLength = 0x%s\n  - pbMemData = %p\n", 
911                                                                      wine_dbgstr_longlong(pDesc->llMemLength), pDesc->pbMemData);
912                 if (pDesc->dwValidData & DMUS_OBJ_STREAM) ptr += sprintf(ptr, " - pStream = %p", pDesc->pStream);
913
914                 return wine_dbg_sprintf("%s", buffer);
915         } else {
916                 return wine_dbg_sprintf("(NULL)");
917         }
918 }