3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998 Rob Riggs
5 * Copyright 2000-2002 TransGaming Technologies, Inc.
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.
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.
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
21 * Most thread locking is complete. There may be a few race
22 * conditions still lurking.
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
38 #define NONAMELESSSTRUCT
39 #define NONAMELESSUNION
48 #include "wine/debug.h"
64 #include "dsound_private.h"
66 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
68 struct list DSOUND_renderers = LIST_INIT(DSOUND_renderers);
69 CRITICAL_SECTION DSOUND_renderers_lock;
71 struct list DSOUND_capturers = LIST_INIT(DSOUND_capturers);
72 CRITICAL_SECTION DSOUND_capturers_lock;
74 GUID DSOUND_renderer_guids[MAXWAVEDRIVERS];
75 GUID DSOUND_capture_guids[MAXWAVEDRIVERS];
77 static IMMDeviceEnumerator *g_devenum;
78 static CRITICAL_SECTION g_devenum_lock;
79 static HANDLE g_devenum_thread;
81 WCHAR wine_vxd_drv[] = { 'w','i','n','e','m','m','.','v','x','d', 0 };
83 HRESULT mmErr(UINT err)
86 case MMSYSERR_NOERROR:
88 case MMSYSERR_ALLOCATED:
89 return DSERR_ALLOCATED;
91 case MMSYSERR_INVALHANDLE:
92 case WAVERR_STILLPLAYING:
93 return DSERR_GENERIC; /* FIXME */
94 case MMSYSERR_NODRIVER:
95 return DSERR_NODRIVER;
97 return DSERR_OUTOFMEMORY;
98 case MMSYSERR_INVALPARAM:
99 case WAVERR_BADFORMAT:
100 case WAVERR_UNPREPARED:
101 return DSERR_INVALIDPARAM;
102 case MMSYSERR_NOTSUPPORTED:
103 return DSERR_UNSUPPORTED;
105 FIXME("Unknown MMSYS error %d\n",err);
106 return DSERR_GENERIC;
110 /* All default settings, you most likely don't want to touch these, see wiki on UsefulRegistryKeys */
111 int ds_emuldriver = 0;
112 int ds_hel_buflen = 32768 * 2;
113 int ds_snd_queue_max = 10;
114 int ds_snd_shadow_maxsize = 2;
115 int ds_default_sample_rate = 44100;
116 int ds_default_bits_per_sample = 16;
117 static int ds_default_playback;
118 static int ds_default_capture;
119 static HINSTANCE instance;
122 * Get a config key from either the app-specific or the default config
125 static inline DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
126 char *buffer, DWORD size )
128 if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
129 if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
130 return ERROR_FILE_NOT_FOUND;
135 * Setup the dsound options.
138 void setup_dsound_options(void)
140 char buffer[MAX_PATH+16];
141 HKEY hkey, appkey = 0;
144 buffer[MAX_PATH]='\0';
146 /* @@ Wine registry key: HKCU\Software\Wine\DirectSound */
147 if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\DirectSound", &hkey )) hkey = 0;
149 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
150 if (len && len < MAX_PATH)
153 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectSound */
154 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
156 char *p, *appname = buffer;
157 if ((p = strrchr( appname, '/' ))) appname = p + 1;
158 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
159 strcat( appname, "\\DirectSound" );
160 TRACE("appname = [%s]\n", appname);
161 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
162 RegCloseKey( tmpkey );
168 if (!get_config_key( hkey, appkey, "EmulDriver", buffer, MAX_PATH ))
169 ds_emuldriver = strcmp(buffer, "N");
171 if (!get_config_key( hkey, appkey, "HelBuflen", buffer, MAX_PATH ))
172 ds_hel_buflen = atoi(buffer);
174 if (!get_config_key( hkey, appkey, "SndQueueMax", buffer, MAX_PATH ))
175 ds_snd_queue_max = atoi(buffer);
177 if (!get_config_key( hkey, appkey, "DefaultPlayback", buffer, MAX_PATH ))
178 ds_default_playback = atoi(buffer);
180 if (!get_config_key( hkey, appkey, "MaxShadowSize", buffer, MAX_PATH ))
181 ds_snd_shadow_maxsize = atoi(buffer);
183 if (!get_config_key( hkey, appkey, "DefaultCapture", buffer, MAX_PATH ))
184 ds_default_capture = atoi(buffer);
186 if (!get_config_key( hkey, appkey, "DefaultSampleRate", buffer, MAX_PATH ))
187 ds_default_sample_rate = atoi(buffer);
189 if (!get_config_key( hkey, appkey, "DefaultBitsPerSample", buffer, MAX_PATH ))
190 ds_default_bits_per_sample = atoi(buffer);
192 if (appkey) RegCloseKey( appkey );
193 if (hkey) RegCloseKey( hkey );
195 TRACE("ds_emuldriver = %d\n", ds_emuldriver);
196 TRACE("ds_hel_buflen = %d\n", ds_hel_buflen);
197 TRACE("ds_snd_queue_max = %d\n", ds_snd_queue_max);
198 TRACE("ds_default_playback = %d\n", ds_default_playback);
199 TRACE("ds_default_capture = %d\n", ds_default_capture);
200 TRACE("ds_default_sample_rate = %d\n", ds_default_sample_rate);
201 TRACE("ds_default_bits_per_sample = %d\n", ds_default_bits_per_sample);
202 TRACE("ds_snd_shadow_maxsize = %d\n", ds_snd_shadow_maxsize);
205 static const char * get_device_id(LPCGUID pGuid)
207 if (IsEqualGUID(&DSDEVID_DefaultPlayback, pGuid))
208 return "DSDEVID_DefaultPlayback";
209 else if (IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuid))
210 return "DSDEVID_DefaultVoicePlayback";
211 else if (IsEqualGUID(&DSDEVID_DefaultCapture, pGuid))
212 return "DSDEVID_DefaultCapture";
213 else if (IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuid))
214 return "DSDEVID_DefaultVoiceCapture";
215 return debugstr_guid(pGuid);
218 /* The MMDeviceEnumerator object has to be created & destroyed
219 * from the same thread. */
220 static DWORD WINAPI devenum_thread_proc(void *arg)
226 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
228 ERR("CoInitializeEx failed: %08x\n", hr);
232 hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL,
233 CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&g_devenum);
235 ERR("CoCreateInstance failed: %08x\n", hr);
242 PeekMessageW(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
244 while(GetMessageW(&msg, NULL, 0, 0)){
246 DispatchMessageW(&msg);
248 ERR("Unknown message: %04x\n", msg.message);
251 IMMDeviceEnumerator_Release(g_devenum);
258 static IMMDeviceEnumerator *get_mmdevenum(void)
263 EnterCriticalSection(&g_devenum_lock);
266 LeaveCriticalSection(&g_devenum_lock);
270 events[0] = CreateEventW(NULL, FALSE, FALSE, NULL);
272 g_devenum_thread = CreateThread(NULL, 0, devenum_thread_proc,
274 if(!g_devenum_thread){
275 LeaveCriticalSection(&g_devenum_lock);
276 CloseHandle(events[0]);
280 events[1] = g_devenum_thread;
281 wait = WaitForMultipleObjects(2, events, FALSE, INFINITE);
282 CloseHandle(events[0]);
283 if(wait != WAIT_OBJECT_0){
284 if(wait == 1 + WAIT_OBJECT_0){
285 CloseHandle(g_devenum_thread);
286 g_devenum_thread = NULL;
288 LeaveCriticalSection(&g_devenum_lock);
292 LeaveCriticalSection(&g_devenum_lock);
297 static HRESULT get_mmdevice_guid(IMMDevice *device, IPropertyStore *ps,
304 hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
306 WARN("OpenPropertyStore failed: %08x\n", hr);
310 IPropertyStore_AddRef(ps);
312 PropVariantInit(&pv);
314 hr = IPropertyStore_GetValue(ps, &PKEY_AudioEndpoint_GUID, &pv);
316 IPropertyStore_Release(ps);
317 WARN("GetValue(GUID) failed: %08x\n", hr);
321 CLSIDFromString(pv.u.pwszVal, guid);
323 PropVariantClear(&pv);
324 IPropertyStore_Release(ps);
329 /***************************************************************************
330 * GetDeviceID [DSOUND.9]
332 * Retrieves unique identifier of default device specified
335 * pGuidSrc [I] Address of device GUID.
336 * pGuidDest [O] Address to receive unique device GUID.
340 * Failure: DSERR_INVALIDPARAM
343 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
344 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
345 * DSDEVID_DefaultVoiceCapture.
346 * Returns pGuidSrc if pGuidSrc is a valid device or the device
347 * GUID for the specified constants.
349 HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest)
351 IMMDeviceEnumerator *devenum;
352 EDataFlow flow = (EDataFlow)-1;
353 ERole role = (ERole)-1;
356 TRACE("(%s,%p)\n", get_device_id(pGuidSrc),pGuidDest);
358 if(!pGuidSrc || !pGuidDest)
359 return DSERR_INVALIDPARAM;
361 devenum = get_mmdevenum();
363 return DSERR_GENERIC;
365 if(IsEqualGUID(&DSDEVID_DefaultPlayback, pGuidSrc)){
368 }else if(IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuidSrc)){
369 role = eCommunications;
371 }else if(IsEqualGUID(&DSDEVID_DefaultCapture, pGuidSrc)){
374 }else if(IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuidSrc)){
375 role = eCommunications;
379 if(role != (ERole)-1 && flow != (EDataFlow)-1){
382 hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum,
383 flow, role, &device);
385 WARN("GetDefaultAudioEndpoint failed: %08x\n", hr);
386 return DSERR_NODRIVER;
389 hr = get_mmdevice_guid(device, NULL, pGuidDest);
390 IMMDevice_Release(device);
392 return (hr == S_OK) ? DS_OK : hr;
395 *pGuidDest = *pGuidSrc;
402 LPDSENUMCALLBACKA callA;
406 static BOOL CALLBACK a_to_w_callback(LPGUID guid, LPCWSTR descW, LPCWSTR modW, LPVOID data)
408 struct morecontext *context = data;
409 char descA[MAXPNAMELEN], modA[MAXPNAMELEN];
411 WideCharToMultiByte(CP_ACP, 0, descW, -1, descA, sizeof(descA), NULL, NULL);
412 WideCharToMultiByte(CP_ACP, 0, modW, -1, modA, sizeof(modA), NULL, NULL);
414 return context->callA(guid, descA, modA, context->data);
417 /***************************************************************************
418 * DirectSoundEnumerateA [DSOUND.2]
420 * Enumerate all DirectSound drivers installed in the system
423 * lpDSEnumCallback [I] Address of callback function.
424 * lpContext [I] Address of user defined context passed to callback function.
428 * Failure: DSERR_INVALIDPARAM
430 HRESULT WINAPI DirectSoundEnumerateA(
431 LPDSENUMCALLBACKA lpDSEnumCallback,
434 struct morecontext context;
436 if (lpDSEnumCallback == NULL) {
437 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
438 return DSERR_INVALIDPARAM;
441 context.callA = lpDSEnumCallback;
442 context.data = lpContext;
444 return DirectSoundEnumerateW(a_to_w_callback, &context);
447 HRESULT get_mmdevice(EDataFlow flow, const GUID *tgt, IMMDevice **device)
449 IMMDeviceEnumerator *devenum;
450 IMMDeviceCollection *coll;
454 devenum = get_mmdevenum();
456 return DSERR_GENERIC;
458 hr = IMMDeviceEnumerator_EnumAudioEndpoints(devenum, flow,
459 DEVICE_STATE_ACTIVE, &coll);
461 WARN("EnumAudioEndpoints failed: %08x\n", hr);
465 hr = IMMDeviceCollection_GetCount(coll, &count);
467 IMMDeviceCollection_Release(coll);
468 WARN("GetCount failed: %08x\n", hr);
472 for(i = 0; i < count; ++i){
475 hr = IMMDeviceCollection_Item(coll, i, device);
479 hr = get_mmdevice_guid(*device, NULL, &guid);
481 IMMDevice_Release(*device);
485 if(IsEqualGUID(&guid, tgt))
488 IMMDevice_Release(*device);
491 WARN("No device with GUID %s found!\n", wine_dbgstr_guid(tgt));
493 return DSERR_INVALIDPARAM;
496 /* S_FALSE means the callback returned FALSE at some point
497 * S_OK means the callback always returned TRUE */
498 HRESULT enumerate_mmdevices(EDataFlow flow, GUID *guids,
499 LPDSENUMCALLBACKW cb, void *user)
501 IMMDeviceEnumerator *devenum;
502 IMMDeviceCollection *coll;
507 static const WCHAR primary_desc[] = {'P','r','i','m','a','r','y',' ',
508 'S','o','u','n','d',' ','D','r','i','v','e','r',0};
509 static const WCHAR empty_drv[] = {0};
511 devenum = get_mmdevenum();
515 hr = IMMDeviceEnumerator_EnumAudioEndpoints(g_devenum, flow,
516 DEVICE_STATE_ACTIVE, &coll);
518 WARN("EnumAudioEndpoints failed: %08x\n", hr);
522 hr = IMMDeviceCollection_GetCount(coll, &count);
524 IMMDeviceCollection_Release(coll);
525 WARN("GetCount failed: %08x\n", hr);
532 keep_going = cb(NULL, primary_desc, empty_drv, user);
534 for(i = 0; keep_going && i < count; ++i){
539 PropVariantInit(&pv);
541 hr = IMMDeviceCollection_Item(coll, i, &device);
543 WARN("Item failed: %08x\n", hr);
547 hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
549 IMMDevice_Release(device);
550 WARN("OpenPropertyStore failed: %08x\n", hr);
554 hr = get_mmdevice_guid(device, ps, &guids[i]);
556 IPropertyStore_Release(ps);
557 IMMDevice_Release(device);
561 hr = IPropertyStore_GetValue(ps,
562 (const PROPERTYKEY *)&DEVPKEY_Device_FriendlyName, &pv);
564 IPropertyStore_Release(ps);
565 IMMDevice_Release(device);
566 WARN("GetValue(FriendlyName) failed: %08x\n", hr);
570 keep_going = cb(&guids[i], pv.u.pwszVal, wine_vxd_drv, user);
572 PropVariantClear(&pv);
573 IPropertyStore_Release(ps);
574 IMMDevice_Release(device);
577 IMMDeviceCollection_Release(coll);
579 return (keep_going == TRUE) ? S_OK : S_FALSE;
582 /***************************************************************************
583 * DirectSoundEnumerateW [DSOUND.3]
585 * Enumerate all DirectSound drivers installed in the system
588 * lpDSEnumCallback [I] Address of callback function.
589 * lpContext [I] Address of user defined context passed to callback function.
593 * Failure: DSERR_INVALIDPARAM
595 HRESULT WINAPI DirectSoundEnumerateW(
596 LPDSENUMCALLBACKW lpDSEnumCallback,
601 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext);
603 if (lpDSEnumCallback == NULL) {
604 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
605 return DSERR_INVALIDPARAM;
608 setup_dsound_options();
610 hr = enumerate_mmdevices(eRender, DSOUND_renderer_guids,
611 lpDSEnumCallback, lpContext);
612 return SUCCEEDED(hr) ? DS_OK : hr;
615 /***************************************************************************
616 * DirectSoundCaptureEnumerateA [DSOUND.7]
618 * Enumerate all DirectSound drivers installed in the system.
621 * lpDSEnumCallback [I] Address of callback function.
622 * lpContext [I] Address of user defined context passed to callback function.
626 * Failure: DSERR_INVALIDPARAM
628 HRESULT WINAPI DirectSoundCaptureEnumerateA(
629 LPDSENUMCALLBACKA lpDSEnumCallback,
632 struct morecontext context;
634 if (lpDSEnumCallback == NULL) {
635 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
636 return DSERR_INVALIDPARAM;
639 context.callA = lpDSEnumCallback;
640 context.data = lpContext;
642 return DirectSoundCaptureEnumerateW(a_to_w_callback, &context);
645 /***************************************************************************
646 * DirectSoundCaptureEnumerateW [DSOUND.8]
648 * Enumerate all DirectSound drivers installed in the system.
651 * lpDSEnumCallback [I] Address of callback function.
652 * lpContext [I] Address of user defined context passed to callback function.
656 * Failure: DSERR_INVALIDPARAM
659 DirectSoundCaptureEnumerateW(
660 LPDSENUMCALLBACKW lpDSEnumCallback,
665 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext );
667 if (lpDSEnumCallback == NULL) {
668 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
669 return DSERR_INVALIDPARAM;
672 setup_dsound_options();
674 hr = enumerate_mmdevices(eCapture, DSOUND_capture_guids,
675 lpDSEnumCallback, lpContext);
676 return SUCCEEDED(hr) ? DS_OK : hr;
679 /*******************************************************************************
680 * DirectSound ClassFactory
683 typedef HRESULT (*FnCreateInstance)(REFIID riid, LPVOID *ppobj);
686 IClassFactory IClassFactory_iface;
688 FnCreateInstance pfnCreateInstance;
691 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
693 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
696 static HRESULT WINAPI
697 DSCF_QueryInterface(LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj)
699 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
700 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
703 if (IsEqualIID(riid, &IID_IUnknown) ||
704 IsEqualIID(riid, &IID_IClassFactory))
707 IUnknown_AddRef(iface);
711 return E_NOINTERFACE;
714 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
719 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
721 /* static class, won't be freed */
725 static HRESULT WINAPI DSCF_CreateInstance(
726 LPCLASSFACTORY iface,
731 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
732 TRACE("(%p, %p, %s, %p)\n", This, pOuter, debugstr_guid(riid), ppobj);
735 return CLASS_E_NOAGGREGATION;
738 WARN("invalid parameter\n");
739 return DSERR_INVALIDPARAM;
742 return This->pfnCreateInstance(riid, ppobj);
745 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
747 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
748 FIXME("(%p, %d) stub!\n", This, dolock);
752 static const IClassFactoryVtbl DSCF_Vtbl = {
760 static IClassFactoryImpl DSOUND_CF[] = {
761 { { &DSCF_Vtbl }, &CLSID_DirectSound, (FnCreateInstance)DSOUND_Create },
762 { { &DSCF_Vtbl }, &CLSID_DirectSound8, (FnCreateInstance)DSOUND_Create8 },
763 { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture, (FnCreateInstance)DSOUND_CaptureCreate },
764 { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture8, (FnCreateInstance)DSOUND_CaptureCreate8 },
765 { { &DSCF_Vtbl }, &CLSID_DirectSoundFullDuplex, (FnCreateInstance)DSOUND_FullDuplexCreate },
766 { { &DSCF_Vtbl }, &CLSID_DirectSoundPrivate, (FnCreateInstance)IKsPrivatePropertySetImpl_Create },
767 { { NULL }, NULL, NULL }
770 /*******************************************************************************
771 * DllGetClassObject [DSOUND.@]
772 * Retrieves class object from a DLL object
775 * Docs say returns STDAPI
778 * rclsid [I] CLSID for the class object
779 * riid [I] Reference to identifier of interface for class object
780 * ppv [O] Address of variable to receive interface pointer for riid
784 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
787 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
790 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
793 WARN("invalid parameter\n");
799 if (!IsEqualIID(riid, &IID_IClassFactory) &&
800 !IsEqualIID(riid, &IID_IUnknown)) {
801 WARN("no interface for %s\n", debugstr_guid(riid));
802 return E_NOINTERFACE;
805 while (NULL != DSOUND_CF[i].rclsid) {
806 if (IsEqualGUID(rclsid, DSOUND_CF[i].rclsid)) {
807 DSCF_AddRef(&DSOUND_CF[i].IClassFactory_iface);
808 *ppv = &DSOUND_CF[i];
814 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid),
815 debugstr_guid(riid), ppv);
816 return CLASS_E_CLASSNOTAVAILABLE;
820 /*******************************************************************************
821 * DllCanUnloadNow [DSOUND.4]
822 * Determines whether the DLL is in use.
825 * Can unload now: S_OK
826 * Cannot unload now (the DLL is still active): S_FALSE
828 HRESULT WINAPI DllCanUnloadNow(void)
833 #define INIT_GUID(guid, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
834 guid.Data1 = l; guid.Data2 = w1; guid.Data3 = w2; \
835 guid.Data4[0] = b1; guid.Data4[1] = b2; guid.Data4[2] = b3; \
836 guid.Data4[3] = b4; guid.Data4[4] = b5; guid.Data4[5] = b6; \
837 guid.Data4[6] = b7; guid.Data4[7] = b8;
839 /***********************************************************************
840 * DllMain (DSOUND.init)
842 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
844 TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpvReserved);
847 case DLL_PROCESS_ATTACH:
848 TRACE("DLL_PROCESS_ATTACH\n");
850 DisableThreadLibraryCalls(hInstDLL);
851 /* Increase refcount on dsound by 1 */
852 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)hInstDLL, &hInstDLL);
853 InitializeCriticalSection(&DSOUND_renderers_lock);
854 InitializeCriticalSection(&DSOUND_capturers_lock);
855 InitializeCriticalSection(&g_devenum_lock);
857 case DLL_PROCESS_DETACH:
858 TRACE("DLL_PROCESS_DETACH\n");
861 TRACE("UNKNOWN REASON\n");
867 /***********************************************************************
868 * DllRegisterServer (DSOUND.@)
870 HRESULT WINAPI DllRegisterServer(void)
872 return __wine_register_resources( instance );
875 /***********************************************************************
876 * DllUnregisterServer (DSOUND.@)
878 HRESULT WINAPI DllUnregisterServer(void)
880 return __wine_unregister_resources( instance );