gitlab: Run tests on Debian after the daily commit round.
[wine.git] / dlls / dsound / dsound_main.c
blob215588393d8909477b2ca7a1cc3fe3cbe8abd4a9
1 /* DirectSound
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.
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
35 #include <stdarg.h>
37 #define COBJMACROS
38 #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 "mmddk.h"
47 #include "wine/debug.h"
48 #include "dsound.h"
49 #include "dsconf.h"
50 #include "ks.h"
51 #include "rpcproxy.h"
52 #include "rpc.h"
53 #include "rpcndr.h"
54 #include "unknwn.h"
55 #include "oleidl.h"
56 #include "shobjidl.h"
57 #include "strmif.h"
59 #include "initguid.h"
60 #include "ksmedia.h"
61 #include "propkey.h"
62 #include "devpkey.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 const WCHAR wine_vxd_drv[] = L"winemm.vxd";
93 /* All default settings, you most likely don't want to touch these, see wiki on UsefulRegistryKeys */
94 int ds_hel_buflen = 32768 * 2;
97 * Get a config key from either the app-specific or the default config
100 static inline DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
101 char *buffer, DWORD size )
103 if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
104 if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
105 return ERROR_FILE_NOT_FOUND;
110 * Setup the dsound options.
113 void setup_dsound_options(void)
115 char buffer[MAX_PATH+16];
116 HKEY hkey, appkey = 0;
117 DWORD len;
119 buffer[MAX_PATH]='\0';
121 /* @@ Wine registry key: HKCU\Software\Wine\DirectSound */
122 if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\DirectSound", &hkey )) hkey = 0;
124 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
125 if (len && len < MAX_PATH)
127 HKEY tmpkey;
128 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectSound */
129 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
131 char *p, *appname = buffer;
132 if ((p = strrchr( appname, '/' ))) appname = p + 1;
133 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
134 strcat( appname, "\\DirectSound" );
135 TRACE("appname = [%s]\n", appname);
136 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
137 RegCloseKey( tmpkey );
141 /* get options */
143 if (!get_config_key( hkey, appkey, "HelBuflen", buffer, MAX_PATH ))
144 ds_hel_buflen = atoi(buffer);
146 if (appkey) RegCloseKey( appkey );
147 if (hkey) RegCloseKey( hkey );
149 TRACE("ds_hel_buflen = %d\n", ds_hel_buflen);
152 static const char * get_device_id(LPCGUID pGuid)
154 if (IsEqualGUID(&DSDEVID_DefaultPlayback, pGuid))
155 return "DSDEVID_DefaultPlayback";
156 else if (IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuid))
157 return "DSDEVID_DefaultVoicePlayback";
158 else if (IsEqualGUID(&DSDEVID_DefaultCapture, pGuid))
159 return "DSDEVID_DefaultCapture";
160 else if (IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuid))
161 return "DSDEVID_DefaultVoiceCapture";
162 return debugstr_guid(pGuid);
165 static HRESULT get_mmdevenum(IMMDeviceEnumerator **devenum)
167 HRESULT hr, init_hr;
169 init_hr = CoInitialize(NULL);
171 hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL,
172 CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)devenum);
173 if(FAILED(hr)){
174 if(SUCCEEDED(init_hr))
175 CoUninitialize();
176 *devenum = NULL;
177 ERR("CoCreateInstance failed: %08lx\n", hr);
178 return hr;
181 return init_hr;
184 static void release_mmdevenum(IMMDeviceEnumerator *devenum, HRESULT init_hr)
186 IMMDeviceEnumerator_Release(devenum);
187 if(SUCCEEDED(init_hr))
188 CoUninitialize();
191 static HRESULT get_mmdevice_guid(IMMDevice *device, IPropertyStore *ps,
192 GUID *guid)
194 PROPVARIANT pv;
195 HRESULT hr;
197 if(!ps){
198 hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
199 if(FAILED(hr)){
200 WARN("OpenPropertyStore failed: %08lx\n", hr);
201 return hr;
203 }else
204 IPropertyStore_AddRef(ps);
206 PropVariantInit(&pv);
208 hr = IPropertyStore_GetValue(ps, &PKEY_AudioEndpoint_GUID, &pv);
209 if(FAILED(hr)){
210 IPropertyStore_Release(ps);
211 WARN("GetValue(GUID) failed: %08lx\n", hr);
212 return hr;
215 CLSIDFromString(pv.pwszVal, guid);
217 PropVariantClear(&pv);
218 IPropertyStore_Release(ps);
220 return S_OK;
223 /***************************************************************************
224 * GetDeviceID [DSOUND.9]
226 * Retrieves unique identifier of default device specified
228 * PARAMS
229 * pGuidSrc [I] Address of device GUID.
230 * pGuidDest [O] Address to receive unique device GUID.
232 * RETURNS
233 * Success: DS_OK
234 * Failure: DSERR_INVALIDPARAM
236 * NOTES
237 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
238 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
239 * DSDEVID_DefaultVoiceCapture.
240 * Returns pGuidSrc if pGuidSrc is a valid device or the device
241 * GUID for the specified constants.
243 HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest)
245 IMMDeviceEnumerator *devenum;
246 EDataFlow flow = (EDataFlow)-1;
247 ERole role = (ERole)-1;
248 HRESULT hr, init_hr;
250 TRACE("(%s,%p)\n", get_device_id(pGuidSrc),pGuidDest);
252 if(!pGuidSrc || !pGuidDest)
253 return DSERR_INVALIDPARAM;
255 init_hr = get_mmdevenum(&devenum);
256 if(!devenum)
257 return init_hr;
259 if(IsEqualGUID(&DSDEVID_DefaultPlayback, pGuidSrc)){
260 role = eMultimedia;
261 flow = eRender;
262 }else if(IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuidSrc)){
263 role = eCommunications;
264 flow = eRender;
265 }else if(IsEqualGUID(&DSDEVID_DefaultCapture, pGuidSrc)){
266 role = eMultimedia;
267 flow = eCapture;
268 }else if(IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuidSrc)){
269 role = eCommunications;
270 flow = eCapture;
273 if(role != (ERole)-1 && flow != (EDataFlow)-1){
274 IMMDevice *device;
276 hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum,
277 flow, role, &device);
278 if(FAILED(hr)){
279 WARN("GetDefaultAudioEndpoint failed: %08lx\n", hr);
280 release_mmdevenum(devenum, init_hr);
281 return DSERR_NODRIVER;
284 hr = get_mmdevice_guid(device, NULL, pGuidDest);
285 IMMDevice_Release(device);
287 release_mmdevenum(devenum, init_hr);
289 return (hr == S_OK) ? DS_OK : hr;
292 release_mmdevenum(devenum, init_hr);
294 *pGuidDest = *pGuidSrc;
296 return DS_OK;
299 struct morecontext
301 LPDSENUMCALLBACKA callA;
302 LPVOID data;
305 static BOOL CALLBACK a_to_w_callback(LPGUID guid, LPCWSTR descW, LPCWSTR modW, LPVOID data)
307 struct morecontext *context = data;
308 char descA[MAXPNAMELEN], modA[MAXPNAMELEN];
310 WideCharToMultiByte(CP_ACP, 0, descW, -1, descA, sizeof(descA), NULL, NULL);
311 WideCharToMultiByte(CP_ACP, 0, modW, -1, modA, sizeof(modA), NULL, NULL);
313 return context->callA(guid, descA, modA, context->data);
316 /***************************************************************************
317 * DirectSoundEnumerateA [DSOUND.2]
319 * Enumerate all DirectSound drivers installed in the system
321 * PARAMS
322 * lpDSEnumCallback [I] Address of callback function.
323 * lpContext [I] Address of user defined context passed to callback function.
325 * RETURNS
326 * Success: DS_OK
327 * Failure: DSERR_INVALIDPARAM
329 HRESULT WINAPI DirectSoundEnumerateA(
330 LPDSENUMCALLBACKA lpDSEnumCallback,
331 LPVOID lpContext)
333 struct morecontext context;
335 if (lpDSEnumCallback == NULL) {
336 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
337 return DSERR_INVALIDPARAM;
340 context.callA = lpDSEnumCallback;
341 context.data = lpContext;
343 return DirectSoundEnumerateW(a_to_w_callback, &context);
346 HRESULT get_mmdevice(EDataFlow flow, const GUID *tgt, IMMDevice **device)
348 IMMDeviceEnumerator *devenum;
349 IMMDeviceCollection *coll;
350 UINT count, i;
351 HRESULT hr, init_hr;
353 init_hr = get_mmdevenum(&devenum);
354 if(!devenum)
355 return init_hr;
357 hr = IMMDeviceEnumerator_EnumAudioEndpoints(devenum, flow,
358 DEVICE_STATE_ACTIVE, &coll);
359 if(FAILED(hr)){
360 WARN("EnumAudioEndpoints failed: %08lx\n", hr);
361 release_mmdevenum(devenum, init_hr);
362 return hr;
365 hr = IMMDeviceCollection_GetCount(coll, &count);
366 if(FAILED(hr)){
367 IMMDeviceCollection_Release(coll);
368 release_mmdevenum(devenum, init_hr);
369 WARN("GetCount failed: %08lx\n", hr);
370 return hr;
373 for(i = 0; i < count; ++i){
374 GUID guid;
376 hr = IMMDeviceCollection_Item(coll, i, device);
377 if(FAILED(hr))
378 continue;
380 hr = get_mmdevice_guid(*device, NULL, &guid);
381 if(FAILED(hr)){
382 IMMDevice_Release(*device);
383 continue;
386 if(IsEqualGUID(&guid, tgt)){
387 IMMDeviceCollection_Release(coll);
388 release_mmdevenum(devenum, init_hr);
389 return DS_OK;
392 IMMDevice_Release(*device);
395 WARN("No device with GUID %s found!\n", wine_dbgstr_guid(tgt));
397 IMMDeviceCollection_Release(coll);
398 release_mmdevenum(devenum, init_hr);
400 return DSERR_INVALIDPARAM;
403 static BOOL send_device(IMMDevice *device, GUID *guid,
404 LPDSENUMCALLBACKW cb, void *user)
406 IPropertyStore *ps;
407 PROPVARIANT pv;
408 BOOL keep_going;
409 HRESULT hr;
411 PropVariantInit(&pv);
413 hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
414 if(FAILED(hr)){
415 WARN("OpenPropertyStore failed: %08lx\n", hr);
416 return TRUE;
419 hr = get_mmdevice_guid(device, ps, guid);
420 if(FAILED(hr)){
421 IPropertyStore_Release(ps);
422 return TRUE;
425 hr = IPropertyStore_GetValue(ps,
426 (const PROPERTYKEY *)&DEVPKEY_Device_FriendlyName, &pv);
427 if(FAILED(hr)){
428 IPropertyStore_Release(ps);
429 WARN("GetValue(FriendlyName) failed: %08lx\n", hr);
430 return TRUE;
433 TRACE("Calling back with %s (%s)\n", wine_dbgstr_guid(guid),
434 wine_dbgstr_w(pv.pwszVal));
436 keep_going = cb(guid, pv.pwszVal, wine_vxd_drv, user);
438 PropVariantClear(&pv);
439 IPropertyStore_Release(ps);
441 return keep_going;
444 /* S_FALSE means the callback returned FALSE at some point
445 * S_OK means the callback always returned TRUE */
446 HRESULT enumerate_mmdevices(EDataFlow flow, GUID *guids,
447 LPDSENUMCALLBACKW cb, void *user)
449 IMMDeviceEnumerator *devenum;
450 IMMDeviceCollection *coll;
451 IMMDevice *defdev = NULL;
452 UINT count, i, n;
453 BOOL keep_going;
454 HRESULT hr, init_hr;
456 init_hr = get_mmdevenum(&devenum);
457 if(!devenum)
458 return init_hr;
460 hr = IMMDeviceEnumerator_EnumAudioEndpoints(devenum, flow,
461 DEVICE_STATE_ACTIVE, &coll);
462 if(FAILED(hr)){
463 release_mmdevenum(devenum, init_hr);
464 WARN("EnumAudioEndpoints failed: %08lx\n", hr);
465 return DS_OK;
468 hr = IMMDeviceCollection_GetCount(coll, &count);
469 if(FAILED(hr)){
470 IMMDeviceCollection_Release(coll);
471 release_mmdevenum(devenum, init_hr);
472 WARN("GetCount failed: %08lx\n", hr);
473 return DS_OK;
476 if(count == 0){
477 IMMDeviceCollection_Release(coll);
478 release_mmdevenum(devenum, init_hr);
479 return DS_OK;
482 TRACE("Calling back with NULL (Primary Sound Driver)\n");
483 keep_going = cb(NULL, L"Primary Sound Driver", L"", user);
485 /* always send the default device first */
486 if(keep_going){
487 hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum, flow,
488 eMultimedia, &defdev);
489 if(FAILED(hr)){
490 defdev = NULL;
491 n = 0;
492 }else{
493 keep_going = send_device(defdev, &guids[0], cb, user);
494 n = 1;
498 for(i = 0; keep_going && i < count; ++i){
499 IMMDevice *device;
501 hr = IMMDeviceCollection_Item(coll, i, &device);
502 if(FAILED(hr)){
503 WARN("Item failed: %08lx\n", hr);
504 continue;
507 if(device != defdev){
508 keep_going = send_device(device, &guids[n], cb, user);
509 ++n;
512 IMMDevice_Release(device);
515 if(defdev)
516 IMMDevice_Release(defdev);
517 IMMDeviceCollection_Release(coll);
519 release_mmdevenum(devenum, init_hr);
521 return keep_going ? S_OK : S_FALSE;
524 /***************************************************************************
525 * DirectSoundEnumerateW [DSOUND.3]
527 * Enumerate all DirectSound drivers installed in the system
529 * PARAMS
530 * lpDSEnumCallback [I] Address of callback function.
531 * lpContext [I] Address of user defined context passed to callback function.
533 * RETURNS
534 * Success: DS_OK
535 * Failure: DSERR_INVALIDPARAM
537 HRESULT WINAPI DirectSoundEnumerateW(
538 LPDSENUMCALLBACKW lpDSEnumCallback,
539 LPVOID lpContext )
541 HRESULT hr;
543 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext);
545 if (lpDSEnumCallback == NULL) {
546 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
547 return DSERR_INVALIDPARAM;
550 setup_dsound_options();
552 hr = enumerate_mmdevices(eRender, DSOUND_renderer_guids,
553 lpDSEnumCallback, lpContext);
554 return SUCCEEDED(hr) ? DS_OK : hr;
557 /***************************************************************************
558 * DirectSoundCaptureEnumerateA [DSOUND.7]
560 * Enumerate all DirectSound drivers installed in the system.
562 * PARAMS
563 * lpDSEnumCallback [I] Address of callback function.
564 * lpContext [I] Address of user defined context passed to callback function.
566 * RETURNS
567 * Success: DS_OK
568 * Failure: DSERR_INVALIDPARAM
570 HRESULT WINAPI DirectSoundCaptureEnumerateA(
571 LPDSENUMCALLBACKA lpDSEnumCallback,
572 LPVOID lpContext)
574 struct morecontext context;
576 if (lpDSEnumCallback == NULL) {
577 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
578 return DSERR_INVALIDPARAM;
581 context.callA = lpDSEnumCallback;
582 context.data = lpContext;
584 return DirectSoundCaptureEnumerateW(a_to_w_callback, &context);
587 /***************************************************************************
588 * DirectSoundCaptureEnumerateW [DSOUND.8]
590 * Enumerate all DirectSound drivers installed in the system.
592 * PARAMS
593 * lpDSEnumCallback [I] Address of callback function.
594 * lpContext [I] Address of user defined context passed to callback function.
596 * RETURNS
597 * Success: DS_OK
598 * Failure: DSERR_INVALIDPARAM
600 HRESULT WINAPI
601 DirectSoundCaptureEnumerateW(
602 LPDSENUMCALLBACKW lpDSEnumCallback,
603 LPVOID lpContext)
605 HRESULT hr;
607 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext );
609 if (lpDSEnumCallback == NULL) {
610 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
611 return DSERR_INVALIDPARAM;
614 setup_dsound_options();
616 hr = enumerate_mmdevices(eCapture, DSOUND_capture_guids,
617 lpDSEnumCallback, lpContext);
618 return SUCCEEDED(hr) ? DS_OK : hr;
621 /*******************************************************************************
622 * DirectSound ClassFactory
625 typedef HRESULT (*FnCreateInstance)(REFIID riid, LPVOID *ppobj);
627 typedef struct {
628 IClassFactory IClassFactory_iface;
629 REFCLSID rclsid;
630 FnCreateInstance pfnCreateInstance;
631 } IClassFactoryImpl;
633 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
635 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
638 static HRESULT WINAPI
639 DSCF_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppobj)
641 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
642 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
643 if (ppobj == NULL)
644 return E_POINTER;
645 if (IsEqualIID(riid, &IID_IUnknown) ||
646 IsEqualIID(riid, &IID_IClassFactory))
648 *ppobj = iface;
649 IClassFactory_AddRef(iface);
650 return S_OK;
652 *ppobj = NULL;
653 return E_NOINTERFACE;
656 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
658 return 2;
661 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
663 /* static class, won't be freed */
664 return 1;
667 static HRESULT WINAPI DSCF_CreateInstance(
668 LPCLASSFACTORY iface,
669 LPUNKNOWN pOuter,
670 REFIID riid,
671 LPVOID *ppobj)
673 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
674 TRACE("(%p, %p, %s, %p)\n", This, pOuter, debugstr_guid(riid), ppobj);
676 if (pOuter)
677 return CLASS_E_NOAGGREGATION;
679 if (ppobj == NULL) {
680 WARN("invalid parameter\n");
681 return DSERR_INVALIDPARAM;
683 *ppobj = NULL;
684 return This->pfnCreateInstance(riid, ppobj);
687 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
689 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
690 FIXME("(%p, %d) stub!\n", This, dolock);
691 return S_OK;
694 static const IClassFactoryVtbl DSCF_Vtbl = {
695 DSCF_QueryInterface,
696 DSCF_AddRef,
697 DSCF_Release,
698 DSCF_CreateInstance,
699 DSCF_LockServer
702 static IClassFactoryImpl DSOUND_CF[] = {
703 { { &DSCF_Vtbl }, &CLSID_DirectSound, DSOUND_Create },
704 { { &DSCF_Vtbl }, &CLSID_DirectSound8, DSOUND_Create8 },
705 { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture, DSOUND_CaptureCreate },
706 { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture8, DSOUND_CaptureCreate8 },
707 { { &DSCF_Vtbl }, &CLSID_DirectSoundFullDuplex, DSOUND_FullDuplexCreate },
708 { { &DSCF_Vtbl }, &CLSID_DirectSoundPrivate, IKsPrivatePropertySetImpl_Create },
709 { { NULL }, NULL, NULL }
712 /*******************************************************************************
713 * DllGetClassObject [DSOUND.@]
714 * Retrieves class object from a DLL object
716 * NOTES
717 * Docs say returns STDAPI
719 * PARAMS
720 * rclsid [I] CLSID for the class object
721 * riid [I] Reference to identifier of interface for class object
722 * ppv [O] Address of variable to receive interface pointer for riid
724 * RETURNS
725 * Success: S_OK
726 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
727 * E_UNEXPECTED
729 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
731 int i = 0;
732 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
734 if (ppv == NULL) {
735 WARN("invalid parameter\n");
736 return E_INVALIDARG;
739 *ppv = NULL;
741 if (!IsEqualIID(riid, &IID_IClassFactory) &&
742 !IsEqualIID(riid, &IID_IUnknown)) {
743 WARN("no interface for %s\n", debugstr_guid(riid));
744 return E_NOINTERFACE;
747 while (NULL != DSOUND_CF[i].rclsid) {
748 if (IsEqualGUID(rclsid, DSOUND_CF[i].rclsid)) {
749 DSCF_AddRef(&DSOUND_CF[i].IClassFactory_iface);
750 *ppv = &DSOUND_CF[i];
751 return S_OK;
753 i++;
756 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid),
757 debugstr_guid(riid), ppv);
758 return CLASS_E_CLASSNOTAVAILABLE;
762 #define INIT_GUID(guid, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
763 guid.Data1 = l; guid.Data2 = w1; guid.Data3 = w2; \
764 guid.Data4[0] = b1; guid.Data4[1] = b2; guid.Data4[2] = b3; \
765 guid.Data4[3] = b4; guid.Data4[4] = b5; guid.Data4[5] = b6; \
766 guid.Data4[6] = b7; guid.Data4[7] = b8;
768 /***********************************************************************
769 * DllMain (DSOUND.init)
771 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
773 TRACE("(%p %ld %p)\n", hInstDLL, fdwReason, lpvReserved);
775 switch (fdwReason) {
776 case DLL_PROCESS_ATTACH:
777 DisableThreadLibraryCalls(hInstDLL);
778 /* Increase refcount on dsound by 1 */
779 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)hInstDLL, &hInstDLL);
780 break;
781 case DLL_PROCESS_DETACH:
782 if (lpvReserved) break;
783 DeleteCriticalSection(&DSOUND_renderers_lock);
784 DeleteCriticalSection(&DSOUND_capturers_lock);
785 break;
787 return TRUE;