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 /* All default settings, you most likely don't want to touch these, see wiki on UsefulRegistryKeys */
105 int ds_hel_buflen
= 32768 * 2;
106 int ds_snd_queue_max
= 10;
107 int ds_default_sample_rate
= 44100;
108 int ds_default_bits_per_sample
= 16;
109 static HINSTANCE instance
;
112 * Get a config key from either the app-specific or the default config
115 static inline DWORD
get_config_key( HKEY defkey
, HKEY appkey
, const char *name
,
116 char *buffer
, DWORD size
)
118 if (appkey
&& !RegQueryValueExA( appkey
, name
, 0, NULL
, (LPBYTE
)buffer
, &size
)) return 0;
119 if (defkey
&& !RegQueryValueExA( defkey
, name
, 0, NULL
, (LPBYTE
)buffer
, &size
)) return 0;
120 return ERROR_FILE_NOT_FOUND
;
125 * Setup the dsound options.
128 void setup_dsound_options(void)
130 char buffer
[MAX_PATH
+16];
131 HKEY hkey
, appkey
= 0;
134 buffer
[MAX_PATH
]='\0';
136 /* @@ Wine registry key: HKCU\Software\Wine\DirectSound */
137 if (RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\DirectSound", &hkey
)) hkey
= 0;
139 len
= GetModuleFileNameA( 0, buffer
, MAX_PATH
);
140 if (len
&& len
< MAX_PATH
)
143 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectSound */
144 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\AppDefaults", &tmpkey
))
146 char *p
, *appname
= buffer
;
147 if ((p
= strrchr( appname
, '/' ))) appname
= p
+ 1;
148 if ((p
= strrchr( appname
, '\\' ))) appname
= p
+ 1;
149 strcat( appname
, "\\DirectSound" );
150 TRACE("appname = [%s]\n", appname
);
151 if (RegOpenKeyA( tmpkey
, appname
, &appkey
)) appkey
= 0;
152 RegCloseKey( tmpkey
);
158 if (!get_config_key( hkey
, appkey
, "HelBuflen", buffer
, MAX_PATH
))
159 ds_hel_buflen
= atoi(buffer
);
161 if (!get_config_key( hkey
, appkey
, "SndQueueMax", buffer
, MAX_PATH
))
162 ds_snd_queue_max
= atoi(buffer
);
165 if (!get_config_key( hkey
, appkey
, "DefaultSampleRate", buffer
, MAX_PATH
))
166 ds_default_sample_rate
= atoi(buffer
);
168 if (!get_config_key( hkey
, appkey
, "DefaultBitsPerSample", buffer
, MAX_PATH
))
169 ds_default_bits_per_sample
= atoi(buffer
);
171 if (appkey
) RegCloseKey( appkey
);
172 if (hkey
) RegCloseKey( hkey
);
174 TRACE("ds_hel_buflen = %d\n", ds_hel_buflen
);
175 TRACE("ds_snd_queue_max = %d\n", ds_snd_queue_max
);
176 TRACE("ds_default_sample_rate = %d\n", ds_default_sample_rate
);
177 TRACE("ds_default_bits_per_sample = %d\n", ds_default_bits_per_sample
);
180 static const char * get_device_id(LPCGUID pGuid
)
182 if (IsEqualGUID(&DSDEVID_DefaultPlayback
, pGuid
))
183 return "DSDEVID_DefaultPlayback";
184 else if (IsEqualGUID(&DSDEVID_DefaultVoicePlayback
, pGuid
))
185 return "DSDEVID_DefaultVoicePlayback";
186 else if (IsEqualGUID(&DSDEVID_DefaultCapture
, pGuid
))
187 return "DSDEVID_DefaultCapture";
188 else if (IsEqualGUID(&DSDEVID_DefaultVoiceCapture
, pGuid
))
189 return "DSDEVID_DefaultVoiceCapture";
190 return debugstr_guid(pGuid
);
193 /* The MMDeviceEnumerator object has to be created & destroyed
194 * from the same thread. */
195 static DWORD WINAPI
devenum_thread_proc(void *arg
)
201 hr
= CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
203 ERR("CoInitializeEx failed: %08x\n", hr
);
207 hr
= CoCreateInstance(&CLSID_MMDeviceEnumerator
, NULL
,
208 CLSCTX_INPROC_SERVER
, &IID_IMMDeviceEnumerator
, (void**)&g_devenum
);
210 ERR("CoCreateInstance failed: %08x\n", hr
);
217 PeekMessageW(&msg
, NULL
, WM_USER
, WM_USER
, PM_NOREMOVE
);
219 while(GetMessageW(&msg
, NULL
, 0, 0)){
221 DispatchMessageW(&msg
);
223 ERR("Unknown message: %04x\n", msg
.message
);
226 IMMDeviceEnumerator_Release(g_devenum
);
233 static IMMDeviceEnumerator
*get_mmdevenum(void)
238 EnterCriticalSection(&g_devenum_lock
);
241 LeaveCriticalSection(&g_devenum_lock
);
245 events
[0] = CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
247 g_devenum_thread
= CreateThread(NULL
, 0, devenum_thread_proc
,
249 if(!g_devenum_thread
){
250 LeaveCriticalSection(&g_devenum_lock
);
251 CloseHandle(events
[0]);
255 events
[1] = g_devenum_thread
;
256 wait
= WaitForMultipleObjects(2, events
, FALSE
, INFINITE
);
257 CloseHandle(events
[0]);
258 if(wait
!= WAIT_OBJECT_0
){
259 if(wait
== 1 + WAIT_OBJECT_0
){
260 CloseHandle(g_devenum_thread
);
261 g_devenum_thread
= NULL
;
263 LeaveCriticalSection(&g_devenum_lock
);
267 LeaveCriticalSection(&g_devenum_lock
);
272 static HRESULT
get_mmdevice_guid(IMMDevice
*device
, IPropertyStore
*ps
,
279 hr
= IMMDevice_OpenPropertyStore(device
, STGM_READ
, &ps
);
281 WARN("OpenPropertyStore failed: %08x\n", hr
);
285 IPropertyStore_AddRef(ps
);
287 PropVariantInit(&pv
);
289 hr
= IPropertyStore_GetValue(ps
, &PKEY_AudioEndpoint_GUID
, &pv
);
291 IPropertyStore_Release(ps
);
292 WARN("GetValue(GUID) failed: %08x\n", hr
);
296 CLSIDFromString(pv
.u
.pwszVal
, guid
);
298 PropVariantClear(&pv
);
299 IPropertyStore_Release(ps
);
304 /***************************************************************************
305 * GetDeviceID [DSOUND.9]
307 * Retrieves unique identifier of default device specified
310 * pGuidSrc [I] Address of device GUID.
311 * pGuidDest [O] Address to receive unique device GUID.
315 * Failure: DSERR_INVALIDPARAM
318 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
319 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
320 * DSDEVID_DefaultVoiceCapture.
321 * Returns pGuidSrc if pGuidSrc is a valid device or the device
322 * GUID for the specified constants.
324 HRESULT WINAPI
GetDeviceID(LPCGUID pGuidSrc
, LPGUID pGuidDest
)
326 IMMDeviceEnumerator
*devenum
;
327 EDataFlow flow
= (EDataFlow
)-1;
328 ERole role
= (ERole
)-1;
331 TRACE("(%s,%p)\n", get_device_id(pGuidSrc
),pGuidDest
);
333 if(!pGuidSrc
|| !pGuidDest
)
334 return DSERR_INVALIDPARAM
;
336 devenum
= get_mmdevenum();
338 return DSERR_GENERIC
;
340 if(IsEqualGUID(&DSDEVID_DefaultPlayback
, pGuidSrc
)){
343 }else if(IsEqualGUID(&DSDEVID_DefaultVoicePlayback
, pGuidSrc
)){
344 role
= eCommunications
;
346 }else if(IsEqualGUID(&DSDEVID_DefaultCapture
, pGuidSrc
)){
349 }else if(IsEqualGUID(&DSDEVID_DefaultVoiceCapture
, pGuidSrc
)){
350 role
= eCommunications
;
354 if(role
!= (ERole
)-1 && flow
!= (EDataFlow
)-1){
357 hr
= IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum
,
358 flow
, role
, &device
);
360 WARN("GetDefaultAudioEndpoint failed: %08x\n", hr
);
361 return DSERR_NODRIVER
;
364 hr
= get_mmdevice_guid(device
, NULL
, pGuidDest
);
365 IMMDevice_Release(device
);
367 return (hr
== S_OK
) ? DS_OK
: hr
;
370 *pGuidDest
= *pGuidSrc
;
377 LPDSENUMCALLBACKA callA
;
381 static BOOL CALLBACK
a_to_w_callback(LPGUID guid
, LPCWSTR descW
, LPCWSTR modW
, LPVOID data
)
383 struct morecontext
*context
= data
;
384 char descA
[MAXPNAMELEN
], modA
[MAXPNAMELEN
];
386 WideCharToMultiByte(CP_ACP
, 0, descW
, -1, descA
, sizeof(descA
), NULL
, NULL
);
387 WideCharToMultiByte(CP_ACP
, 0, modW
, -1, modA
, sizeof(modA
), NULL
, NULL
);
389 return context
->callA(guid
, descA
, modA
, context
->data
);
392 /***************************************************************************
393 * DirectSoundEnumerateA [DSOUND.2]
395 * Enumerate all DirectSound drivers installed in the system
398 * lpDSEnumCallback [I] Address of callback function.
399 * lpContext [I] Address of user defined context passed to callback function.
403 * Failure: DSERR_INVALIDPARAM
405 HRESULT WINAPI
DirectSoundEnumerateA(
406 LPDSENUMCALLBACKA lpDSEnumCallback
,
409 struct morecontext context
;
411 if (lpDSEnumCallback
== NULL
) {
412 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
413 return DSERR_INVALIDPARAM
;
416 context
.callA
= lpDSEnumCallback
;
417 context
.data
= lpContext
;
419 return DirectSoundEnumerateW(a_to_w_callback
, &context
);
422 HRESULT
get_mmdevice(EDataFlow flow
, const GUID
*tgt
, IMMDevice
**device
)
424 IMMDeviceEnumerator
*devenum
;
425 IMMDeviceCollection
*coll
;
429 devenum
= get_mmdevenum();
431 return DSERR_GENERIC
;
433 hr
= IMMDeviceEnumerator_EnumAudioEndpoints(devenum
, flow
,
434 DEVICE_STATE_ACTIVE
, &coll
);
436 WARN("EnumAudioEndpoints failed: %08x\n", hr
);
440 hr
= IMMDeviceCollection_GetCount(coll
, &count
);
442 IMMDeviceCollection_Release(coll
);
443 WARN("GetCount failed: %08x\n", hr
);
447 for(i
= 0; i
< count
; ++i
){
450 hr
= IMMDeviceCollection_Item(coll
, i
, device
);
454 hr
= get_mmdevice_guid(*device
, NULL
, &guid
);
456 IMMDevice_Release(*device
);
460 if(IsEqualGUID(&guid
, tgt
))
463 IMMDevice_Release(*device
);
466 WARN("No device with GUID %s found!\n", wine_dbgstr_guid(tgt
));
468 return DSERR_INVALIDPARAM
;
471 static BOOL
send_device(IMMDevice
*device
, GUID
*guid
,
472 LPDSENUMCALLBACKW cb
, void *user
)
479 PropVariantInit(&pv
);
481 hr
= IMMDevice_OpenPropertyStore(device
, STGM_READ
, &ps
);
483 WARN("OpenPropertyStore failed: %08x\n", hr
);
487 hr
= get_mmdevice_guid(device
, ps
, guid
);
489 IPropertyStore_Release(ps
);
493 hr
= IPropertyStore_GetValue(ps
,
494 (const PROPERTYKEY
*)&DEVPKEY_Device_FriendlyName
, &pv
);
496 IPropertyStore_Release(ps
);
497 WARN("GetValue(FriendlyName) failed: %08x\n", hr
);
501 TRACE("Calling back with %s (%s)\n", wine_dbgstr_guid(guid
),
502 wine_dbgstr_w(pv
.u
.pwszVal
));
504 keep_going
= cb(guid
, pv
.u
.pwszVal
, wine_vxd_drv
, user
);
506 PropVariantClear(&pv
);
507 IPropertyStore_Release(ps
);
512 /* S_FALSE means the callback returned FALSE at some point
513 * S_OK means the callback always returned TRUE */
514 HRESULT
enumerate_mmdevices(EDataFlow flow
, GUID
*guids
,
515 LPDSENUMCALLBACKW cb
, void *user
)
517 IMMDeviceEnumerator
*devenum
;
518 IMMDeviceCollection
*coll
;
519 IMMDevice
*defdev
= NULL
;
524 static const WCHAR primary_desc
[] = {'P','r','i','m','a','r','y',' ',
525 'S','o','u','n','d',' ','D','r','i','v','e','r',0};
526 static const WCHAR empty_drv
[] = {0};
528 devenum
= get_mmdevenum();
532 hr
= IMMDeviceEnumerator_EnumAudioEndpoints(g_devenum
, flow
,
533 DEVICE_STATE_ACTIVE
, &coll
);
535 WARN("EnumAudioEndpoints failed: %08x\n", hr
);
539 hr
= IMMDeviceCollection_GetCount(coll
, &count
);
541 IMMDeviceCollection_Release(coll
);
542 WARN("GetCount failed: %08x\n", hr
);
549 TRACE("Calling back with NULL (%s)\n", wine_dbgstr_w(primary_desc
));
550 keep_going
= cb(NULL
, primary_desc
, empty_drv
, user
);
552 /* always send the default device first */
554 hr
= IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum
, flow
,
555 eMultimedia
, &defdev
);
560 keep_going
= send_device(defdev
, &guids
[0], cb
, user
);
565 for(i
= 0; keep_going
&& i
< count
; ++i
){
568 hr
= IMMDeviceCollection_Item(coll
, i
, &device
);
570 WARN("Item failed: %08x\n", hr
);
574 if(device
!= defdev
){
575 send_device(device
, &guids
[n
], cb
, user
);
579 IMMDevice_Release(device
);
583 IMMDevice_Release(defdev
);
584 IMMDeviceCollection_Release(coll
);
586 return (keep_going
== TRUE
) ? S_OK
: S_FALSE
;
589 /***************************************************************************
590 * DirectSoundEnumerateW [DSOUND.3]
592 * Enumerate all DirectSound drivers installed in the system
595 * lpDSEnumCallback [I] Address of callback function.
596 * lpContext [I] Address of user defined context passed to callback function.
600 * Failure: DSERR_INVALIDPARAM
602 HRESULT WINAPI
DirectSoundEnumerateW(
603 LPDSENUMCALLBACKW lpDSEnumCallback
,
608 TRACE("(%p,%p)\n", lpDSEnumCallback
, lpContext
);
610 if (lpDSEnumCallback
== NULL
) {
611 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
612 return DSERR_INVALIDPARAM
;
615 setup_dsound_options();
617 hr
= enumerate_mmdevices(eRender
, DSOUND_renderer_guids
,
618 lpDSEnumCallback
, lpContext
);
619 return SUCCEEDED(hr
) ? DS_OK
: hr
;
622 /***************************************************************************
623 * DirectSoundCaptureEnumerateA [DSOUND.7]
625 * Enumerate all DirectSound drivers installed in the system.
628 * lpDSEnumCallback [I] Address of callback function.
629 * lpContext [I] Address of user defined context passed to callback function.
633 * Failure: DSERR_INVALIDPARAM
635 HRESULT WINAPI
DirectSoundCaptureEnumerateA(
636 LPDSENUMCALLBACKA lpDSEnumCallback
,
639 struct morecontext context
;
641 if (lpDSEnumCallback
== NULL
) {
642 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
643 return DSERR_INVALIDPARAM
;
646 context
.callA
= lpDSEnumCallback
;
647 context
.data
= lpContext
;
649 return DirectSoundCaptureEnumerateW(a_to_w_callback
, &context
);
652 /***************************************************************************
653 * DirectSoundCaptureEnumerateW [DSOUND.8]
655 * Enumerate all DirectSound drivers installed in the system.
658 * lpDSEnumCallback [I] Address of callback function.
659 * lpContext [I] Address of user defined context passed to callback function.
663 * Failure: DSERR_INVALIDPARAM
666 DirectSoundCaptureEnumerateW(
667 LPDSENUMCALLBACKW lpDSEnumCallback
,
672 TRACE("(%p,%p)\n", lpDSEnumCallback
, lpContext
);
674 if (lpDSEnumCallback
== NULL
) {
675 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
676 return DSERR_INVALIDPARAM
;
679 setup_dsound_options();
681 hr
= enumerate_mmdevices(eCapture
, DSOUND_capture_guids
,
682 lpDSEnumCallback
, lpContext
);
683 return SUCCEEDED(hr
) ? DS_OK
: hr
;
686 /*******************************************************************************
687 * DirectSound ClassFactory
690 typedef HRESULT (*FnCreateInstance
)(REFIID riid
, LPVOID
*ppobj
);
693 IClassFactory IClassFactory_iface
;
695 FnCreateInstance pfnCreateInstance
;
698 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
700 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
703 static HRESULT WINAPI
704 DSCF_QueryInterface(LPCLASSFACTORY iface
, REFIID riid
, LPVOID
*ppobj
)
706 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
707 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppobj
);
710 if (IsEqualIID(riid
, &IID_IUnknown
) ||
711 IsEqualIID(riid
, &IID_IClassFactory
))
714 IUnknown_AddRef(iface
);
718 return E_NOINTERFACE
;
721 static ULONG WINAPI
DSCF_AddRef(LPCLASSFACTORY iface
)
726 static ULONG WINAPI
DSCF_Release(LPCLASSFACTORY iface
)
728 /* static class, won't be freed */
732 static HRESULT WINAPI
DSCF_CreateInstance(
733 LPCLASSFACTORY iface
,
738 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
739 TRACE("(%p, %p, %s, %p)\n", This
, pOuter
, debugstr_guid(riid
), ppobj
);
742 return CLASS_E_NOAGGREGATION
;
745 WARN("invalid parameter\n");
746 return DSERR_INVALIDPARAM
;
749 return This
->pfnCreateInstance(riid
, ppobj
);
752 static HRESULT WINAPI
DSCF_LockServer(LPCLASSFACTORY iface
, BOOL dolock
)
754 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
755 FIXME("(%p, %d) stub!\n", This
, dolock
);
759 static const IClassFactoryVtbl DSCF_Vtbl
= {
767 static IClassFactoryImpl DSOUND_CF
[] = {
768 { { &DSCF_Vtbl
}, &CLSID_DirectSound
, (FnCreateInstance
)DSOUND_Create
},
769 { { &DSCF_Vtbl
}, &CLSID_DirectSound8
, (FnCreateInstance
)DSOUND_Create8
},
770 { { &DSCF_Vtbl
}, &CLSID_DirectSoundCapture
, (FnCreateInstance
)DSOUND_CaptureCreate
},
771 { { &DSCF_Vtbl
}, &CLSID_DirectSoundCapture8
, (FnCreateInstance
)DSOUND_CaptureCreate8
},
772 { { &DSCF_Vtbl
}, &CLSID_DirectSoundFullDuplex
, (FnCreateInstance
)DSOUND_FullDuplexCreate
},
773 { { &DSCF_Vtbl
}, &CLSID_DirectSoundPrivate
, (FnCreateInstance
)IKsPrivatePropertySetImpl_Create
},
774 { { NULL
}, NULL
, NULL
}
777 /*******************************************************************************
778 * DllGetClassObject [DSOUND.@]
779 * Retrieves class object from a DLL object
782 * Docs say returns STDAPI
785 * rclsid [I] CLSID for the class object
786 * riid [I] Reference to identifier of interface for class object
787 * ppv [O] Address of variable to receive interface pointer for riid
791 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
794 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
797 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
800 WARN("invalid parameter\n");
806 if (!IsEqualIID(riid
, &IID_IClassFactory
) &&
807 !IsEqualIID(riid
, &IID_IUnknown
)) {
808 WARN("no interface for %s\n", debugstr_guid(riid
));
809 return E_NOINTERFACE
;
812 while (NULL
!= DSOUND_CF
[i
].rclsid
) {
813 if (IsEqualGUID(rclsid
, DSOUND_CF
[i
].rclsid
)) {
814 DSCF_AddRef(&DSOUND_CF
[i
].IClassFactory_iface
);
815 *ppv
= &DSOUND_CF
[i
];
821 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid
),
822 debugstr_guid(riid
), ppv
);
823 return CLASS_E_CLASSNOTAVAILABLE
;
827 /*******************************************************************************
828 * DllCanUnloadNow [DSOUND.4]
829 * Determines whether the DLL is in use.
832 * Can unload now: S_OK
833 * Cannot unload now (the DLL is still active): S_FALSE
835 HRESULT WINAPI
DllCanUnloadNow(void)
840 #define INIT_GUID(guid, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
841 guid.Data1 = l; guid.Data2 = w1; guid.Data3 = w2; \
842 guid.Data4[0] = b1; guid.Data4[1] = b2; guid.Data4[2] = b3; \
843 guid.Data4[3] = b4; guid.Data4[4] = b5; guid.Data4[5] = b6; \
844 guid.Data4[6] = b7; guid.Data4[7] = b8;
846 /***********************************************************************
847 * DllMain (DSOUND.init)
849 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
851 TRACE("(%p %d %p)\n", hInstDLL
, fdwReason
, lpvReserved
);
854 case DLL_PROCESS_ATTACH
:
855 TRACE("DLL_PROCESS_ATTACH\n");
857 DisableThreadLibraryCalls(hInstDLL
);
858 /* Increase refcount on dsound by 1 */
859 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
, (LPCWSTR
)hInstDLL
, &hInstDLL
);
861 case DLL_PROCESS_DETACH
:
862 TRACE("DLL_PROCESS_DETACH\n");
863 DeleteCriticalSection(&DSOUND_renderers_lock
);
864 DeleteCriticalSection(&DSOUND_capturers_lock
);
865 DeleteCriticalSection(&g_devenum_lock
);
868 TRACE("UNKNOWN REASON\n");
874 /***********************************************************************
875 * DllRegisterServer (DSOUND.@)
877 HRESULT WINAPI
DllRegisterServer(void)
879 return __wine_register_resources( instance
);
882 /***********************************************************************
883 * DllUnregisterServer (DSOUND.@)
885 HRESULT WINAPI
DllUnregisterServer(void)
887 return __wine_unregister_resources( instance
);