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;
70 static CRITICAL_SECTION_DEBUG DSOUND_renderers_lock_debug =
72 0, 0, &DSOUND_renderers_lock,
73 { &DSOUND_renderers_lock_debug.ProcessLocksList, &DSOUND_renderers_lock_debug.ProcessLocksList },
74 0, 0, { (DWORD_PTR)(__FILE__ ": DSOUND_renderers_lock") }
76 CRITICAL_SECTION DSOUND_renderers_lock = { &DSOUND_renderers_lock_debug, -1, 0, 0, 0, 0 };
78 struct list DSOUND_capturers = LIST_INIT(DSOUND_capturers);
79 CRITICAL_SECTION DSOUND_capturers_lock;
80 static CRITICAL_SECTION_DEBUG DSOUND_capturers_lock_debug =
82 0, 0, &DSOUND_capturers_lock,
83 { &DSOUND_capturers_lock_debug.ProcessLocksList, &DSOUND_capturers_lock_debug.ProcessLocksList },
84 0, 0, { (DWORD_PTR)(__FILE__ ": DSOUND_capturers_lock") }
86 CRITICAL_SECTION DSOUND_capturers_lock = { &DSOUND_capturers_lock_debug, -1, 0, 0, 0, 0 };
88 GUID DSOUND_renderer_guids[MAXWAVEDRIVERS];
89 GUID DSOUND_capture_guids[MAXWAVEDRIVERS];
91 static IMMDeviceEnumerator *g_devenum;
92 static CRITICAL_SECTION g_devenum_lock;
93 static CRITICAL_SECTION_DEBUG g_devenum_lock_debug =
95 0, 0, &g_devenum_lock,
96 { &g_devenum_lock_debug.ProcessLocksList, &g_devenum_lock_debug.ProcessLocksList },
97 0, 0, { (DWORD_PTR)(__FILE__ ": g_devenum_lock") }
99 static CRITICAL_SECTION g_devenum_lock = { &g_devenum_lock_debug, -1, 0, 0, 0, 0 };
100 static HANDLE g_devenum_thread;
102 WCHAR wine_vxd_drv[] = { 'w','i','n','e','m','m','.','v','x','d', 0 };
104 HRESULT mmErr(UINT err)
107 case MMSYSERR_NOERROR:
109 case MMSYSERR_ALLOCATED:
110 return DSERR_ALLOCATED;
112 case MMSYSERR_INVALHANDLE:
113 case WAVERR_STILLPLAYING:
114 return DSERR_GENERIC; /* FIXME */
115 case MMSYSERR_NODRIVER:
116 return DSERR_NODRIVER;
118 return DSERR_OUTOFMEMORY;
119 case MMSYSERR_INVALPARAM:
120 case WAVERR_BADFORMAT:
121 case WAVERR_UNPREPARED:
122 return DSERR_INVALIDPARAM;
123 case MMSYSERR_NOTSUPPORTED:
124 return DSERR_UNSUPPORTED;
126 FIXME("Unknown MMSYS error %d\n",err);
127 return DSERR_GENERIC;
131 /* All default settings, you most likely don't want to touch these, see wiki on UsefulRegistryKeys */
132 int ds_hel_buflen = 32768 * 2;
133 int ds_snd_queue_max = 10;
134 int ds_snd_shadow_maxsize = 2;
135 int ds_default_sample_rate = 44100;
136 int ds_default_bits_per_sample = 16;
137 static HINSTANCE instance;
140 * Get a config key from either the app-specific or the default config
143 static inline DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
144 char *buffer, DWORD size )
146 if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
147 if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
148 return ERROR_FILE_NOT_FOUND;
153 * Setup the dsound options.
156 void setup_dsound_options(void)
158 char buffer[MAX_PATH+16];
159 HKEY hkey, appkey = 0;
162 buffer[MAX_PATH]='\0';
164 /* @@ Wine registry key: HKCU\Software\Wine\DirectSound */
165 if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\DirectSound", &hkey )) hkey = 0;
167 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
168 if (len && len < MAX_PATH)
171 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectSound */
172 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
174 char *p, *appname = buffer;
175 if ((p = strrchr( appname, '/' ))) appname = p + 1;
176 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
177 strcat( appname, "\\DirectSound" );
178 TRACE("appname = [%s]\n", appname);
179 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
180 RegCloseKey( tmpkey );
186 if (!get_config_key( hkey, appkey, "HelBuflen", buffer, MAX_PATH ))
187 ds_hel_buflen = atoi(buffer);
189 if (!get_config_key( hkey, appkey, "SndQueueMax", buffer, MAX_PATH ))
190 ds_snd_queue_max = atoi(buffer);
192 if (!get_config_key( hkey, appkey, "MaxShadowSize", buffer, MAX_PATH ))
193 ds_snd_shadow_maxsize = atoi(buffer);
195 if (!get_config_key( hkey, appkey, "DefaultSampleRate", buffer, MAX_PATH ))
196 ds_default_sample_rate = atoi(buffer);
198 if (!get_config_key( hkey, appkey, "DefaultBitsPerSample", buffer, MAX_PATH ))
199 ds_default_bits_per_sample = atoi(buffer);
201 if (appkey) RegCloseKey( appkey );
202 if (hkey) RegCloseKey( hkey );
204 TRACE("ds_hel_buflen = %d\n", ds_hel_buflen);
205 TRACE("ds_snd_queue_max = %d\n", ds_snd_queue_max);
206 TRACE("ds_default_sample_rate = %d\n", ds_default_sample_rate);
207 TRACE("ds_default_bits_per_sample = %d\n", ds_default_bits_per_sample);
208 TRACE("ds_snd_shadow_maxsize = %d\n", ds_snd_shadow_maxsize);
211 static const char * get_device_id(LPCGUID pGuid)
213 if (IsEqualGUID(&DSDEVID_DefaultPlayback, pGuid))
214 return "DSDEVID_DefaultPlayback";
215 else if (IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuid))
216 return "DSDEVID_DefaultVoicePlayback";
217 else if (IsEqualGUID(&DSDEVID_DefaultCapture, pGuid))
218 return "DSDEVID_DefaultCapture";
219 else if (IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuid))
220 return "DSDEVID_DefaultVoiceCapture";
221 return debugstr_guid(pGuid);
224 /* The MMDeviceEnumerator object has to be created & destroyed
225 * from the same thread. */
226 static DWORD WINAPI devenum_thread_proc(void *arg)
232 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
234 ERR("CoInitializeEx failed: %08x\n", hr);
238 hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL,
239 CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&g_devenum);
241 ERR("CoCreateInstance failed: %08x\n", hr);
248 PeekMessageW(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
250 while(GetMessageW(&msg, NULL, 0, 0)){
252 DispatchMessageW(&msg);
254 ERR("Unknown message: %04x\n", msg.message);
257 IMMDeviceEnumerator_Release(g_devenum);
264 static IMMDeviceEnumerator *get_mmdevenum(void)
269 EnterCriticalSection(&g_devenum_lock);
272 LeaveCriticalSection(&g_devenum_lock);
276 events[0] = CreateEventW(NULL, FALSE, FALSE, NULL);
278 g_devenum_thread = CreateThread(NULL, 0, devenum_thread_proc,
280 if(!g_devenum_thread){
281 LeaveCriticalSection(&g_devenum_lock);
282 CloseHandle(events[0]);
286 events[1] = g_devenum_thread;
287 wait = WaitForMultipleObjects(2, events, FALSE, INFINITE);
288 CloseHandle(events[0]);
289 if(wait != WAIT_OBJECT_0){
290 if(wait == 1 + WAIT_OBJECT_0){
291 CloseHandle(g_devenum_thread);
292 g_devenum_thread = NULL;
294 LeaveCriticalSection(&g_devenum_lock);
298 LeaveCriticalSection(&g_devenum_lock);
303 static HRESULT get_mmdevice_guid(IMMDevice *device, IPropertyStore *ps,
310 hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
312 WARN("OpenPropertyStore failed: %08x\n", hr);
316 IPropertyStore_AddRef(ps);
318 PropVariantInit(&pv);
320 hr = IPropertyStore_GetValue(ps, &PKEY_AudioEndpoint_GUID, &pv);
322 IPropertyStore_Release(ps);
323 WARN("GetValue(GUID) failed: %08x\n", hr);
327 CLSIDFromString(pv.u.pwszVal, guid);
329 PropVariantClear(&pv);
330 IPropertyStore_Release(ps);
335 /***************************************************************************
336 * GetDeviceID [DSOUND.9]
338 * Retrieves unique identifier of default device specified
341 * pGuidSrc [I] Address of device GUID.
342 * pGuidDest [O] Address to receive unique device GUID.
346 * Failure: DSERR_INVALIDPARAM
349 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
350 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
351 * DSDEVID_DefaultVoiceCapture.
352 * Returns pGuidSrc if pGuidSrc is a valid device or the device
353 * GUID for the specified constants.
355 HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest)
357 IMMDeviceEnumerator *devenum;
358 EDataFlow flow = (EDataFlow)-1;
359 ERole role = (ERole)-1;
362 TRACE("(%s,%p)\n", get_device_id(pGuidSrc),pGuidDest);
364 if(!pGuidSrc || !pGuidDest)
365 return DSERR_INVALIDPARAM;
367 devenum = get_mmdevenum();
369 return DSERR_GENERIC;
371 if(IsEqualGUID(&DSDEVID_DefaultPlayback, pGuidSrc)){
374 }else if(IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuidSrc)){
375 role = eCommunications;
377 }else if(IsEqualGUID(&DSDEVID_DefaultCapture, pGuidSrc)){
380 }else if(IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuidSrc)){
381 role = eCommunications;
385 if(role != (ERole)-1 && flow != (EDataFlow)-1){
388 hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum,
389 flow, role, &device);
391 WARN("GetDefaultAudioEndpoint failed: %08x\n", hr);
392 return DSERR_NODRIVER;
395 hr = get_mmdevice_guid(device, NULL, pGuidDest);
396 IMMDevice_Release(device);
398 return (hr == S_OK) ? DS_OK : hr;
401 *pGuidDest = *pGuidSrc;
408 LPDSENUMCALLBACKA callA;
412 static BOOL CALLBACK a_to_w_callback(LPGUID guid, LPCWSTR descW, LPCWSTR modW, LPVOID data)
414 struct morecontext *context = data;
415 char descA[MAXPNAMELEN], modA[MAXPNAMELEN];
417 WideCharToMultiByte(CP_ACP, 0, descW, -1, descA, sizeof(descA), NULL, NULL);
418 WideCharToMultiByte(CP_ACP, 0, modW, -1, modA, sizeof(modA), NULL, NULL);
420 return context->callA(guid, descA, modA, context->data);
423 /***************************************************************************
424 * DirectSoundEnumerateA [DSOUND.2]
426 * Enumerate all DirectSound drivers installed in the system
429 * lpDSEnumCallback [I] Address of callback function.
430 * lpContext [I] Address of user defined context passed to callback function.
434 * Failure: DSERR_INVALIDPARAM
436 HRESULT WINAPI DirectSoundEnumerateA(
437 LPDSENUMCALLBACKA lpDSEnumCallback,
440 struct morecontext context;
442 if (lpDSEnumCallback == NULL) {
443 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
444 return DSERR_INVALIDPARAM;
447 context.callA = lpDSEnumCallback;
448 context.data = lpContext;
450 return DirectSoundEnumerateW(a_to_w_callback, &context);
453 HRESULT get_mmdevice(EDataFlow flow, const GUID *tgt, IMMDevice **device)
455 IMMDeviceEnumerator *devenum;
456 IMMDeviceCollection *coll;
460 devenum = get_mmdevenum();
462 return DSERR_GENERIC;
464 hr = IMMDeviceEnumerator_EnumAudioEndpoints(devenum, flow,
465 DEVICE_STATE_ACTIVE, &coll);
467 WARN("EnumAudioEndpoints failed: %08x\n", hr);
471 hr = IMMDeviceCollection_GetCount(coll, &count);
473 IMMDeviceCollection_Release(coll);
474 WARN("GetCount failed: %08x\n", hr);
478 for(i = 0; i < count; ++i){
481 hr = IMMDeviceCollection_Item(coll, i, device);
485 hr = get_mmdevice_guid(*device, NULL, &guid);
487 IMMDevice_Release(*device);
491 if(IsEqualGUID(&guid, tgt))
494 IMMDevice_Release(*device);
497 WARN("No device with GUID %s found!\n", wine_dbgstr_guid(tgt));
499 return DSERR_INVALIDPARAM;
502 static BOOL send_device(IMMDevice *device, GUID *guid,
503 LPDSENUMCALLBACKW cb, void *user)
510 PropVariantInit(&pv);
512 hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
514 WARN("OpenPropertyStore failed: %08x\n", hr);
518 hr = get_mmdevice_guid(device, ps, guid);
520 IPropertyStore_Release(ps);
524 hr = IPropertyStore_GetValue(ps,
525 (const PROPERTYKEY *)&DEVPKEY_Device_FriendlyName, &pv);
527 IPropertyStore_Release(ps);
528 WARN("GetValue(FriendlyName) failed: %08x\n", hr);
532 TRACE("Calling back with %s (%s)\n", wine_dbgstr_guid(guid),
533 wine_dbgstr_w(pv.u.pwszVal));
535 keep_going = cb(guid, pv.u.pwszVal, wine_vxd_drv, user);
537 PropVariantClear(&pv);
538 IPropertyStore_Release(ps);
543 /* S_FALSE means the callback returned FALSE at some point
544 * S_OK means the callback always returned TRUE */
545 HRESULT enumerate_mmdevices(EDataFlow flow, GUID *guids,
546 LPDSENUMCALLBACKW cb, void *user)
548 IMMDeviceEnumerator *devenum;
549 IMMDeviceCollection *coll;
550 IMMDevice *defdev = NULL;
555 static const WCHAR primary_desc[] = {'P','r','i','m','a','r','y',' ',
556 'S','o','u','n','d',' ','D','r','i','v','e','r',0};
557 static const WCHAR empty_drv[] = {0};
559 devenum = get_mmdevenum();
563 hr = IMMDeviceEnumerator_EnumAudioEndpoints(g_devenum, flow,
564 DEVICE_STATE_ACTIVE, &coll);
566 WARN("EnumAudioEndpoints failed: %08x\n", hr);
570 hr = IMMDeviceCollection_GetCount(coll, &count);
572 IMMDeviceCollection_Release(coll);
573 WARN("GetCount failed: %08x\n", hr);
580 TRACE("Calling back with NULL (%s)\n", wine_dbgstr_w(primary_desc));
581 keep_going = cb(NULL, primary_desc, empty_drv, user);
583 /* always send the default device first */
585 hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum, flow,
586 eMultimedia, &defdev);
591 keep_going = send_device(defdev, &guids[0], cb, user);
596 for(i = 0; keep_going && i < count; ++i){
599 hr = IMMDeviceCollection_Item(coll, i, &device);
601 WARN("Item failed: %08x\n", hr);
605 if(device != defdev){
606 send_device(device, &guids[n], cb, user);
610 IMMDevice_Release(device);
614 IMMDevice_Release(defdev);
615 IMMDeviceCollection_Release(coll);
617 return (keep_going == TRUE) ? S_OK : S_FALSE;
620 /***************************************************************************
621 * DirectSoundEnumerateW [DSOUND.3]
623 * Enumerate all DirectSound drivers installed in the system
626 * lpDSEnumCallback [I] Address of callback function.
627 * lpContext [I] Address of user defined context passed to callback function.
631 * Failure: DSERR_INVALIDPARAM
633 HRESULT WINAPI DirectSoundEnumerateW(
634 LPDSENUMCALLBACKW lpDSEnumCallback,
639 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext);
641 if (lpDSEnumCallback == NULL) {
642 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
643 return DSERR_INVALIDPARAM;
646 setup_dsound_options();
648 hr = enumerate_mmdevices(eRender, DSOUND_renderer_guids,
649 lpDSEnumCallback, lpContext);
650 return SUCCEEDED(hr) ? DS_OK : hr;
653 /***************************************************************************
654 * DirectSoundCaptureEnumerateA [DSOUND.7]
656 * Enumerate all DirectSound drivers installed in the system.
659 * lpDSEnumCallback [I] Address of callback function.
660 * lpContext [I] Address of user defined context passed to callback function.
664 * Failure: DSERR_INVALIDPARAM
666 HRESULT WINAPI DirectSoundCaptureEnumerateA(
667 LPDSENUMCALLBACKA lpDSEnumCallback,
670 struct morecontext context;
672 if (lpDSEnumCallback == NULL) {
673 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
674 return DSERR_INVALIDPARAM;
677 context.callA = lpDSEnumCallback;
678 context.data = lpContext;
680 return DirectSoundCaptureEnumerateW(a_to_w_callback, &context);
683 /***************************************************************************
684 * DirectSoundCaptureEnumerateW [DSOUND.8]
686 * Enumerate all DirectSound drivers installed in the system.
689 * lpDSEnumCallback [I] Address of callback function.
690 * lpContext [I] Address of user defined context passed to callback function.
694 * Failure: DSERR_INVALIDPARAM
697 DirectSoundCaptureEnumerateW(
698 LPDSENUMCALLBACKW lpDSEnumCallback,
703 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext );
705 if (lpDSEnumCallback == NULL) {
706 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
707 return DSERR_INVALIDPARAM;
710 setup_dsound_options();
712 hr = enumerate_mmdevices(eCapture, DSOUND_capture_guids,
713 lpDSEnumCallback, lpContext);
714 return SUCCEEDED(hr) ? DS_OK : hr;
717 /*******************************************************************************
718 * DirectSound ClassFactory
721 typedef HRESULT (*FnCreateInstance)(REFIID riid, LPVOID *ppobj);
724 IClassFactory IClassFactory_iface;
726 FnCreateInstance pfnCreateInstance;
729 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
731 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
734 static HRESULT WINAPI
735 DSCF_QueryInterface(LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj)
737 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
738 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
741 if (IsEqualIID(riid, &IID_IUnknown) ||
742 IsEqualIID(riid, &IID_IClassFactory))
745 IUnknown_AddRef(iface);
749 return E_NOINTERFACE;
752 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
757 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
759 /* static class, won't be freed */
763 static HRESULT WINAPI DSCF_CreateInstance(
764 LPCLASSFACTORY iface,
769 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
770 TRACE("(%p, %p, %s, %p)\n", This, pOuter, debugstr_guid(riid), ppobj);
773 return CLASS_E_NOAGGREGATION;
776 WARN("invalid parameter\n");
777 return DSERR_INVALIDPARAM;
780 return This->pfnCreateInstance(riid, ppobj);
783 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
785 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
786 FIXME("(%p, %d) stub!\n", This, dolock);
790 static const IClassFactoryVtbl DSCF_Vtbl = {
798 static IClassFactoryImpl DSOUND_CF[] = {
799 { { &DSCF_Vtbl }, &CLSID_DirectSound, (FnCreateInstance)DSOUND_Create },
800 { { &DSCF_Vtbl }, &CLSID_DirectSound8, (FnCreateInstance)DSOUND_Create8 },
801 { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture, (FnCreateInstance)DSOUND_CaptureCreate },
802 { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture8, (FnCreateInstance)DSOUND_CaptureCreate8 },
803 { { &DSCF_Vtbl }, &CLSID_DirectSoundFullDuplex, (FnCreateInstance)DSOUND_FullDuplexCreate },
804 { { &DSCF_Vtbl }, &CLSID_DirectSoundPrivate, (FnCreateInstance)IKsPrivatePropertySetImpl_Create },
805 { { NULL }, NULL, NULL }
808 /*******************************************************************************
809 * DllGetClassObject [DSOUND.@]
810 * Retrieves class object from a DLL object
813 * Docs say returns STDAPI
816 * rclsid [I] CLSID for the class object
817 * riid [I] Reference to identifier of interface for class object
818 * ppv [O] Address of variable to receive interface pointer for riid
822 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
825 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
828 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
831 WARN("invalid parameter\n");
837 if (!IsEqualIID(riid, &IID_IClassFactory) &&
838 !IsEqualIID(riid, &IID_IUnknown)) {
839 WARN("no interface for %s\n", debugstr_guid(riid));
840 return E_NOINTERFACE;
843 while (NULL != DSOUND_CF[i].rclsid) {
844 if (IsEqualGUID(rclsid, DSOUND_CF[i].rclsid)) {
845 DSCF_AddRef(&DSOUND_CF[i].IClassFactory_iface);
846 *ppv = &DSOUND_CF[i];
852 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid),
853 debugstr_guid(riid), ppv);
854 return CLASS_E_CLASSNOTAVAILABLE;
858 /*******************************************************************************
859 * DllCanUnloadNow [DSOUND.4]
860 * Determines whether the DLL is in use.
863 * Can unload now: S_OK
864 * Cannot unload now (the DLL is still active): S_FALSE
866 HRESULT WINAPI DllCanUnloadNow(void)
871 #define INIT_GUID(guid, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
872 guid.Data1 = l; guid.Data2 = w1; guid.Data3 = w2; \
873 guid.Data4[0] = b1; guid.Data4[1] = b2; guid.Data4[2] = b3; \
874 guid.Data4[3] = b4; guid.Data4[4] = b5; guid.Data4[5] = b6; \
875 guid.Data4[6] = b7; guid.Data4[7] = b8;
877 /***********************************************************************
878 * DllMain (DSOUND.init)
880 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
882 TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpvReserved);
885 case DLL_PROCESS_ATTACH:
886 TRACE("DLL_PROCESS_ATTACH\n");
888 DisableThreadLibraryCalls(hInstDLL);
889 /* Increase refcount on dsound by 1 */
890 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)hInstDLL, &hInstDLL);
892 case DLL_PROCESS_DETACH:
893 TRACE("DLL_PROCESS_DETACH\n");
894 DeleteCriticalSection(&DSOUND_renderers_lock);
895 DeleteCriticalSection(&DSOUND_capturers_lock);
896 DeleteCriticalSection(&g_devenum_lock);
899 TRACE("UNKNOWN REASON\n");
905 /***********************************************************************
906 * DllRegisterServer (DSOUND.@)
908 HRESULT WINAPI DllRegisterServer(void)
910 return __wine_register_resources( instance );
913 /***********************************************************************
914 * DllUnregisterServer (DSOUND.@)
916 HRESULT WINAPI DllUnregisterServer(void)
918 return __wine_unregister_resources( instance );