winex11: add owned windows to taskbar if owner is not mapped
[wine] / dlls / dsound / dsound_main.c
1 /*                      DirectSound
2  *
3  * Copyright 1998 Marcus Meissner
4  * Copyright 1998 Rob Riggs
5  * Copyright 2000-2002 TransGaming Technologies, Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  *
21  * Most thread locking is complete. There may be a few race
22  * conditions still lurking.
23  *
24  * TODO:
25  *      Implement SetCooperativeLevel properly (need to address focus issues)
26  *      Implement DirectSound3DBuffers (stubs in place)
27  *      Use hardware 3D support if available
28  *      Add critical section locking inside Release and AddRef methods
29  *      Handle static buffers - put those in hardware, non-static not in hardware
30  *      Hardware DuplicateSoundBuffer
31  *      Proper volume calculation for 3d buffers
32  *      Remove DS_HEL_FRAGS and use mixer fragment length for it
33  */
34
35 #include <stdarg.h>
36
37 #define COBJMACROS
38 #define NONAMELESSSTRUCT
39 #define NONAMELESSUNION
40 #include "windef.h"
41 #include "winbase.h"
42 #include "winuser.h"
43 #include "winnls.h"
44 #include "winreg.h"
45 #include "mmsystem.h"
46 #include "winternl.h"
47 #include "mmddk.h"
48 #include "wine/debug.h"
49 #include "dsound.h"
50 #include "dsconf.h"
51 #include "ks.h"
52 #include "initguid.h"
53 #include "ksmedia.h"
54 #include "dsdriver.h"
55
56 #include "dsound_private.h"
57
58 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
59
60 DirectSoundDevice*      DSOUND_renderer[MAXWAVEDRIVERS];
61 GUID                    DSOUND_renderer_guids[MAXWAVEDRIVERS];
62 GUID                    DSOUND_capture_guids[MAXWAVEDRIVERS];
63
64 HRESULT mmErr(UINT err)
65 {
66         switch(err) {
67         case MMSYSERR_NOERROR:
68                 return DS_OK;
69         case MMSYSERR_ALLOCATED:
70                 return DSERR_ALLOCATED;
71         case MMSYSERR_ERROR:
72         case MMSYSERR_INVALHANDLE:
73         case WAVERR_STILLPLAYING:
74                 return DSERR_GENERIC; /* FIXME */
75         case MMSYSERR_NODRIVER:
76                 return DSERR_NODRIVER;
77         case MMSYSERR_NOMEM:
78                 return DSERR_OUTOFMEMORY;
79         case MMSYSERR_INVALPARAM:
80         case WAVERR_BADFORMAT:
81         case WAVERR_UNPREPARED:
82                 return DSERR_INVALIDPARAM;
83         case MMSYSERR_NOTSUPPORTED:
84                 return DSERR_UNSUPPORTED;
85         default:
86                 FIXME("Unknown MMSYS error %d\n",err);
87                 return DSERR_GENERIC;
88         }
89 }
90
91 /* All default settings, you most likely don't want to touch these, see wiki on UsefulRegistryKeys */
92 int ds_emuldriver = 0;
93 int ds_hel_buflen = 32768;
94 int ds_snd_queue_max = 10;
95 int ds_snd_queue_min = 6;
96 int ds_snd_shadow_maxsize = 2;
97 int ds_hw_accel = DS_HW_ACCEL_FULL;
98 int ds_default_playback = 0;
99 int ds_default_capture = 0;
100 int ds_default_sample_rate = 44100;
101 int ds_default_bits_per_sample = 16;
102
103 /*
104  * Get a config key from either the app-specific or the default config
105  */
106
107 static inline DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
108                                     char *buffer, DWORD size )
109 {
110     if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
111     if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
112     return ERROR_FILE_NOT_FOUND;
113 }
114
115
116 /*
117  * Setup the dsound options.
118  */
119
120 void setup_dsound_options(void)
121 {
122     char buffer[MAX_PATH+16];
123     HKEY hkey, appkey = 0;
124     DWORD len;
125
126     buffer[MAX_PATH]='\0';
127
128     /* @@ Wine registry key: HKCU\Software\Wine\DirectSound */
129     if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\DirectSound", &hkey )) hkey = 0;
130
131     len = GetModuleFileNameA( 0, buffer, MAX_PATH );
132     if (len && len < MAX_PATH)
133     {
134         HKEY tmpkey;
135         /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectSound */
136         if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
137         {
138             char *p, *appname = buffer;
139             if ((p = strrchr( appname, '/' ))) appname = p + 1;
140             if ((p = strrchr( appname, '\\' ))) appname = p + 1;
141             strcat( appname, "\\DirectSound" );
142             TRACE("appname = [%s]\n", appname);
143             if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
144             RegCloseKey( tmpkey );
145         }
146     }
147
148     /* get options */
149
150     if (!get_config_key( hkey, appkey, "EmulDriver", buffer, MAX_PATH ))
151         ds_emuldriver = strcmp(buffer, "N");
152
153     if (!get_config_key( hkey, appkey, "HelBuflen", buffer, MAX_PATH ))
154         ds_hel_buflen = atoi(buffer);
155
156     if (!get_config_key( hkey, appkey, "SndQueueMax", buffer, MAX_PATH ))
157         ds_snd_queue_max = atoi(buffer);
158
159     if (!get_config_key( hkey, appkey, "SndQueueMin", buffer, MAX_PATH ))
160         ds_snd_queue_min = atoi(buffer);
161
162     if (!get_config_key( hkey, appkey, "HardwareAcceleration", buffer, MAX_PATH )) {
163         if (strcmp(buffer, "Full") == 0)
164             ds_hw_accel = DS_HW_ACCEL_FULL;
165         else if (strcmp(buffer, "Standard") == 0)
166             ds_hw_accel = DS_HW_ACCEL_STANDARD;
167         else if (strcmp(buffer, "Basic") == 0)
168             ds_hw_accel = DS_HW_ACCEL_BASIC;
169         else if (strcmp(buffer, "Emulation") == 0)
170             ds_hw_accel = DS_HW_ACCEL_EMULATION;
171     }
172
173     if (!get_config_key( hkey, appkey, "DefaultPlayback", buffer, MAX_PATH ))
174         ds_default_playback = atoi(buffer);
175
176     if (!get_config_key( hkey, appkey, "MaxShadowSize", buffer, MAX_PATH ))
177         ds_snd_shadow_maxsize = atoi(buffer);
178
179     if (!get_config_key( hkey, appkey, "DefaultCapture", buffer, MAX_PATH ))
180         ds_default_capture = atoi(buffer);
181
182     if (!get_config_key( hkey, appkey, "DefaultSampleRate", buffer, MAX_PATH ))
183         ds_default_sample_rate = atoi(buffer);
184
185     if (!get_config_key( hkey, appkey, "DefaultBitsPerSample", buffer, MAX_PATH ))
186         ds_default_bits_per_sample = atoi(buffer);
187
188     if (appkey) RegCloseKey( appkey );
189     if (hkey) RegCloseKey( hkey );
190
191     TRACE("ds_emuldriver = %d\n", ds_emuldriver);
192     TRACE("ds_hel_buflen = %d\n", ds_hel_buflen);
193     TRACE("ds_snd_queue_max = %d\n", ds_snd_queue_max);
194     TRACE("ds_snd_queue_min = %d\n", ds_snd_queue_min);
195     TRACE("ds_hw_accel = %s\n",
196         ds_hw_accel==DS_HW_ACCEL_FULL ? "Full" :
197         ds_hw_accel==DS_HW_ACCEL_STANDARD ? "Standard" :
198         ds_hw_accel==DS_HW_ACCEL_BASIC ? "Basic" :
199         ds_hw_accel==DS_HW_ACCEL_EMULATION ? "Emulation" :
200         "Unknown");
201     TRACE("ds_default_playback = %d\n", ds_default_playback);
202     TRACE("ds_default_capture = %d\n", ds_default_playback);
203     TRACE("ds_default_sample_rate = %d\n", ds_default_sample_rate);
204     TRACE("ds_default_bits_per_sample = %d\n", ds_default_bits_per_sample);
205     TRACE("ds_snd_shadow_maxsize = %d\n", ds_snd_shadow_maxsize);
206 }
207
208 static const char * get_device_id(LPCGUID pGuid)
209 {
210     if (IsEqualGUID(&DSDEVID_DefaultPlayback, pGuid))
211         return "DSDEVID_DefaultPlayback";
212     else if (IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuid))
213         return "DSDEVID_DefaultVoicePlayback";
214     else if (IsEqualGUID(&DSDEVID_DefaultCapture, pGuid))
215         return "DSDEVID_DefaultCapture";
216     else if (IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuid))
217         return "DSDEVID_DefaultVoiceCapture";
218     return debugstr_guid(pGuid);
219 }
220
221 /***************************************************************************
222  * GetDeviceID  [DSOUND.9]
223  *
224  * Retrieves unique identifier of default device specified
225  *
226  * PARAMS
227  *    pGuidSrc  [I] Address of device GUID.
228  *    pGuidDest [O] Address to receive unique device GUID.
229  *
230  * RETURNS
231  *    Success: DS_OK
232  *    Failure: DSERR_INVALIDPARAM
233  *
234  * NOTES
235  *    pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
236  *    DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
237  *    DSDEVID_DefaultVoiceCapture.
238  *    Returns pGuidSrc if pGuidSrc is a valid device or the device
239  *    GUID for the specified constants.
240  */
241 HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest)
242 {
243     TRACE("(%s,%p)\n", get_device_id(pGuidSrc),pGuidDest);
244
245     if ( pGuidSrc == NULL) {
246         WARN("invalid parameter: pGuidSrc == NULL\n");
247         return DSERR_INVALIDPARAM;
248     }
249
250     if ( pGuidDest == NULL ) {
251         WARN("invalid parameter: pGuidDest == NULL\n");
252         return DSERR_INVALIDPARAM;
253     }
254
255     if ( IsEqualGUID( &DSDEVID_DefaultPlayback, pGuidSrc ) ||
256          IsEqualGUID( &DSDEVID_DefaultVoicePlayback, pGuidSrc ) ) {
257         *pGuidDest = DSOUND_renderer_guids[ds_default_playback];
258         TRACE("returns %s\n", get_device_id(pGuidDest));
259         return DS_OK;
260     }
261
262     if ( IsEqualGUID( &DSDEVID_DefaultCapture, pGuidSrc ) ||
263          IsEqualGUID( &DSDEVID_DefaultVoiceCapture, pGuidSrc ) ) {
264         *pGuidDest = DSOUND_capture_guids[ds_default_capture];
265         TRACE("returns %s\n", get_device_id(pGuidDest));
266         return DS_OK;
267     }
268
269     *pGuidDest = *pGuidSrc;
270     TRACE("returns %s\n", get_device_id(pGuidDest));
271
272     return DS_OK;
273 }
274
275
276 /***************************************************************************
277  * DirectSoundEnumerateA [DSOUND.2]
278  *
279  * Enumerate all DirectSound drivers installed in the system
280  *
281  * PARAMS
282  *    lpDSEnumCallback  [I] Address of callback function.
283  *    lpContext         [I] Address of user defined context passed to callback function.
284  *
285  * RETURNS
286  *    Success: DS_OK
287  *    Failure: DSERR_INVALIDPARAM
288  */
289 HRESULT WINAPI DirectSoundEnumerateA(
290     LPDSENUMCALLBACKA lpDSEnumCallback,
291     LPVOID lpContext)
292 {
293     unsigned devs, wod;
294     DSDRIVERDESC desc;
295     GUID guid;
296     int err;
297
298     TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
299         lpDSEnumCallback, lpContext);
300
301     if (lpDSEnumCallback == NULL) {
302         WARN("invalid parameter: lpDSEnumCallback == NULL\n");
303         return DSERR_INVALIDPARAM;
304     }
305
306     devs = waveOutGetNumDevs();
307     if (devs > 0) {
308         if (GetDeviceID(&DSDEVID_DefaultPlayback, &guid) == DS_OK) {
309             for (wod = 0; wod < devs; ++wod) {
310                 if (IsEqualGUID( &guid, &DSOUND_renderer_guids[wod]) ) {
311                     err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
312                     if (err == DS_OK) {
313                         TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
314                               "Primary Sound Driver",desc.szDrvname,lpContext);
315                         if (lpDSEnumCallback(NULL, "Primary Sound Driver", desc.szDrvname, lpContext) == FALSE)
316                             return DS_OK;
317                     }
318                 }
319             }
320         }
321     }
322
323     for (wod = 0; wod < devs; ++wod) {
324         err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
325         if (err == DS_OK) {
326             TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
327                   debugstr_guid(&DSOUND_renderer_guids[wod]),desc.szDesc,desc.szDrvname,lpContext);
328             if (lpDSEnumCallback(&DSOUND_renderer_guids[wod], desc.szDesc, desc.szDrvname, lpContext) == FALSE)
329                 return DS_OK;
330         }
331     }
332     return DS_OK;
333 }
334
335 /***************************************************************************
336  * DirectSoundEnumerateW [DSOUND.3]
337  *
338  * Enumerate all DirectSound drivers installed in the system
339  *
340  * PARAMS
341  *    lpDSEnumCallback  [I] Address of callback function.
342  *    lpContext         [I] Address of user defined context passed to callback function.
343  *
344  * RETURNS
345  *    Success: DS_OK
346  *    Failure: DSERR_INVALIDPARAM
347  */
348 HRESULT WINAPI DirectSoundEnumerateW(
349         LPDSENUMCALLBACKW lpDSEnumCallback,
350         LPVOID lpContext )
351 {
352     unsigned devs, wod;
353     DSDRIVERDESC desc;
354     GUID guid;
355     int err;
356     WCHAR wDesc[MAXPNAMELEN];
357     WCHAR wName[MAXPNAMELEN];
358
359     TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
360         lpDSEnumCallback, lpContext);
361
362     if (lpDSEnumCallback == NULL) {
363         WARN("invalid parameter: lpDSEnumCallback == NULL\n");
364         return DSERR_INVALIDPARAM;
365     }
366
367     devs = waveOutGetNumDevs();
368     if (devs > 0) {
369         if (GetDeviceID(&DSDEVID_DefaultPlayback, &guid) == DS_OK) {
370             for (wod = 0; wod < devs; ++wod) {
371                 if (IsEqualGUID( &guid, &DSOUND_renderer_guids[wod] ) ) {
372                     err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
373                     if (err == DS_OK) {
374                         TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
375                               "Primary Sound Driver",desc.szDrvname,lpContext);
376                         MultiByteToWideChar( CP_ACP, 0, "Primary Sound Driver", -1,
377                                              wDesc, sizeof(wDesc)/sizeof(WCHAR) );
378                         MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1,
379                                              wName, sizeof(wName)/sizeof(WCHAR) );
380                         if (lpDSEnumCallback(NULL, wDesc, wName, lpContext) == FALSE)
381                             return DS_OK;
382                     }
383                 }
384             }
385         }
386     }
387
388     for (wod = 0; wod < devs; ++wod) {
389         err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
390         if (err == DS_OK) {
391             TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
392                   debugstr_guid(&DSOUND_renderer_guids[wod]),desc.szDesc,desc.szDrvname,lpContext);
393             MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1,
394                                  wDesc, sizeof(wDesc)/sizeof(WCHAR) );
395             MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1,
396                                  wName, sizeof(wName)/sizeof(WCHAR) );
397             if (lpDSEnumCallback(&DSOUND_renderer_guids[wod], wDesc, wName, lpContext) == FALSE)
398                 return DS_OK;
399         }
400     }
401     return DS_OK;
402 }
403
404 /*******************************************************************************
405  * DirectSound ClassFactory
406  */
407
408 typedef  HRESULT (*FnCreateInstance)(REFIID riid, LPVOID *ppobj);
409  
410 typedef struct {
411     const IClassFactoryVtbl *lpVtbl;
412     LONG ref;
413     REFCLSID rclsid;
414     FnCreateInstance pfnCreateInstance;
415 } IClassFactoryImpl;
416
417 static HRESULT WINAPI
418 DSCF_QueryInterface(LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj)
419 {
420     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
421     TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
422     if (ppobj == NULL)
423         return E_POINTER;
424     if (IsEqualIID(riid, &IID_IUnknown) ||
425         IsEqualIID(riid, &IID_IClassFactory))
426     {
427         *ppobj = iface;
428         IUnknown_AddRef(iface);
429         return S_OK;
430     }
431     *ppobj = NULL;
432     return E_NOINTERFACE;
433 }
434
435 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
436 {
437     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
438     ULONG ref = InterlockedIncrement(&(This->ref));
439     TRACE("(%p) ref was %d\n", This, ref - 1);
440     return ref;
441 }
442
443 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
444 {
445     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
446     ULONG ref = InterlockedDecrement(&(This->ref));
447     TRACE("(%p) ref was %d\n", This, ref + 1);
448     /* static class, won't be freed */
449     return ref;
450 }
451
452 static HRESULT WINAPI DSCF_CreateInstance(
453     LPCLASSFACTORY iface,
454     LPUNKNOWN pOuter,
455     REFIID riid,
456     LPVOID *ppobj)
457 {
458     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
459     TRACE("(%p, %p, %s, %p)\n", This, pOuter, debugstr_guid(riid), ppobj);
460
461     if (pOuter)
462         return CLASS_E_NOAGGREGATION;
463
464     if (ppobj == NULL) {
465         WARN("invalid parameter\n");
466         return DSERR_INVALIDPARAM;
467     }
468     *ppobj = NULL;
469     return This->pfnCreateInstance(riid, ppobj);
470 }
471  
472 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
473 {
474     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
475     FIXME("(%p, %d) stub!\n", This, dolock);
476     return S_OK;
477 }
478
479 static const IClassFactoryVtbl DSCF_Vtbl = {
480     DSCF_QueryInterface,
481     DSCF_AddRef,
482     DSCF_Release,
483     DSCF_CreateInstance,
484     DSCF_LockServer
485 };
486
487 static IClassFactoryImpl DSOUND_CF[] = {
488     { &DSCF_Vtbl, 1, &CLSID_DirectSound, (FnCreateInstance)DSOUND_Create },
489     { &DSCF_Vtbl, 1, &CLSID_DirectSound8, (FnCreateInstance)DSOUND_Create8 },
490     { &DSCF_Vtbl, 1, &CLSID_DirectSoundCapture, (FnCreateInstance)DSOUND_CaptureCreate },
491     { &DSCF_Vtbl, 1, &CLSID_DirectSoundCapture8, (FnCreateInstance)DSOUND_CaptureCreate8 },
492     { &DSCF_Vtbl, 1, &CLSID_DirectSoundFullDuplex, (FnCreateInstance)DSOUND_FullDuplexCreate },
493     { &DSCF_Vtbl, 1, &CLSID_DirectSoundPrivate, (FnCreateInstance)IKsPrivatePropertySetImpl_Create },
494     { NULL, 0, NULL, NULL }
495 };
496
497 /*******************************************************************************
498  * DllGetClassObject [DSOUND.@]
499  * Retrieves class object from a DLL object
500  *
501  * NOTES
502  *    Docs say returns STDAPI
503  *
504  * PARAMS
505  *    rclsid [I] CLSID for the class object
506  *    riid   [I] Reference to identifier of interface for class object
507  *    ppv    [O] Address of variable to receive interface pointer for riid
508  *
509  * RETURNS
510  *    Success: S_OK
511  *    Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
512  *             E_UNEXPECTED
513  */
514 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
515 {
516     int i = 0;
517     TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
518
519     if (ppv == NULL) {
520         WARN("invalid parameter\n");
521         return E_INVALIDARG;
522     }
523
524     *ppv = NULL;
525
526     if (!IsEqualIID(riid, &IID_IClassFactory) &&
527         !IsEqualIID(riid, &IID_IUnknown)) {
528         WARN("no interface for %s\n", debugstr_guid(riid));
529         return E_NOINTERFACE;
530     }
531
532     while (NULL != DSOUND_CF[i].rclsid) {
533         if (IsEqualGUID(rclsid, DSOUND_CF[i].rclsid)) {
534             DSCF_AddRef((IClassFactory*) &DSOUND_CF[i]);
535             *ppv = &DSOUND_CF[i];
536             return S_OK;
537         }
538         i++;
539     }
540
541     WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid),
542          debugstr_guid(riid), ppv);
543     return CLASS_E_CLASSNOTAVAILABLE;
544 }
545
546
547 /*******************************************************************************
548  * DllCanUnloadNow [DSOUND.4]
549  * Determines whether the DLL is in use.
550  *
551  * RETURNS
552  *    Success: S_OK
553  *    Failure: S_FALSE
554  */
555 HRESULT WINAPI DllCanUnloadNow(void)
556 {
557     FIXME("(void): stub\n");
558     return S_FALSE;
559 }
560
561 #define INIT_GUID(guid, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)      \
562         guid.Data1 = l; guid.Data2 = w1; guid.Data3 = w2;               \
563         guid.Data4[0] = b1; guid.Data4[1] = b2; guid.Data4[2] = b3;     \
564         guid.Data4[3] = b4; guid.Data4[4] = b5; guid.Data4[5] = b6;     \
565         guid.Data4[6] = b7; guid.Data4[7] = b8;
566
567 /***********************************************************************
568  *           DllMain (DSOUND.init)
569  */
570 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
571 {
572     int i;
573     TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpvReserved);
574
575     switch (fdwReason) {
576     case DLL_PROCESS_ATTACH:
577         TRACE("DLL_PROCESS_ATTACH\n");
578         for (i = 0; i < MAXWAVEDRIVERS; i++) {
579             DSOUND_renderer[i] = NULL;
580             DSOUND_capture[i] = NULL;
581             INIT_GUID(DSOUND_renderer_guids[i], 0xbd6dd71a, 0x3deb, 0x11d1, 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 + i);
582             INIT_GUID(DSOUND_capture_guids[i],  0xbd6dd71b, 0x3deb, 0x11d1, 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 + i);
583         }
584         DisableThreadLibraryCalls(hInstDLL);
585         /* Increase refcount on dsound by 1 */
586         GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)hInstDLL, &hInstDLL);
587         break;
588     case DLL_PROCESS_DETACH:
589         TRACE("DLL_PROCESS_DETACH\n");
590         break;
591     default:
592         TRACE("UNKNOWN REASON\n");
593         break;
594     }
595     return TRUE;
596 }