dmscript: Return CLASS_E_CLASSNOTAVAILABLE for classes not implemented.
[wine/multimedia.git] / dlls / dmscript / dmscript_main.c
blob6caf158d32c60bfa81713cf64645204bcc68989a
1 /* DirectMusicScript Main
3 * Copyright (C) 2003-2004 Rok Mandeljc
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.
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.
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
20 #include "config.h"
21 #include "wine/port.h"
23 #include "dmscript_private.h"
24 #include "rpcproxy.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(dmscript);
28 static HINSTANCE instance;
29 LONG DMSCRIPT_refCount = 0;
31 typedef struct {
32 IClassFactory IClassFactory_iface;
33 HRESULT WINAPI (*fnCreateInstance)(REFIID riid, void **ppv, IUnknown *pUnkOuter);
34 } IClassFactoryImpl;
36 static HRESULT WINAPI create_unimpl_instance(REFIID riid, void **ppv, IUnknown *pUnkOuter)
38 FIXME("(%p, %s, %p) stub\n", pUnkOuter, debugstr_dmguid(riid), ppv);
40 return CLASS_E_CLASSNOTAVAILABLE;
43 /******************************************************************
44 * IClassFactory implementation
46 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
48 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
51 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
53 if (ppv == NULL)
54 return E_POINTER;
56 if (IsEqualGUID(&IID_IUnknown, riid))
57 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
58 else if (IsEqualGUID(&IID_IClassFactory, riid))
59 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
60 else {
61 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
62 *ppv = NULL;
63 return E_NOINTERFACE;
66 *ppv = iface;
67 IUnknown_AddRef((IUnknown*)*ppv);
68 return S_OK;
71 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
73 DMSCRIPT_LockModule();
75 return 2; /* non-heap based object */
78 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
80 DMSCRIPT_UnlockModule();
82 return 1; /* non-heap based object */
85 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
86 REFIID riid, void **ppv)
88 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
90 TRACE ("(%p, %s, %p)\n", pUnkOuter, debugstr_dmguid(riid), ppv);
92 return This->fnCreateInstance(riid, ppv, pUnkOuter);
95 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
97 TRACE("(%d)\n", dolock);
99 if (dolock)
100 DMSCRIPT_LockModule();
101 else
102 DMSCRIPT_UnlockModule();
104 return S_OK;
107 static const IClassFactoryVtbl classfactory_vtbl = {
108 ClassFactory_QueryInterface,
109 ClassFactory_AddRef,
110 ClassFactory_Release,
111 ClassFactory_CreateInstance,
112 ClassFactory_LockServer
115 static IClassFactoryImpl ScriptAutoImplSegment_CF = {{&classfactory_vtbl}, create_unimpl_instance};
116 static IClassFactoryImpl ScriptTrack_CF = {{&classfactory_vtbl},
117 DMUSIC_CreateDirectMusicScriptTrack};
118 static IClassFactoryImpl AudioVBScript_CF = {{&classfactory_vtbl}, create_unimpl_instance};
119 static IClassFactoryImpl Script_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicScriptImpl};
120 static IClassFactoryImpl ScriptAutoImplPerformance_CF = {{&classfactory_vtbl},
121 create_unimpl_instance};
122 static IClassFactoryImpl ScriptSourceCodeLoader_CF = {{&classfactory_vtbl}, create_unimpl_instance};
123 static IClassFactoryImpl ScriptAutoImplSegmentState_CF = {{&classfactory_vtbl},
124 create_unimpl_instance};
125 static IClassFactoryImpl ScriptAutoImplAudioPathConfig_CF = {{&classfactory_vtbl},
126 create_unimpl_instance};
127 static IClassFactoryImpl ScriptAutoImplAudioPath_CF = {{&classfactory_vtbl},
128 create_unimpl_instance};
129 static IClassFactoryImpl ScriptAutoImplSong_CF = {{&classfactory_vtbl}, create_unimpl_instance};
131 /******************************************************************
132 * DllMain
136 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
137 if (fdwReason == DLL_PROCESS_ATTACH) {
138 instance = hinstDLL;
139 DisableThreadLibraryCalls(hinstDLL);
142 return TRUE;
146 /******************************************************************
147 * DllCanUnloadNow (DMSCRIPT.@)
151 HRESULT WINAPI DllCanUnloadNow(void)
153 return DMSCRIPT_refCount != 0 ? S_FALSE : S_OK;
157 /******************************************************************
158 * DllGetClassObject (DMSCRIPT.@)
162 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
164 TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
165 if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpSegment) && IsEqualIID (riid, &IID_IClassFactory)) {
166 *ppv = &ScriptAutoImplSegment_CF;
167 IClassFactory_AddRef((IClassFactory*)*ppv);
168 return S_OK;
169 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
170 *ppv = &ScriptTrack_CF;
171 IClassFactory_AddRef((IClassFactory*)*ppv);
172 return S_OK;
173 } else if (IsEqualCLSID (rclsid, &CLSID_AudioVBScript) && IsEqualIID (riid, &IID_IClassFactory)) {
174 *ppv = &AudioVBScript_CF;
175 IClassFactory_AddRef((IClassFactory*)*ppv);
176 return S_OK;
177 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScript) && IsEqualIID (riid, &IID_IClassFactory)) {
178 *ppv = &Script_CF;
179 IClassFactory_AddRef((IClassFactory*)*ppv);
180 return S_OK;
181 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpPerformance) && IsEqualIID (riid, &IID_IClassFactory)) {
182 *ppv = &ScriptAutoImplPerformance_CF;
183 IClassFactory_AddRef((IClassFactory*)*ppv);
184 return S_OK;
185 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptSourceCodeLoader) && IsEqualIID (riid, &IID_IClassFactory)) {
186 *ppv = &ScriptSourceCodeLoader_CF;
187 IClassFactory_AddRef((IClassFactory*)*ppv);
188 return S_OK;
189 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpSegmentState) && IsEqualIID (riid, &IID_IClassFactory)) {
190 *ppv = &ScriptAutoImplSegmentState_CF;
191 IClassFactory_AddRef((IClassFactory*)*ppv);
192 return S_OK;
193 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpAudioPathConfig) && IsEqualIID (riid, &IID_IClassFactory)) {
194 *ppv = &ScriptAutoImplAudioPathConfig_CF;
195 IClassFactory_AddRef((IClassFactory*)*ppv);
196 return S_OK;
197 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpAudioPath) && IsEqualIID (riid, &IID_IClassFactory)) {
198 *ppv = &ScriptAutoImplAudioPath_CF;
199 IClassFactory_AddRef((IClassFactory*)*ppv);
200 return S_OK;
201 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpSong) && IsEqualIID (riid, &IID_IClassFactory)) {
202 *ppv = &ScriptAutoImplSong_CF;
203 IClassFactory_AddRef((IClassFactory*)*ppv);
204 return S_OK;
207 WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
208 return CLASS_E_CLASSNOTAVAILABLE;
212 /***********************************************************************
213 * DllRegisterServer (DMSCRIPT.@)
215 HRESULT WINAPI DllRegisterServer(void)
217 return __wine_register_resources( instance );
220 /***********************************************************************
221 * DllUnregisterServer (DMSCRIPT.@)
223 HRESULT WINAPI DllUnregisterServer(void)
225 return __wine_unregister_resources( instance );
228 /******************************************************************
229 * Helper functions
234 /* FOURCC to string conversion for debug messages */
235 const char *debugstr_fourcc (DWORD fourcc) {
236 if (!fourcc) return "'null'";
237 return wine_dbg_sprintf ("\'%c%c%c%c\'",
238 (char)(fourcc), (char)(fourcc >> 8),
239 (char)(fourcc >> 16), (char)(fourcc >> 24));
242 /* DMUS_VERSION struct to string conversion for debug messages */
243 static const char *debugstr_dmversion (const DMUS_VERSION *version) {
244 if (!version) return "'null'";
245 return wine_dbg_sprintf ("\'%i,%i,%i,%i\'",
246 (int)((version->dwVersionMS & 0xFFFF0000) >> 8), (int)(version->dwVersionMS & 0x0000FFFF),
247 (int)((version->dwVersionLS & 0xFFFF0000) >> 8), (int)(version->dwVersionLS & 0x0000FFFF));
250 /* returns name of given GUID */
251 const char *debugstr_dmguid (const GUID *id) {
252 static const guid_info guids[] = {
253 /* CLSIDs */
254 GE(CLSID_AudioVBScript),
255 GE(CLSID_DirectMusic),
256 GE(CLSID_DirectMusicAudioPathConfig),
257 GE(CLSID_DirectMusicAuditionTrack),
258 GE(CLSID_DirectMusicBand),
259 GE(CLSID_DirectMusicBandTrack),
260 GE(CLSID_DirectMusicChordMapTrack),
261 GE(CLSID_DirectMusicChordMap),
262 GE(CLSID_DirectMusicChordTrack),
263 GE(CLSID_DirectMusicCollection),
264 GE(CLSID_DirectMusicCommandTrack),
265 GE(CLSID_DirectMusicComposer),
266 GE(CLSID_DirectMusicContainer),
267 GE(CLSID_DirectMusicGraph),
268 GE(CLSID_DirectMusicLoader),
269 GE(CLSID_DirectMusicLyricsTrack),
270 GE(CLSID_DirectMusicMarkerTrack),
271 GE(CLSID_DirectMusicMelodyFormulationTrack),
272 GE(CLSID_DirectMusicMotifTrack),
273 GE(CLSID_DirectMusicMuteTrack),
274 GE(CLSID_DirectMusicParamControlTrack),
275 GE(CLSID_DirectMusicPatternTrack),
276 GE(CLSID_DirectMusicPerformance),
277 GE(CLSID_DirectMusicScript),
278 GE(CLSID_DirectMusicScriptAutoImpSegment),
279 GE(CLSID_DirectMusicScriptAutoImpPerformance),
280 GE(CLSID_DirectMusicScriptAutoImpSegmentState),
281 GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig),
282 GE(CLSID_DirectMusicScriptAutoImpAudioPath),
283 GE(CLSID_DirectMusicScriptAutoImpSong),
284 GE(CLSID_DirectMusicScriptSourceCodeLoader),
285 GE(CLSID_DirectMusicScriptTrack),
286 GE(CLSID_DirectMusicSection),
287 GE(CLSID_DirectMusicSegment),
288 GE(CLSID_DirectMusicSegmentState),
289 GE(CLSID_DirectMusicSegmentTriggerTrack),
290 GE(CLSID_DirectMusicSegTriggerTrack),
291 GE(CLSID_DirectMusicSeqTrack),
292 GE(CLSID_DirectMusicSignPostTrack),
293 GE(CLSID_DirectMusicSong),
294 GE(CLSID_DirectMusicStyle),
295 GE(CLSID_DirectMusicStyleTrack),
296 GE(CLSID_DirectMusicSynth),
297 GE(CLSID_DirectMusicSynthSink),
298 GE(CLSID_DirectMusicSysExTrack),
299 GE(CLSID_DirectMusicTemplate),
300 GE(CLSID_DirectMusicTempoTrack),
301 GE(CLSID_DirectMusicTimeSigTrack),
302 GE(CLSID_DirectMusicWaveTrack),
303 GE(CLSID_DirectSoundWave),
304 /* IIDs */
305 GE(IID_IDirectMusic),
306 GE(IID_IDirectMusic2),
307 GE(IID_IDirectMusic8),
308 GE(IID_IDirectMusicAudioPath),
309 GE(IID_IDirectMusicBand),
310 GE(IID_IDirectMusicBuffer),
311 GE(IID_IDirectMusicChordMap),
312 GE(IID_IDirectMusicCollection),
313 GE(IID_IDirectMusicComposer),
314 GE(IID_IDirectMusicContainer),
315 GE(IID_IDirectMusicDownload),
316 GE(IID_IDirectMusicDownloadedInstrument),
317 GE(IID_IDirectMusicGetLoader),
318 GE(IID_IDirectMusicGraph),
319 GE(IID_IDirectMusicInstrument),
320 GE(IID_IDirectMusicLoader),
321 GE(IID_IDirectMusicLoader8),
322 GE(IID_IDirectMusicObject),
323 GE(IID_IDirectMusicPatternTrack),
324 GE(IID_IDirectMusicPerformance),
325 GE(IID_IDirectMusicPerformance2),
326 GE(IID_IDirectMusicPerformance8),
327 GE(IID_IDirectMusicPort),
328 GE(IID_IDirectMusicPortDownload),
329 GE(IID_IDirectMusicScript),
330 GE(IID_IDirectMusicSegment),
331 GE(IID_IDirectMusicSegment2),
332 GE(IID_IDirectMusicSegment8),
333 GE(IID_IDirectMusicSegmentState),
334 GE(IID_IDirectMusicSegmentState8),
335 GE(IID_IDirectMusicStyle),
336 GE(IID_IDirectMusicStyle8),
337 GE(IID_IDirectMusicSynth),
338 GE(IID_IDirectMusicSynth8),
339 GE(IID_IDirectMusicSynthSink),
340 GE(IID_IDirectMusicThru),
341 GE(IID_IDirectMusicTool),
342 GE(IID_IDirectMusicTool8),
343 GE(IID_IDirectMusicTrack),
344 GE(IID_IDirectMusicTrack8),
345 GE(IID_IUnknown),
346 GE(IID_IPersistStream),
347 GE(IID_IStream),
348 GE(IID_IClassFactory),
349 /* GUIDs */
350 GE(GUID_DirectMusicAllTypes),
351 GE(GUID_NOTIFICATION_CHORD),
352 GE(GUID_NOTIFICATION_COMMAND),
353 GE(GUID_NOTIFICATION_MEASUREANDBEAT),
354 GE(GUID_NOTIFICATION_PERFORMANCE),
355 GE(GUID_NOTIFICATION_RECOMPOSE),
356 GE(GUID_NOTIFICATION_SEGMENT),
357 GE(GUID_BandParam),
358 GE(GUID_ChordParam),
359 GE(GUID_CommandParam),
360 GE(GUID_CommandParam2),
361 GE(GUID_CommandParamNext),
362 GE(GUID_IDirectMusicBand),
363 GE(GUID_IDirectMusicChordMap),
364 GE(GUID_IDirectMusicStyle),
365 GE(GUID_MuteParam),
366 GE(GUID_Play_Marker),
367 GE(GUID_RhythmParam),
368 GE(GUID_TempoParam),
369 GE(GUID_TimeSignature),
370 GE(GUID_Valid_Start_Time),
371 GE(GUID_Clear_All_Bands),
372 GE(GUID_ConnectToDLSCollection),
373 GE(GUID_Disable_Auto_Download),
374 GE(GUID_DisableTempo),
375 GE(GUID_DisableTimeSig),
376 GE(GUID_Download),
377 GE(GUID_DownloadToAudioPath),
378 GE(GUID_Enable_Auto_Download),
379 GE(GUID_EnableTempo),
380 GE(GUID_EnableTimeSig),
381 GE(GUID_IgnoreBankSelectForGM),
382 GE(GUID_SeedVariations),
383 GE(GUID_StandardMIDIFile),
384 GE(GUID_Unload),
385 GE(GUID_UnloadFromAudioPath),
386 GE(GUID_Variations),
387 GE(GUID_PerfMasterTempo),
388 GE(GUID_PerfMasterVolume),
389 GE(GUID_PerfMasterGrooveLevel),
390 GE(GUID_PerfAutoDownload),
391 GE(GUID_DefaultGMCollection),
392 GE(GUID_Synth_Default),
393 GE(GUID_Buffer_Reverb),
394 GE(GUID_Buffer_EnvReverb),
395 GE(GUID_Buffer_Stereo),
396 GE(GUID_Buffer_3D_Dry),
397 GE(GUID_Buffer_Mono),
398 GE(GUID_DMUS_PROP_GM_Hardware),
399 GE(GUID_DMUS_PROP_GS_Capable),
400 GE(GUID_DMUS_PROP_GS_Hardware),
401 GE(GUID_DMUS_PROP_DLS1),
402 GE(GUID_DMUS_PROP_DLS2),
403 GE(GUID_DMUS_PROP_Effects),
404 GE(GUID_DMUS_PROP_INSTRUMENT2),
405 GE(GUID_DMUS_PROP_LegacyCaps),
406 GE(GUID_DMUS_PROP_MemorySize),
407 GE(GUID_DMUS_PROP_SampleMemorySize),
408 GE(GUID_DMUS_PROP_SamplePlaybackRate),
409 GE(GUID_DMUS_PROP_SetSynthSink),
410 GE(GUID_DMUS_PROP_SinkUsesDSound),
411 GE(GUID_DMUS_PROP_SynthSink_DSOUND),
412 GE(GUID_DMUS_PROP_SynthSink_WAVE),
413 GE(GUID_DMUS_PROP_Volume),
414 GE(GUID_DMUS_PROP_WavesReverb),
415 GE(GUID_DMUS_PROP_WriteLatency),
416 GE(GUID_DMUS_PROP_WritePeriod),
417 GE(GUID_DMUS_PROP_XG_Capable),
418 GE(GUID_DMUS_PROP_XG_Hardware)
421 unsigned int i;
423 if (!id) return "(null)";
425 for (i = 0; i < sizeof(guids)/sizeof(guids[0]); i++) {
426 if (IsEqualGUID(id, guids[i].guid))
427 return guids[i].name;
429 /* if we didn't find it, act like standard debugstr_guid */
430 return debugstr_guid(id);
433 /* generic flag-dumping function */
434 static const char* debugstr_flags (DWORD flags, const flag_info* names, size_t num_names){
435 char buffer[128] = "", *ptr = &buffer[0];
436 unsigned int i;
437 int size = sizeof(buffer);
439 for (i=0; i < num_names; i++)
441 if ((flags & names[i].val) || /* standard flag*/
442 ((!flags) && (!names[i].val))) { /* zero value only */
443 int cnt = snprintf(ptr, size, "%s ", names[i].name);
444 if (cnt < 0 || cnt >= size) break;
445 size -= cnt;
446 ptr += cnt;
450 return wine_dbg_sprintf("%s", buffer);
453 /* dump DMUS_OBJ flags */
454 static const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask) {
455 static const flag_info flags[] = {
456 FE(DMUS_OBJ_OBJECT),
457 FE(DMUS_OBJ_CLASS),
458 FE(DMUS_OBJ_NAME),
459 FE(DMUS_OBJ_CATEGORY),
460 FE(DMUS_OBJ_FILENAME),
461 FE(DMUS_OBJ_FULLPATH),
462 FE(DMUS_OBJ_URL),
463 FE(DMUS_OBJ_VERSION),
464 FE(DMUS_OBJ_DATE),
465 FE(DMUS_OBJ_LOADED),
466 FE(DMUS_OBJ_MEMORY),
467 FE(DMUS_OBJ_STREAM)
469 return debugstr_flags (flagmask, flags, sizeof(flags)/sizeof(flags[0]));
472 /* dump whole DMUS_OBJECTDESC struct */
473 const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc) {
474 if (pDesc) {
475 char buffer[1024] = "", *ptr = &buffer[0];
477 ptr += sprintf(ptr, "DMUS_OBJECTDESC (%p):\n", pDesc);
478 ptr += sprintf(ptr, " - dwSize = %d\n", pDesc->dwSize);
479 ptr += sprintf(ptr, " - dwValidData = %s\n", debugstr_DMUS_OBJ_FLAGS (pDesc->dwValidData));
480 if (pDesc->dwValidData & DMUS_OBJ_CLASS) ptr += sprintf(ptr, " - guidClass = %s\n", debugstr_dmguid(&pDesc->guidClass));
481 if (pDesc->dwValidData & DMUS_OBJ_OBJECT) ptr += sprintf(ptr, " - guidObject = %s\n", debugstr_guid(&pDesc->guidObject));
482 if (pDesc->dwValidData & DMUS_OBJ_DATE) ptr += sprintf(ptr, " - ftDate = FIXME\n");
483 if (pDesc->dwValidData & DMUS_OBJ_VERSION) ptr += sprintf(ptr, " - vVersion = %s\n", debugstr_dmversion(&pDesc->vVersion));
484 if (pDesc->dwValidData & DMUS_OBJ_NAME) ptr += sprintf(ptr, " - wszName = %s\n", debugstr_w(pDesc->wszName));
485 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) ptr += sprintf(ptr, " - wszCategory = %s\n", debugstr_w(pDesc->wszCategory));
486 if (pDesc->dwValidData & DMUS_OBJ_FILENAME) ptr += sprintf(ptr, " - wszFileName = %s\n", debugstr_w(pDesc->wszFileName));
487 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) ptr += sprintf(ptr, " - llMemLength = 0x%s\n - pbMemData = %p\n",
488 wine_dbgstr_longlong(pDesc->llMemLength), pDesc->pbMemData);
489 if (pDesc->dwValidData & DMUS_OBJ_STREAM) ptr += sprintf(ptr, " - pStream = %p", pDesc->pStream);
491 return wine_dbg_sprintf("%s", buffer);
492 } else {
493 return wine_dbg_sprintf("(NULL)");