ntdll: Translate signal to trap when trap code is 0 on ARM.
[wine.git] / dlls / dswave / dswave_main.c
bloba136bb839dac8f0b3f52afdeeba4fb1ddb812480
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
20 #include "config.h"
21 #include "wine/port.h"
23 #include <stdio.h>
24 #include <stdarg.h>
26 #define COBJMACROS
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnt.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winreg.h"
34 #include "objbase.h"
35 #include "rpcproxy.h"
36 #include "initguid.h"
37 #include "dmusici.h"
39 #include "dswave_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(dswave);
43 static HINSTANCE instance;
44 LONG DSWAVE_refCount = 0;
46 typedef struct {
47 IClassFactory IClassFactory_iface;
48 } IClassFactoryImpl;
50 /******************************************************************
51 * DirectMusicWave ClassFactory
53 static HRESULT WINAPI WaveCF_QueryInterface(IClassFactory * iface, REFIID riid, void **ppv)
55 if (ppv == NULL)
56 return E_POINTER;
58 if (IsEqualGUID(&IID_IUnknown, riid))
59 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
60 else if (IsEqualGUID(&IID_IClassFactory, riid))
61 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
62 else {
63 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
64 *ppv = NULL;
65 return E_NOINTERFACE;
68 *ppv = iface;
69 IUnknown_AddRef((IUnknown*)*ppv);
70 return S_OK;
73 static ULONG WINAPI WaveCF_AddRef(IClassFactory * iface)
75 DSWAVE_LockModule();
77 return 2; /* non-heap based object */
80 static ULONG WINAPI WaveCF_Release(IClassFactory * iface)
82 DSWAVE_UnlockModule();
84 return 1; /* non-heap based object */
87 static HRESULT WINAPI WaveCF_CreateInstance(IClassFactory * iface, IUnknown *outer_unk, REFIID riid,
88 void **ret_iface)
90 TRACE ("(%p, %s, %p)\n", outer_unk, debugstr_dmguid(riid), ret_iface);
92 if (outer_unk) {
93 *ret_iface = NULL;
94 return CLASS_E_NOAGGREGATION;
97 return create_dswave(riid, ret_iface);
100 static HRESULT WINAPI WaveCF_LockServer(IClassFactory * iface, BOOL dolock)
102 TRACE("(%d)\n", dolock);
104 if (dolock)
105 DSWAVE_LockModule();
106 else
107 DSWAVE_UnlockModule();
109 return S_OK;
112 static const IClassFactoryVtbl WaveCF_Vtbl = {
113 WaveCF_QueryInterface,
114 WaveCF_AddRef,
115 WaveCF_Release,
116 WaveCF_CreateInstance,
117 WaveCF_LockServer
120 static IClassFactoryImpl Wave_CF = {{&WaveCF_Vtbl}};
122 /******************************************************************
123 * DllMain
127 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
128 if (fdwReason == DLL_PROCESS_ATTACH) {
129 instance = hinstDLL;
130 DisableThreadLibraryCalls(hinstDLL);
133 return TRUE;
137 /******************************************************************
138 * DllCanUnloadNow (DSWAVE.@)
142 HRESULT WINAPI DllCanUnloadNow(void)
144 return DSWAVE_refCount != 0 ? S_FALSE : S_OK;
148 /******************************************************************
149 * DllGetClassObject (DSWAVE.@)
153 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
155 TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
156 if (IsEqualCLSID (rclsid, &CLSID_DirectSoundWave) && IsEqualIID (riid, &IID_IClassFactory)) {
157 *ppv = &Wave_CF;
158 IClassFactory_AddRef((IClassFactory*)*ppv);
159 return S_OK;
162 WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
163 return CLASS_E_CLASSNOTAVAILABLE;
166 /***********************************************************************
167 * DllRegisterServer (DSWAVE.@)
169 HRESULT WINAPI DllRegisterServer(void)
171 return __wine_register_resources( instance );
174 /***********************************************************************
175 * DllUnregisterServer (DSWAVE.@)
177 HRESULT WINAPI DllUnregisterServer(void)
179 return __wine_unregister_resources( instance );
182 /******************************************************************
183 * Helper functions
187 /* FOURCC to string conversion for debug messages */
188 const char *debugstr_fourcc (DWORD fourcc) {
189 if (!fourcc) return "'null'";
190 return wine_dbg_sprintf ("\'%c%c%c%c\'",
191 (char)(fourcc), (char)(fourcc >> 8),
192 (char)(fourcc >> 16), (char)(fourcc >> 24));
195 /* DMUS_VERSION struct to string conversion for debug messages */
196 static const char *debugstr_dmversion(const DMUS_VERSION *version)
198 if (!version)
199 return "'null'";
200 return wine_dbg_sprintf("'%hu,%hu,%hu,%hu'",
201 HIWORD(version->dwVersionMS), LOWORD(version->dwVersionMS),
202 HIWORD(version->dwVersionLS), LOWORD(version->dwVersionLS));
205 /* returns name of given GUID */
206 const char *debugstr_dmguid (const GUID *id) {
207 static const guid_info guids[] = {
208 /* CLSIDs */
209 GE(CLSID_AudioVBScript),
210 GE(CLSID_DirectMusic),
211 GE(CLSID_DirectMusicAudioPathConfig),
212 GE(CLSID_DirectMusicAuditionTrack),
213 GE(CLSID_DirectMusicBand),
214 GE(CLSID_DirectMusicBandTrack),
215 GE(CLSID_DirectMusicChordMapTrack),
216 GE(CLSID_DirectMusicChordMap),
217 GE(CLSID_DirectMusicChordTrack),
218 GE(CLSID_DirectMusicCollection),
219 GE(CLSID_DirectMusicCommandTrack),
220 GE(CLSID_DirectMusicComposer),
221 GE(CLSID_DirectMusicContainer),
222 GE(CLSID_DirectMusicGraph),
223 GE(CLSID_DirectMusicLoader),
224 GE(CLSID_DirectMusicLyricsTrack),
225 GE(CLSID_DirectMusicMarkerTrack),
226 GE(CLSID_DirectMusicMelodyFormulationTrack),
227 GE(CLSID_DirectMusicMotifTrack),
228 GE(CLSID_DirectMusicMuteTrack),
229 GE(CLSID_DirectMusicParamControlTrack),
230 GE(CLSID_DirectMusicPatternTrack),
231 GE(CLSID_DirectMusicPerformance),
232 GE(CLSID_DirectMusicScript),
233 GE(CLSID_DirectMusicScriptAutoImpSegment),
234 GE(CLSID_DirectMusicScriptAutoImpPerformance),
235 GE(CLSID_DirectMusicScriptAutoImpSegmentState),
236 GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig),
237 GE(CLSID_DirectMusicScriptAutoImpAudioPath),
238 GE(CLSID_DirectMusicScriptAutoImpSong),
239 GE(CLSID_DirectMusicScriptSourceCodeLoader),
240 GE(CLSID_DirectMusicScriptTrack),
241 GE(CLSID_DirectMusicSection),
242 GE(CLSID_DirectMusicSegment),
243 GE(CLSID_DirectMusicSegmentState),
244 GE(CLSID_DirectMusicSegmentTriggerTrack),
245 GE(CLSID_DirectMusicSegTriggerTrack),
246 GE(CLSID_DirectMusicSeqTrack),
247 GE(CLSID_DirectMusicSignPostTrack),
248 GE(CLSID_DirectMusicSong),
249 GE(CLSID_DirectMusicStyle),
250 GE(CLSID_DirectMusicStyleTrack),
251 GE(CLSID_DirectMusicSynth),
252 GE(CLSID_DirectMusicSynthSink),
253 GE(CLSID_DirectMusicSysExTrack),
254 GE(CLSID_DirectMusicTemplate),
255 GE(CLSID_DirectMusicTempoTrack),
256 GE(CLSID_DirectMusicTimeSigTrack),
257 GE(CLSID_DirectMusicWaveTrack),
258 GE(CLSID_DirectSoundWave),
259 /* IIDs */
260 GE(IID_IDirectMusic),
261 GE(IID_IDirectMusic2),
262 GE(IID_IDirectMusic8),
263 GE(IID_IDirectMusicAudioPath),
264 GE(IID_IDirectMusicBand),
265 GE(IID_IDirectMusicBuffer),
266 GE(IID_IDirectMusicChordMap),
267 GE(IID_IDirectMusicCollection),
268 GE(IID_IDirectMusicComposer),
269 GE(IID_IDirectMusicContainer),
270 GE(IID_IDirectMusicDownload),
271 GE(IID_IDirectMusicDownloadedInstrument),
272 GE(IID_IDirectMusicGetLoader),
273 GE(IID_IDirectMusicGraph),
274 GE(IID_IDirectMusicInstrument),
275 GE(IID_IDirectMusicLoader),
276 GE(IID_IDirectMusicLoader8),
277 GE(IID_IDirectMusicObject),
278 GE(IID_IDirectMusicPatternTrack),
279 GE(IID_IDirectMusicPerformance),
280 GE(IID_IDirectMusicPerformance2),
281 GE(IID_IDirectMusicPerformance8),
282 GE(IID_IDirectMusicPort),
283 GE(IID_IDirectMusicPortDownload),
284 GE(IID_IDirectMusicScript),
285 GE(IID_IDirectMusicSegment),
286 GE(IID_IDirectMusicSegment2),
287 GE(IID_IDirectMusicSegment8),
288 GE(IID_IDirectMusicSegmentState),
289 GE(IID_IDirectMusicSegmentState8),
290 GE(IID_IDirectMusicStyle),
291 GE(IID_IDirectMusicStyle8),
292 GE(IID_IDirectMusicSynth),
293 GE(IID_IDirectMusicSynth8),
294 GE(IID_IDirectMusicSynthSink),
295 GE(IID_IDirectMusicThru),
296 GE(IID_IDirectMusicTool),
297 GE(IID_IDirectMusicTool8),
298 GE(IID_IDirectMusicTrack),
299 GE(IID_IDirectMusicTrack8),
300 GE(IID_IUnknown),
301 GE(IID_IPersistStream),
302 GE(IID_IStream),
303 GE(IID_IClassFactory),
304 /* GUIDs */
305 GE(GUID_DirectMusicAllTypes),
306 GE(GUID_NOTIFICATION_CHORD),
307 GE(GUID_NOTIFICATION_COMMAND),
308 GE(GUID_NOTIFICATION_MEASUREANDBEAT),
309 GE(GUID_NOTIFICATION_PERFORMANCE),
310 GE(GUID_NOTIFICATION_RECOMPOSE),
311 GE(GUID_NOTIFICATION_SEGMENT),
312 GE(GUID_BandParam),
313 GE(GUID_ChordParam),
314 GE(GUID_CommandParam),
315 GE(GUID_CommandParam2),
316 GE(GUID_CommandParamNext),
317 GE(GUID_IDirectMusicBand),
318 GE(GUID_IDirectMusicChordMap),
319 GE(GUID_IDirectMusicStyle),
320 GE(GUID_MuteParam),
321 GE(GUID_Play_Marker),
322 GE(GUID_RhythmParam),
323 GE(GUID_TempoParam),
324 GE(GUID_TimeSignature),
325 GE(GUID_Valid_Start_Time),
326 GE(GUID_Clear_All_Bands),
327 GE(GUID_ConnectToDLSCollection),
328 GE(GUID_Disable_Auto_Download),
329 GE(GUID_DisableTempo),
330 GE(GUID_DisableTimeSig),
331 GE(GUID_Download),
332 GE(GUID_DownloadToAudioPath),
333 GE(GUID_Enable_Auto_Download),
334 GE(GUID_EnableTempo),
335 GE(GUID_EnableTimeSig),
336 GE(GUID_IgnoreBankSelectForGM),
337 GE(GUID_SeedVariations),
338 GE(GUID_StandardMIDIFile),
339 GE(GUID_Unload),
340 GE(GUID_UnloadFromAudioPath),
341 GE(GUID_Variations),
342 GE(GUID_PerfMasterTempo),
343 GE(GUID_PerfMasterVolume),
344 GE(GUID_PerfMasterGrooveLevel),
345 GE(GUID_PerfAutoDownload),
346 GE(GUID_DefaultGMCollection),
347 GE(GUID_Synth_Default),
348 GE(GUID_Buffer_Reverb),
349 GE(GUID_Buffer_EnvReverb),
350 GE(GUID_Buffer_Stereo),
351 GE(GUID_Buffer_3D_Dry),
352 GE(GUID_Buffer_Mono),
353 GE(GUID_DMUS_PROP_GM_Hardware),
354 GE(GUID_DMUS_PROP_GS_Capable),
355 GE(GUID_DMUS_PROP_GS_Hardware),
356 GE(GUID_DMUS_PROP_DLS1),
357 GE(GUID_DMUS_PROP_DLS2),
358 GE(GUID_DMUS_PROP_Effects),
359 GE(GUID_DMUS_PROP_INSTRUMENT2),
360 GE(GUID_DMUS_PROP_LegacyCaps),
361 GE(GUID_DMUS_PROP_MemorySize),
362 GE(GUID_DMUS_PROP_SampleMemorySize),
363 GE(GUID_DMUS_PROP_SamplePlaybackRate),
364 GE(GUID_DMUS_PROP_SetSynthSink),
365 GE(GUID_DMUS_PROP_SinkUsesDSound),
366 GE(GUID_DMUS_PROP_SynthSink_DSOUND),
367 GE(GUID_DMUS_PROP_SynthSink_WAVE),
368 GE(GUID_DMUS_PROP_Volume),
369 GE(GUID_DMUS_PROP_WavesReverb),
370 GE(GUID_DMUS_PROP_WriteLatency),
371 GE(GUID_DMUS_PROP_WritePeriod),
372 GE(GUID_DMUS_PROP_XG_Capable),
373 GE(GUID_DMUS_PROP_XG_Hardware)
376 unsigned int i;
378 if (!id) return "(null)";
380 for (i = 0; i < ARRAY_SIZE(guids); i++) {
381 if (IsEqualGUID(id, guids[i].guid))
382 return guids[i].name;
384 /* if we didn't find it, act like standard debugstr_guid */
385 return debugstr_guid(id);
388 /* generic flag-dumping function */
389 static const char* debugstr_flags (DWORD flags, const flag_info* names, size_t num_names){
390 char buffer[128] = "", *ptr = &buffer[0];
391 unsigned int i;
392 int size = sizeof(buffer);
394 for (i=0; i < num_names; i++)
396 if ((flags & names[i].val) || /* standard flag*/
397 ((!flags) && (!names[i].val))) { /* zero value only */
398 int cnt = snprintf(ptr, size, "%s ", names[i].name);
399 if (cnt < 0 || cnt >= size) break;
400 size -= cnt;
401 ptr += cnt;
405 return wine_dbg_sprintf("%s", buffer);
408 /* dump DMUS_OBJ flags */
409 static const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask) {
410 static const flag_info flags[] = {
411 FE(DMUS_OBJ_OBJECT),
412 FE(DMUS_OBJ_CLASS),
413 FE(DMUS_OBJ_NAME),
414 FE(DMUS_OBJ_CATEGORY),
415 FE(DMUS_OBJ_FILENAME),
416 FE(DMUS_OBJ_FULLPATH),
417 FE(DMUS_OBJ_URL),
418 FE(DMUS_OBJ_VERSION),
419 FE(DMUS_OBJ_DATE),
420 FE(DMUS_OBJ_LOADED),
421 FE(DMUS_OBJ_MEMORY),
422 FE(DMUS_OBJ_STREAM)
424 return debugstr_flags(flagmask, flags, ARRAY_SIZE(flags));
427 /* dump whole DMUS_OBJECTDESC struct */
428 const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc) {
429 if (pDesc) {
430 char buffer[1024] = "", *ptr = &buffer[0];
432 ptr += sprintf(ptr, "DMUS_OBJECTDESC (%p):\n", pDesc);
433 ptr += sprintf(ptr, " - dwSize = %d\n", pDesc->dwSize);
434 ptr += sprintf(ptr, " - dwValidData = %s\n", debugstr_DMUS_OBJ_FLAGS (pDesc->dwValidData));
435 if (pDesc->dwValidData & DMUS_OBJ_CLASS) ptr += sprintf(ptr, " - guidClass = %s\n", debugstr_dmguid(&pDesc->guidClass));
436 if (pDesc->dwValidData & DMUS_OBJ_OBJECT) ptr += sprintf(ptr, " - guidObject = %s\n", debugstr_guid(&pDesc->guidObject));
437 if (pDesc->dwValidData & DMUS_OBJ_DATE) ptr += sprintf(ptr, " - ftDate = FIXME\n");
438 if (pDesc->dwValidData & DMUS_OBJ_VERSION) ptr += sprintf(ptr, " - vVersion = %s\n", debugstr_dmversion(&pDesc->vVersion));
439 if (pDesc->dwValidData & DMUS_OBJ_NAME) ptr += sprintf(ptr, " - wszName = %s\n", debugstr_w(pDesc->wszName));
440 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) ptr += sprintf(ptr, " - wszCategory = %s\n", debugstr_w(pDesc->wszCategory));
441 if (pDesc->dwValidData & DMUS_OBJ_FILENAME) ptr += sprintf(ptr, " - wszFileName = %s\n", debugstr_w(pDesc->wszFileName));
442 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) ptr += sprintf(ptr, " - llMemLength = 0x%s\n - pbMemData = %p\n",
443 wine_dbgstr_longlong(pDesc->llMemLength), pDesc->pbMemData);
444 if (pDesc->dwValidData & DMUS_OBJ_STREAM) ptr += sprintf(ptr, " - pStream = %p", pDesc->pStream);
446 return wine_dbg_sprintf("%s", buffer);
447 } else {
448 return wine_dbg_sprintf("(NULL)");