vbscript/tests: Add tests for the script TypeInfo's TypeComp binds.
[wine.git] / dlls / dswave / dswave_main.c
blob4f3a73d9e90d03752e92f6e8a2922b8de477b5c2
1 /* DirectMusic Wave 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
21 #include <stdio.h>
22 #include <stdarg.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnt.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "winreg.h"
32 #include "objbase.h"
33 #include "rpcproxy.h"
34 #include "initguid.h"
35 #include "dmusici.h"
37 #include "dswave_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(dswave);
41 static HINSTANCE instance;
42 LONG DSWAVE_refCount = 0;
44 typedef struct {
45 IClassFactory IClassFactory_iface;
46 } IClassFactoryImpl;
48 /******************************************************************
49 * DirectMusicWave ClassFactory
51 static HRESULT WINAPI WaveCF_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 WaveCF_AddRef(IClassFactory * iface)
73 DSWAVE_LockModule();
75 return 2; /* non-heap based object */
78 static ULONG WINAPI WaveCF_Release(IClassFactory * iface)
80 DSWAVE_UnlockModule();
82 return 1; /* non-heap based object */
85 static HRESULT WINAPI WaveCF_CreateInstance(IClassFactory * iface, IUnknown *outer_unk, REFIID riid,
86 void **ret_iface)
88 TRACE ("(%p, %s, %p)\n", outer_unk, debugstr_dmguid(riid), ret_iface);
90 if (outer_unk) {
91 *ret_iface = NULL;
92 return CLASS_E_NOAGGREGATION;
95 return create_dswave(riid, ret_iface);
98 static HRESULT WINAPI WaveCF_LockServer(IClassFactory * iface, BOOL dolock)
100 TRACE("(%d)\n", dolock);
102 if (dolock)
103 DSWAVE_LockModule();
104 else
105 DSWAVE_UnlockModule();
107 return S_OK;
110 static const IClassFactoryVtbl WaveCF_Vtbl = {
111 WaveCF_QueryInterface,
112 WaveCF_AddRef,
113 WaveCF_Release,
114 WaveCF_CreateInstance,
115 WaveCF_LockServer
118 static IClassFactoryImpl Wave_CF = {{&WaveCF_Vtbl}};
120 /******************************************************************
121 * DllMain
125 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
126 if (fdwReason == DLL_PROCESS_ATTACH) {
127 instance = hinstDLL;
128 DisableThreadLibraryCalls(hinstDLL);
131 return TRUE;
135 /******************************************************************
136 * DllCanUnloadNow (DSWAVE.@)
140 HRESULT WINAPI DllCanUnloadNow(void)
142 return DSWAVE_refCount != 0 ? S_FALSE : S_OK;
146 /******************************************************************
147 * DllGetClassObject (DSWAVE.@)
151 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
153 TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
154 if (IsEqualCLSID (rclsid, &CLSID_DirectSoundWave) && IsEqualIID (riid, &IID_IClassFactory)) {
155 *ppv = &Wave_CF;
156 IClassFactory_AddRef((IClassFactory*)*ppv);
157 return S_OK;
160 WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
161 return CLASS_E_CLASSNOTAVAILABLE;
164 /***********************************************************************
165 * DllRegisterServer (DSWAVE.@)
167 HRESULT WINAPI DllRegisterServer(void)
169 return __wine_register_resources( instance );
172 /***********************************************************************
173 * DllUnregisterServer (DSWAVE.@)
175 HRESULT WINAPI DllUnregisterServer(void)
177 return __wine_unregister_resources( instance );
180 /******************************************************************
181 * Helper functions
185 /* FOURCC to string conversion for debug messages */
186 const char *debugstr_fourcc (DWORD fourcc) {
187 if (!fourcc) return "'null'";
188 return wine_dbg_sprintf ("\'%c%c%c%c\'",
189 (char)(fourcc), (char)(fourcc >> 8),
190 (char)(fourcc >> 16), (char)(fourcc >> 24));
193 /* DMUS_VERSION struct to string conversion for debug messages */
194 static const char *debugstr_dmversion(const DMUS_VERSION *version)
196 if (!version)
197 return "'null'";
198 return wine_dbg_sprintf("'%hu,%hu,%hu,%hu'",
199 HIWORD(version->dwVersionMS), LOWORD(version->dwVersionMS),
200 HIWORD(version->dwVersionLS), LOWORD(version->dwVersionLS));
203 /* returns name of given GUID */
204 const char *debugstr_dmguid (const GUID *id) {
205 static const guid_info guids[] = {
206 /* CLSIDs */
207 GE(CLSID_AudioVBScript),
208 GE(CLSID_DirectMusic),
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)
374 unsigned int i;
376 if (!id) return "(null)";
378 for (i = 0; i < ARRAY_SIZE(guids); i++) {
379 if (IsEqualGUID(id, guids[i].guid))
380 return guids[i].name;
382 /* if we didn't find it, act like standard debugstr_guid */
383 return debugstr_guid(id);
386 /* generic flag-dumping function */
387 static const char* debugstr_flags (DWORD flags, const flag_info* names, size_t num_names){
388 char buffer[128] = "", *ptr = &buffer[0];
389 unsigned int i;
390 int size = sizeof(buffer);
392 for (i=0; i < num_names; i++)
394 if ((flags & names[i].val) || /* standard flag*/
395 ((!flags) && (!names[i].val))) { /* zero value only */
396 int cnt = snprintf(ptr, size, "%s ", names[i].name);
397 if (cnt < 0 || cnt >= size) break;
398 size -= cnt;
399 ptr += cnt;
403 return wine_dbg_sprintf("%s", buffer);
406 /* dump DMUS_OBJ flags */
407 static const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask) {
408 static const flag_info flags[] = {
409 FE(DMUS_OBJ_OBJECT),
410 FE(DMUS_OBJ_CLASS),
411 FE(DMUS_OBJ_NAME),
412 FE(DMUS_OBJ_CATEGORY),
413 FE(DMUS_OBJ_FILENAME),
414 FE(DMUS_OBJ_FULLPATH),
415 FE(DMUS_OBJ_URL),
416 FE(DMUS_OBJ_VERSION),
417 FE(DMUS_OBJ_DATE),
418 FE(DMUS_OBJ_LOADED),
419 FE(DMUS_OBJ_MEMORY),
420 FE(DMUS_OBJ_STREAM)
422 return debugstr_flags(flagmask, flags, ARRAY_SIZE(flags));
425 /* dump whole DMUS_OBJECTDESC struct */
426 const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc) {
427 if (pDesc) {
428 char buffer[1024] = "", *ptr = &buffer[0];
430 ptr += sprintf(ptr, "DMUS_OBJECTDESC (%p):\n", pDesc);
431 ptr += sprintf(ptr, " - dwSize = %d\n", pDesc->dwSize);
432 ptr += sprintf(ptr, " - dwValidData = %s\n", debugstr_DMUS_OBJ_FLAGS (pDesc->dwValidData));
433 if (pDesc->dwValidData & DMUS_OBJ_CLASS) ptr += sprintf(ptr, " - guidClass = %s\n", debugstr_dmguid(&pDesc->guidClass));
434 if (pDesc->dwValidData & DMUS_OBJ_OBJECT) ptr += sprintf(ptr, " - guidObject = %s\n", debugstr_guid(&pDesc->guidObject));
435 if (pDesc->dwValidData & DMUS_OBJ_DATE) ptr += sprintf(ptr, " - ftDate = FIXME\n");
436 if (pDesc->dwValidData & DMUS_OBJ_VERSION) ptr += sprintf(ptr, " - vVersion = %s\n", debugstr_dmversion(&pDesc->vVersion));
437 if (pDesc->dwValidData & DMUS_OBJ_NAME) ptr += sprintf(ptr, " - wszName = %s\n", debugstr_w(pDesc->wszName));
438 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) ptr += sprintf(ptr, " - wszCategory = %s\n", debugstr_w(pDesc->wszCategory));
439 if (pDesc->dwValidData & DMUS_OBJ_FILENAME) ptr += sprintf(ptr, " - wszFileName = %s\n", debugstr_w(pDesc->wszFileName));
440 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) ptr += sprintf(ptr, " - llMemLength = 0x%s - pbMemData = %p\n",
441 wine_dbgstr_longlong(pDesc->llMemLength), pDesc->pbMemData);
442 if (pDesc->dwValidData & DMUS_OBJ_STREAM) ptr += sprintf(ptr, " - pStream = %p", pDesc->pStream);
444 return wine_dbg_sprintf("%s", buffer);
445 } else {
446 return wine_dbg_sprintf("(NULL)");