ntoskrnl.exe: Export InitSafeBootMode.
[wine/wine-gecko.git] / dlls / dsound / dsound_main.c
blob0e3a31320848906a77030d8b3b8588eef5cdbe6f
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 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 "rpcproxy.h"
53 #include "rpc.h"
54 #include "rpcndr.h"
55 #include "unknwn.h"
56 #include "oleidl.h"
57 #include "shobjidl.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 WCHAR wine_vxd_drv[] = { 'w','i','n','e','m','m','.','v','x','d', 0 };
93 /* All default settings, you most likely don't want to touch these, see wiki on UsefulRegistryKeys */
94 int ds_hel_buflen = 32768 * 2;
95 int ds_snd_queue_max = 10;
96 static HINSTANCE instance;
99 * Get a config key from either the app-specific or the default config
102 static inline DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
103 char *buffer, DWORD size )
105 if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
106 if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
107 return ERROR_FILE_NOT_FOUND;
112 * Setup the dsound options.
115 void setup_dsound_options(void)
117 char buffer[MAX_PATH+16];
118 HKEY hkey, appkey = 0;
119 DWORD len;
121 buffer[MAX_PATH]='\0';
123 /* @@ Wine registry key: HKCU\Software\Wine\DirectSound */
124 if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\DirectSound", &hkey )) hkey = 0;
126 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
127 if (len && len < MAX_PATH)
129 HKEY tmpkey;
130 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectSound */
131 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
133 char *p, *appname = buffer;
134 if ((p = strrchr( appname, '/' ))) appname = p + 1;
135 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
136 strcat( appname, "\\DirectSound" );
137 TRACE("appname = [%s]\n", appname);
138 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
139 RegCloseKey( tmpkey );
143 /* get options */
145 if (!get_config_key( hkey, appkey, "HelBuflen", buffer, MAX_PATH ))
146 ds_hel_buflen = atoi(buffer);
148 if (!get_config_key( hkey, appkey, "SndQueueMax", buffer, MAX_PATH ))
149 ds_snd_queue_max = atoi(buffer);
152 if (appkey) RegCloseKey( appkey );
153 if (hkey) RegCloseKey( hkey );
155 TRACE("ds_hel_buflen = %d\n", ds_hel_buflen);
156 TRACE("ds_snd_queue_max = %d\n", ds_snd_queue_max);
159 static const char * get_device_id(LPCGUID pGuid)
161 if (IsEqualGUID(&DSDEVID_DefaultPlayback, pGuid))
162 return "DSDEVID_DefaultPlayback";
163 else if (IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuid))
164 return "DSDEVID_DefaultVoicePlayback";
165 else if (IsEqualGUID(&DSDEVID_DefaultCapture, pGuid))
166 return "DSDEVID_DefaultCapture";
167 else if (IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuid))
168 return "DSDEVID_DefaultVoiceCapture";
169 return debugstr_guid(pGuid);
172 static HRESULT get_mmdevenum(IMMDeviceEnumerator **devenum)
174 HRESULT hr, init_hr;
176 init_hr = CoInitialize(NULL);
178 hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL,
179 CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)devenum);
180 if(FAILED(hr)){
181 if(SUCCEEDED(init_hr))
182 CoUninitialize();
183 *devenum = NULL;
184 ERR("CoCreateInstance failed: %08x\n", hr);
185 return hr;
188 return init_hr;
191 static void release_mmdevenum(IMMDeviceEnumerator *devenum, HRESULT init_hr)
193 IMMDeviceEnumerator_Release(devenum);
194 if(SUCCEEDED(init_hr))
195 CoUninitialize();
198 static HRESULT get_mmdevice_guid(IMMDevice *device, IPropertyStore *ps,
199 GUID *guid)
201 PROPVARIANT pv;
202 HRESULT hr;
204 if(!ps){
205 hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
206 if(FAILED(hr)){
207 WARN("OpenPropertyStore failed: %08x\n", hr);
208 return hr;
210 }else
211 IPropertyStore_AddRef(ps);
213 PropVariantInit(&pv);
215 hr = IPropertyStore_GetValue(ps, &PKEY_AudioEndpoint_GUID, &pv);
216 if(FAILED(hr)){
217 IPropertyStore_Release(ps);
218 WARN("GetValue(GUID) failed: %08x\n", hr);
219 return hr;
222 CLSIDFromString(pv.u.pwszVal, guid);
224 PropVariantClear(&pv);
225 IPropertyStore_Release(ps);
227 return S_OK;
230 /***************************************************************************
231 * GetDeviceID [DSOUND.9]
233 * Retrieves unique identifier of default device specified
235 * PARAMS
236 * pGuidSrc [I] Address of device GUID.
237 * pGuidDest [O] Address to receive unique device GUID.
239 * RETURNS
240 * Success: DS_OK
241 * Failure: DSERR_INVALIDPARAM
243 * NOTES
244 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
245 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
246 * DSDEVID_DefaultVoiceCapture.
247 * Returns pGuidSrc if pGuidSrc is a valid device or the device
248 * GUID for the specified constants.
250 HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest)
252 IMMDeviceEnumerator *devenum;
253 EDataFlow flow = (EDataFlow)-1;
254 ERole role = (ERole)-1;
255 HRESULT hr, init_hr;
257 TRACE("(%s,%p)\n", get_device_id(pGuidSrc),pGuidDest);
259 if(!pGuidSrc || !pGuidDest)
260 return DSERR_INVALIDPARAM;
262 init_hr = get_mmdevenum(&devenum);
263 if(!devenum)
264 return init_hr;
266 if(IsEqualGUID(&DSDEVID_DefaultPlayback, pGuidSrc)){
267 role = eMultimedia;
268 flow = eRender;
269 }else if(IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuidSrc)){
270 role = eCommunications;
271 flow = eRender;
272 }else if(IsEqualGUID(&DSDEVID_DefaultCapture, pGuidSrc)){
273 role = eMultimedia;
274 flow = eCapture;
275 }else if(IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuidSrc)){
276 role = eCommunications;
277 flow = eCapture;
280 if(role != (ERole)-1 && flow != (EDataFlow)-1){
281 IMMDevice *device;
283 hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum,
284 flow, role, &device);
285 if(FAILED(hr)){
286 WARN("GetDefaultAudioEndpoint failed: %08x\n", hr);
287 release_mmdevenum(devenum, init_hr);
288 return DSERR_NODRIVER;
291 hr = get_mmdevice_guid(device, NULL, pGuidDest);
292 IMMDevice_Release(device);
294 release_mmdevenum(devenum, init_hr);
296 return (hr == S_OK) ? DS_OK : hr;
299 release_mmdevenum(devenum, init_hr);
301 *pGuidDest = *pGuidSrc;
303 return DS_OK;
306 struct morecontext
308 LPDSENUMCALLBACKA callA;
309 LPVOID data;
312 static BOOL CALLBACK a_to_w_callback(LPGUID guid, LPCWSTR descW, LPCWSTR modW, LPVOID data)
314 struct morecontext *context = data;
315 char descA[MAXPNAMELEN], modA[MAXPNAMELEN];
317 WideCharToMultiByte(CP_ACP, 0, descW, -1, descA, sizeof(descA), NULL, NULL);
318 WideCharToMultiByte(CP_ACP, 0, modW, -1, modA, sizeof(modA), NULL, NULL);
320 return context->callA(guid, descA, modA, context->data);
323 /***************************************************************************
324 * DirectSoundEnumerateA [DSOUND.2]
326 * Enumerate all DirectSound drivers installed in the system
328 * PARAMS
329 * lpDSEnumCallback [I] Address of callback function.
330 * lpContext [I] Address of user defined context passed to callback function.
332 * RETURNS
333 * Success: DS_OK
334 * Failure: DSERR_INVALIDPARAM
336 HRESULT WINAPI DirectSoundEnumerateA(
337 LPDSENUMCALLBACKA lpDSEnumCallback,
338 LPVOID lpContext)
340 struct morecontext context;
342 if (lpDSEnumCallback == NULL) {
343 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
344 return DSERR_INVALIDPARAM;
347 context.callA = lpDSEnumCallback;
348 context.data = lpContext;
350 return DirectSoundEnumerateW(a_to_w_callback, &context);
353 HRESULT get_mmdevice(EDataFlow flow, const GUID *tgt, IMMDevice **device)
355 IMMDeviceEnumerator *devenum;
356 IMMDeviceCollection *coll;
357 UINT count, i;
358 HRESULT hr, init_hr;
360 init_hr = get_mmdevenum(&devenum);
361 if(!devenum)
362 return init_hr;
364 hr = IMMDeviceEnumerator_EnumAudioEndpoints(devenum, flow,
365 DEVICE_STATE_ACTIVE, &coll);
366 if(FAILED(hr)){
367 WARN("EnumAudioEndpoints failed: %08x\n", hr);
368 release_mmdevenum(devenum, init_hr);
369 return hr;
372 hr = IMMDeviceCollection_GetCount(coll, &count);
373 if(FAILED(hr)){
374 IMMDeviceCollection_Release(coll);
375 release_mmdevenum(devenum, init_hr);
376 WARN("GetCount failed: %08x\n", hr);
377 return hr;
380 for(i = 0; i < count; ++i){
381 GUID guid;
383 hr = IMMDeviceCollection_Item(coll, i, device);
384 if(FAILED(hr))
385 continue;
387 hr = get_mmdevice_guid(*device, NULL, &guid);
388 if(FAILED(hr)){
389 IMMDevice_Release(*device);
390 continue;
393 if(IsEqualGUID(&guid, tgt)){
394 IMMDeviceCollection_Release(coll);
395 release_mmdevenum(devenum, init_hr);
396 return DS_OK;
399 IMMDevice_Release(*device);
402 WARN("No device with GUID %s found!\n", wine_dbgstr_guid(tgt));
404 IMMDeviceCollection_Release(coll);
405 release_mmdevenum(devenum, init_hr);
407 return DSERR_INVALIDPARAM;
410 static BOOL send_device(IMMDevice *device, GUID *guid,
411 LPDSENUMCALLBACKW cb, void *user)
413 IPropertyStore *ps;
414 PROPVARIANT pv;
415 BOOL keep_going;
416 HRESULT hr;
418 PropVariantInit(&pv);
420 hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
421 if(FAILED(hr)){
422 WARN("OpenPropertyStore failed: %08x\n", hr);
423 return TRUE;
426 hr = get_mmdevice_guid(device, ps, guid);
427 if(FAILED(hr)){
428 IPropertyStore_Release(ps);
429 return TRUE;
432 hr = IPropertyStore_GetValue(ps,
433 (const PROPERTYKEY *)&DEVPKEY_Device_FriendlyName, &pv);
434 if(FAILED(hr)){
435 IPropertyStore_Release(ps);
436 WARN("GetValue(FriendlyName) failed: %08x\n", hr);
437 return TRUE;
440 TRACE("Calling back with %s (%s)\n", wine_dbgstr_guid(guid),
441 wine_dbgstr_w(pv.u.pwszVal));
443 keep_going = cb(guid, pv.u.pwszVal, wine_vxd_drv, user);
445 PropVariantClear(&pv);
446 IPropertyStore_Release(ps);
448 return keep_going;
451 /* S_FALSE means the callback returned FALSE at some point
452 * S_OK means the callback always returned TRUE */
453 HRESULT enumerate_mmdevices(EDataFlow flow, GUID *guids,
454 LPDSENUMCALLBACKW cb, void *user)
456 IMMDeviceEnumerator *devenum;
457 IMMDeviceCollection *coll;
458 IMMDevice *defdev = NULL;
459 UINT count, i, n;
460 BOOL keep_going;
461 HRESULT hr, init_hr;
463 static const WCHAR primary_desc[] = {'P','r','i','m','a','r','y',' ',
464 'S','o','u','n','d',' ','D','r','i','v','e','r',0};
465 static const WCHAR empty_drv[] = {0};
467 init_hr = get_mmdevenum(&devenum);
468 if(!devenum)
469 return init_hr;
471 hr = IMMDeviceEnumerator_EnumAudioEndpoints(devenum, flow,
472 DEVICE_STATE_ACTIVE, &coll);
473 if(FAILED(hr)){
474 release_mmdevenum(devenum, init_hr);
475 WARN("EnumAudioEndpoints failed: %08x\n", hr);
476 return DS_OK;
479 hr = IMMDeviceCollection_GetCount(coll, &count);
480 if(FAILED(hr)){
481 IMMDeviceCollection_Release(coll);
482 release_mmdevenum(devenum, init_hr);
483 WARN("GetCount failed: %08x\n", hr);
484 return DS_OK;
487 if(count == 0){
488 release_mmdevenum(devenum, init_hr);
489 return DS_OK;
492 TRACE("Calling back with NULL (%s)\n", wine_dbgstr_w(primary_desc));
493 keep_going = cb(NULL, primary_desc, empty_drv, user);
495 /* always send the default device first */
496 if(keep_going){
497 hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum, flow,
498 eMultimedia, &defdev);
499 if(FAILED(hr)){
500 defdev = NULL;
501 n = 0;
502 }else{
503 keep_going = send_device(defdev, &guids[0], cb, user);
504 n = 1;
508 for(i = 0; keep_going && i < count; ++i){
509 IMMDevice *device;
511 hr = IMMDeviceCollection_Item(coll, i, &device);
512 if(FAILED(hr)){
513 WARN("Item failed: %08x\n", hr);
514 continue;
517 if(device != defdev){
518 send_device(device, &guids[n], cb, user);
519 ++n;
522 IMMDevice_Release(device);
525 if(defdev)
526 IMMDevice_Release(defdev);
527 IMMDeviceCollection_Release(coll);
529 release_mmdevenum(devenum, init_hr);
531 return (keep_going == TRUE) ? S_OK : S_FALSE;
534 /***************************************************************************
535 * DirectSoundEnumerateW [DSOUND.3]
537 * Enumerate all DirectSound drivers installed in the system
539 * PARAMS
540 * lpDSEnumCallback [I] Address of callback function.
541 * lpContext [I] Address of user defined context passed to callback function.
543 * RETURNS
544 * Success: DS_OK
545 * Failure: DSERR_INVALIDPARAM
547 HRESULT WINAPI DirectSoundEnumerateW(
548 LPDSENUMCALLBACKW lpDSEnumCallback,
549 LPVOID lpContext )
551 HRESULT hr;
553 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext);
555 if (lpDSEnumCallback == NULL) {
556 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
557 return DSERR_INVALIDPARAM;
560 setup_dsound_options();
562 hr = enumerate_mmdevices(eRender, DSOUND_renderer_guids,
563 lpDSEnumCallback, lpContext);
564 return SUCCEEDED(hr) ? DS_OK : hr;
567 /***************************************************************************
568 * DirectSoundCaptureEnumerateA [DSOUND.7]
570 * Enumerate all DirectSound drivers installed in the system.
572 * PARAMS
573 * lpDSEnumCallback [I] Address of callback function.
574 * lpContext [I] Address of user defined context passed to callback function.
576 * RETURNS
577 * Success: DS_OK
578 * Failure: DSERR_INVALIDPARAM
580 HRESULT WINAPI DirectSoundCaptureEnumerateA(
581 LPDSENUMCALLBACKA lpDSEnumCallback,
582 LPVOID lpContext)
584 struct morecontext context;
586 if (lpDSEnumCallback == NULL) {
587 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
588 return DSERR_INVALIDPARAM;
591 context.callA = lpDSEnumCallback;
592 context.data = lpContext;
594 return DirectSoundCaptureEnumerateW(a_to_w_callback, &context);
597 /***************************************************************************
598 * DirectSoundCaptureEnumerateW [DSOUND.8]
600 * Enumerate all DirectSound drivers installed in the system.
602 * PARAMS
603 * lpDSEnumCallback [I] Address of callback function.
604 * lpContext [I] Address of user defined context passed to callback function.
606 * RETURNS
607 * Success: DS_OK
608 * Failure: DSERR_INVALIDPARAM
610 HRESULT WINAPI
611 DirectSoundCaptureEnumerateW(
612 LPDSENUMCALLBACKW lpDSEnumCallback,
613 LPVOID lpContext)
615 HRESULT hr;
617 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext );
619 if (lpDSEnumCallback == NULL) {
620 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
621 return DSERR_INVALIDPARAM;
624 setup_dsound_options();
626 hr = enumerate_mmdevices(eCapture, DSOUND_capture_guids,
627 lpDSEnumCallback, lpContext);
628 return SUCCEEDED(hr) ? DS_OK : hr;
631 /*******************************************************************************
632 * DirectSound ClassFactory
635 typedef HRESULT (*FnCreateInstance)(REFIID riid, LPVOID *ppobj);
637 typedef struct {
638 IClassFactory IClassFactory_iface;
639 REFCLSID rclsid;
640 FnCreateInstance pfnCreateInstance;
641 } IClassFactoryImpl;
643 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
645 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
648 static HRESULT WINAPI
649 DSCF_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppobj)
651 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
652 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
653 if (ppobj == NULL)
654 return E_POINTER;
655 if (IsEqualIID(riid, &IID_IUnknown) ||
656 IsEqualIID(riid, &IID_IClassFactory))
658 *ppobj = iface;
659 IClassFactory_AddRef(iface);
660 return S_OK;
662 *ppobj = NULL;
663 return E_NOINTERFACE;
666 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
668 return 2;
671 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
673 /* static class, won't be freed */
674 return 1;
677 static HRESULT WINAPI DSCF_CreateInstance(
678 LPCLASSFACTORY iface,
679 LPUNKNOWN pOuter,
680 REFIID riid,
681 LPVOID *ppobj)
683 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
684 TRACE("(%p, %p, %s, %p)\n", This, pOuter, debugstr_guid(riid), ppobj);
686 if (pOuter)
687 return CLASS_E_NOAGGREGATION;
689 if (ppobj == NULL) {
690 WARN("invalid parameter\n");
691 return DSERR_INVALIDPARAM;
693 *ppobj = NULL;
694 return This->pfnCreateInstance(riid, ppobj);
697 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
699 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
700 FIXME("(%p, %d) stub!\n", This, dolock);
701 return S_OK;
704 static const IClassFactoryVtbl DSCF_Vtbl = {
705 DSCF_QueryInterface,
706 DSCF_AddRef,
707 DSCF_Release,
708 DSCF_CreateInstance,
709 DSCF_LockServer
712 static IClassFactoryImpl DSOUND_CF[] = {
713 { { &DSCF_Vtbl }, &CLSID_DirectSound, DSOUND_Create },
714 { { &DSCF_Vtbl }, &CLSID_DirectSound8, DSOUND_Create8 },
715 { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture, DSOUND_CaptureCreate },
716 { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture8, DSOUND_CaptureCreate8 },
717 { { &DSCF_Vtbl }, &CLSID_DirectSoundFullDuplex, DSOUND_FullDuplexCreate },
718 { { &DSCF_Vtbl }, &CLSID_DirectSoundPrivate, IKsPrivatePropertySetImpl_Create },
719 { { NULL }, NULL, NULL }
722 /*******************************************************************************
723 * DllGetClassObject [DSOUND.@]
724 * Retrieves class object from a DLL object
726 * NOTES
727 * Docs say returns STDAPI
729 * PARAMS
730 * rclsid [I] CLSID for the class object
731 * riid [I] Reference to identifier of interface for class object
732 * ppv [O] Address of variable to receive interface pointer for riid
734 * RETURNS
735 * Success: S_OK
736 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
737 * E_UNEXPECTED
739 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
741 int i = 0;
742 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
744 if (ppv == NULL) {
745 WARN("invalid parameter\n");
746 return E_INVALIDARG;
749 *ppv = NULL;
751 if (!IsEqualIID(riid, &IID_IClassFactory) &&
752 !IsEqualIID(riid, &IID_IUnknown)) {
753 WARN("no interface for %s\n", debugstr_guid(riid));
754 return E_NOINTERFACE;
757 while (NULL != DSOUND_CF[i].rclsid) {
758 if (IsEqualGUID(rclsid, DSOUND_CF[i].rclsid)) {
759 DSCF_AddRef(&DSOUND_CF[i].IClassFactory_iface);
760 *ppv = &DSOUND_CF[i];
761 return S_OK;
763 i++;
766 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid),
767 debugstr_guid(riid), ppv);
768 return CLASS_E_CLASSNOTAVAILABLE;
772 /*******************************************************************************
773 * DllCanUnloadNow [DSOUND.4]
774 * Determines whether the DLL is in use.
776 * RETURNS
777 * Can unload now: S_OK
778 * Cannot unload now (the DLL is still active): S_FALSE
780 HRESULT WINAPI DllCanUnloadNow(void)
782 return S_FALSE;
785 #define INIT_GUID(guid, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
786 guid.Data1 = l; guid.Data2 = w1; guid.Data3 = w2; \
787 guid.Data4[0] = b1; guid.Data4[1] = b2; guid.Data4[2] = b3; \
788 guid.Data4[3] = b4; guid.Data4[4] = b5; guid.Data4[5] = b6; \
789 guid.Data4[6] = b7; guid.Data4[7] = b8;
791 /***********************************************************************
792 * DllMain (DSOUND.init)
794 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
796 TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpvReserved);
798 switch (fdwReason) {
799 case DLL_PROCESS_ATTACH:
800 instance = hInstDLL;
801 DisableThreadLibraryCalls(hInstDLL);
802 /* Increase refcount on dsound by 1 */
803 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)hInstDLL, &hInstDLL);
804 break;
805 case DLL_PROCESS_DETACH:
806 if (lpvReserved) break;
807 DeleteCriticalSection(&DSOUND_renderers_lock);
808 DeleteCriticalSection(&DSOUND_capturers_lock);
809 break;
811 return TRUE;
814 /***********************************************************************
815 * DllRegisterServer (DSOUND.@)
817 HRESULT WINAPI DllRegisterServer(void)
819 return __wine_register_resources( instance );
822 /***********************************************************************
823 * DllUnregisterServer (DSOUND.@)
825 HRESULT WINAPI DllUnregisterServer(void)
827 return __wine_unregister_resources( instance );