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