mshtml: Added IE9+ mode support to HTMLFormElement::elements property.
[wine.git] / dlls / dsound / dsound_main.c
blob8dd86e40edcc4b1e8256a3134f34112e2501d52e
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 "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"
58 #include "strmif.h"
60 #include "initguid.h"
61 #include "ksmedia.h"
62 #include "propkey.h"
63 #include "devpkey.h"
65 #include "dsound_private.h"
67 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
69 struct list DSOUND_renderers = LIST_INIT(DSOUND_renderers);
70 CRITICAL_SECTION DSOUND_renderers_lock;
71 static CRITICAL_SECTION_DEBUG DSOUND_renderers_lock_debug =
73 0, 0, &DSOUND_renderers_lock,
74 { &DSOUND_renderers_lock_debug.ProcessLocksList, &DSOUND_renderers_lock_debug.ProcessLocksList },
75 0, 0, { (DWORD_PTR)(__FILE__ ": DSOUND_renderers_lock") }
77 CRITICAL_SECTION DSOUND_renderers_lock = { &DSOUND_renderers_lock_debug, -1, 0, 0, 0, 0 };
79 struct list DSOUND_capturers = LIST_INIT(DSOUND_capturers);
80 CRITICAL_SECTION DSOUND_capturers_lock;
81 static CRITICAL_SECTION_DEBUG DSOUND_capturers_lock_debug =
83 0, 0, &DSOUND_capturers_lock,
84 { &DSOUND_capturers_lock_debug.ProcessLocksList, &DSOUND_capturers_lock_debug.ProcessLocksList },
85 0, 0, { (DWORD_PTR)(__FILE__ ": DSOUND_capturers_lock") }
87 CRITICAL_SECTION DSOUND_capturers_lock = { &DSOUND_capturers_lock_debug, -1, 0, 0, 0, 0 };
89 GUID DSOUND_renderer_guids[MAXWAVEDRIVERS];
90 GUID DSOUND_capture_guids[MAXWAVEDRIVERS];
92 const WCHAR wine_vxd_drv[] = { 'w','i','n','e','m','m','.','v','x','d', 0 };
94 /* All default settings, you most likely don't want to touch these, see wiki on UsefulRegistryKeys */
95 int ds_hel_buflen = 32768 * 2;
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 (appkey) RegCloseKey( appkey );
149 if (hkey) RegCloseKey( hkey );
151 TRACE("ds_hel_buflen = %d\n", ds_hel_buflen);
154 static const char * get_device_id(LPCGUID pGuid)
156 if (IsEqualGUID(&DSDEVID_DefaultPlayback, pGuid))
157 return "DSDEVID_DefaultPlayback";
158 else if (IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuid))
159 return "DSDEVID_DefaultVoicePlayback";
160 else if (IsEqualGUID(&DSDEVID_DefaultCapture, pGuid))
161 return "DSDEVID_DefaultCapture";
162 else if (IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuid))
163 return "DSDEVID_DefaultVoiceCapture";
164 return debugstr_guid(pGuid);
167 static HRESULT get_mmdevenum(IMMDeviceEnumerator **devenum)
169 HRESULT hr, init_hr;
171 init_hr = CoInitialize(NULL);
173 hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL,
174 CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)devenum);
175 if(FAILED(hr)){
176 if(SUCCEEDED(init_hr))
177 CoUninitialize();
178 *devenum = NULL;
179 ERR("CoCreateInstance failed: %08x\n", hr);
180 return hr;
183 return init_hr;
186 static void release_mmdevenum(IMMDeviceEnumerator *devenum, HRESULT init_hr)
188 IMMDeviceEnumerator_Release(devenum);
189 if(SUCCEEDED(init_hr))
190 CoUninitialize();
193 static HRESULT get_mmdevice_guid(IMMDevice *device, IPropertyStore *ps,
194 GUID *guid)
196 PROPVARIANT pv;
197 HRESULT hr;
199 if(!ps){
200 hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
201 if(FAILED(hr)){
202 WARN("OpenPropertyStore failed: %08x\n", hr);
203 return hr;
205 }else
206 IPropertyStore_AddRef(ps);
208 PropVariantInit(&pv);
210 hr = IPropertyStore_GetValue(ps, &PKEY_AudioEndpoint_GUID, &pv);
211 if(FAILED(hr)){
212 IPropertyStore_Release(ps);
213 WARN("GetValue(GUID) failed: %08x\n", hr);
214 return hr;
217 CLSIDFromString(pv.u.pwszVal, guid);
219 PropVariantClear(&pv);
220 IPropertyStore_Release(ps);
222 return S_OK;
225 /***************************************************************************
226 * GetDeviceID [DSOUND.9]
228 * Retrieves unique identifier of default device specified
230 * PARAMS
231 * pGuidSrc [I] Address of device GUID.
232 * pGuidDest [O] Address to receive unique device GUID.
234 * RETURNS
235 * Success: DS_OK
236 * Failure: DSERR_INVALIDPARAM
238 * NOTES
239 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
240 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
241 * DSDEVID_DefaultVoiceCapture.
242 * Returns pGuidSrc if pGuidSrc is a valid device or the device
243 * GUID for the specified constants.
245 HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest)
247 IMMDeviceEnumerator *devenum;
248 EDataFlow flow = (EDataFlow)-1;
249 ERole role = (ERole)-1;
250 HRESULT hr, init_hr;
252 TRACE("(%s,%p)\n", get_device_id(pGuidSrc),pGuidDest);
254 if(!pGuidSrc || !pGuidDest)
255 return DSERR_INVALIDPARAM;
257 init_hr = get_mmdevenum(&devenum);
258 if(!devenum)
259 return init_hr;
261 if(IsEqualGUID(&DSDEVID_DefaultPlayback, pGuidSrc)){
262 role = eMultimedia;
263 flow = eRender;
264 }else if(IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuidSrc)){
265 role = eCommunications;
266 flow = eRender;
267 }else if(IsEqualGUID(&DSDEVID_DefaultCapture, pGuidSrc)){
268 role = eMultimedia;
269 flow = eCapture;
270 }else if(IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuidSrc)){
271 role = eCommunications;
272 flow = eCapture;
275 if(role != (ERole)-1 && flow != (EDataFlow)-1){
276 IMMDevice *device;
278 hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum,
279 flow, role, &device);
280 if(FAILED(hr)){
281 WARN("GetDefaultAudioEndpoint failed: %08x\n", hr);
282 release_mmdevenum(devenum, init_hr);
283 return DSERR_NODRIVER;
286 hr = get_mmdevice_guid(device, NULL, pGuidDest);
287 IMMDevice_Release(device);
289 release_mmdevenum(devenum, init_hr);
291 return (hr == S_OK) ? DS_OK : hr;
294 release_mmdevenum(devenum, init_hr);
296 *pGuidDest = *pGuidSrc;
298 return DS_OK;
301 struct morecontext
303 LPDSENUMCALLBACKA callA;
304 LPVOID data;
307 static BOOL CALLBACK a_to_w_callback(LPGUID guid, LPCWSTR descW, LPCWSTR modW, LPVOID data)
309 struct morecontext *context = data;
310 char descA[MAXPNAMELEN], modA[MAXPNAMELEN];
312 WideCharToMultiByte(CP_ACP, 0, descW, -1, descA, sizeof(descA), NULL, NULL);
313 WideCharToMultiByte(CP_ACP, 0, modW, -1, modA, sizeof(modA), NULL, NULL);
315 return context->callA(guid, descA, modA, context->data);
318 /***************************************************************************
319 * DirectSoundEnumerateA [DSOUND.2]
321 * Enumerate all DirectSound drivers installed in the system
323 * PARAMS
324 * lpDSEnumCallback [I] Address of callback function.
325 * lpContext [I] Address of user defined context passed to callback function.
327 * RETURNS
328 * Success: DS_OK
329 * Failure: DSERR_INVALIDPARAM
331 HRESULT WINAPI DirectSoundEnumerateA(
332 LPDSENUMCALLBACKA lpDSEnumCallback,
333 LPVOID lpContext)
335 struct morecontext context;
337 if (lpDSEnumCallback == NULL) {
338 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
339 return DSERR_INVALIDPARAM;
342 context.callA = lpDSEnumCallback;
343 context.data = lpContext;
345 return DirectSoundEnumerateW(a_to_w_callback, &context);
348 HRESULT get_mmdevice(EDataFlow flow, const GUID *tgt, IMMDevice **device)
350 IMMDeviceEnumerator *devenum;
351 IMMDeviceCollection *coll;
352 UINT count, i;
353 HRESULT hr, init_hr;
355 init_hr = get_mmdevenum(&devenum);
356 if(!devenum)
357 return init_hr;
359 hr = IMMDeviceEnumerator_EnumAudioEndpoints(devenum, flow,
360 DEVICE_STATE_ACTIVE, &coll);
361 if(FAILED(hr)){
362 WARN("EnumAudioEndpoints failed: %08x\n", hr);
363 release_mmdevenum(devenum, init_hr);
364 return hr;
367 hr = IMMDeviceCollection_GetCount(coll, &count);
368 if(FAILED(hr)){
369 IMMDeviceCollection_Release(coll);
370 release_mmdevenum(devenum, init_hr);
371 WARN("GetCount failed: %08x\n", hr);
372 return hr;
375 for(i = 0; i < count; ++i){
376 GUID guid;
378 hr = IMMDeviceCollection_Item(coll, i, device);
379 if(FAILED(hr))
380 continue;
382 hr = get_mmdevice_guid(*device, NULL, &guid);
383 if(FAILED(hr)){
384 IMMDevice_Release(*device);
385 continue;
388 if(IsEqualGUID(&guid, tgt)){
389 IMMDeviceCollection_Release(coll);
390 release_mmdevenum(devenum, init_hr);
391 return DS_OK;
394 IMMDevice_Release(*device);
397 WARN("No device with GUID %s found!\n", wine_dbgstr_guid(tgt));
399 IMMDeviceCollection_Release(coll);
400 release_mmdevenum(devenum, init_hr);
402 return DSERR_INVALIDPARAM;
405 static BOOL send_device(IMMDevice *device, GUID *guid,
406 LPDSENUMCALLBACKW cb, void *user)
408 IPropertyStore *ps;
409 PROPVARIANT pv;
410 BOOL keep_going;
411 HRESULT hr;
413 PropVariantInit(&pv);
415 hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
416 if(FAILED(hr)){
417 WARN("OpenPropertyStore failed: %08x\n", hr);
418 return TRUE;
421 hr = get_mmdevice_guid(device, ps, guid);
422 if(FAILED(hr)){
423 IPropertyStore_Release(ps);
424 return TRUE;
427 hr = IPropertyStore_GetValue(ps,
428 (const PROPERTYKEY *)&DEVPKEY_Device_FriendlyName, &pv);
429 if(FAILED(hr)){
430 IPropertyStore_Release(ps);
431 WARN("GetValue(FriendlyName) failed: %08x\n", hr);
432 return TRUE;
435 TRACE("Calling back with %s (%s)\n", wine_dbgstr_guid(guid),
436 wine_dbgstr_w(pv.u.pwszVal));
438 keep_going = cb(guid, pv.u.pwszVal, wine_vxd_drv, user);
440 PropVariantClear(&pv);
441 IPropertyStore_Release(ps);
443 return keep_going;
446 /* S_FALSE means the callback returned FALSE at some point
447 * S_OK means the callback always returned TRUE */
448 HRESULT enumerate_mmdevices(EDataFlow flow, GUID *guids,
449 LPDSENUMCALLBACKW cb, void *user)
451 IMMDeviceEnumerator *devenum;
452 IMMDeviceCollection *coll;
453 IMMDevice *defdev = NULL;
454 UINT count, i, n;
455 BOOL keep_going;
456 HRESULT hr, init_hr;
458 static const WCHAR primary_desc[] = {'P','r','i','m','a','r','y',' ',
459 'S','o','u','n','d',' ','D','r','i','v','e','r',0};
460 static const WCHAR empty_drv[] = {0};
462 init_hr = get_mmdevenum(&devenum);
463 if(!devenum)
464 return init_hr;
466 hr = IMMDeviceEnumerator_EnumAudioEndpoints(devenum, flow,
467 DEVICE_STATE_ACTIVE, &coll);
468 if(FAILED(hr)){
469 release_mmdevenum(devenum, init_hr);
470 WARN("EnumAudioEndpoints failed: %08x\n", hr);
471 return DS_OK;
474 hr = IMMDeviceCollection_GetCount(coll, &count);
475 if(FAILED(hr)){
476 IMMDeviceCollection_Release(coll);
477 release_mmdevenum(devenum, init_hr);
478 WARN("GetCount failed: %08x\n", hr);
479 return DS_OK;
482 if(count == 0){
483 release_mmdevenum(devenum, init_hr);
484 return DS_OK;
487 TRACE("Calling back with NULL (%s)\n", wine_dbgstr_w(primary_desc));
488 keep_going = cb(NULL, primary_desc, empty_drv, user);
490 /* always send the default device first */
491 if(keep_going){
492 hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum, flow,
493 eMultimedia, &defdev);
494 if(FAILED(hr)){
495 defdev = NULL;
496 n = 0;
497 }else{
498 keep_going = send_device(defdev, &guids[0], cb, user);
499 n = 1;
503 for(i = 0; keep_going && i < count; ++i){
504 IMMDevice *device;
506 hr = IMMDeviceCollection_Item(coll, i, &device);
507 if(FAILED(hr)){
508 WARN("Item failed: %08x\n", hr);
509 continue;
512 if(device != defdev){
513 keep_going = send_device(device, &guids[n], cb, user);
514 ++n;
517 IMMDevice_Release(device);
520 if(defdev)
521 IMMDevice_Release(defdev);
522 IMMDeviceCollection_Release(coll);
524 release_mmdevenum(devenum, init_hr);
526 return keep_going ? S_OK : S_FALSE;
529 /***************************************************************************
530 * DirectSoundEnumerateW [DSOUND.3]
532 * Enumerate all DirectSound drivers installed in the system
534 * PARAMS
535 * lpDSEnumCallback [I] Address of callback function.
536 * lpContext [I] Address of user defined context passed to callback function.
538 * RETURNS
539 * Success: DS_OK
540 * Failure: DSERR_INVALIDPARAM
542 HRESULT WINAPI DirectSoundEnumerateW(
543 LPDSENUMCALLBACKW lpDSEnumCallback,
544 LPVOID lpContext )
546 HRESULT hr;
548 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext);
550 if (lpDSEnumCallback == NULL) {
551 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
552 return DSERR_INVALIDPARAM;
555 setup_dsound_options();
557 hr = enumerate_mmdevices(eRender, DSOUND_renderer_guids,
558 lpDSEnumCallback, lpContext);
559 return SUCCEEDED(hr) ? DS_OK : hr;
562 /***************************************************************************
563 * DirectSoundCaptureEnumerateA [DSOUND.7]
565 * Enumerate all DirectSound drivers installed in the system.
567 * PARAMS
568 * lpDSEnumCallback [I] Address of callback function.
569 * lpContext [I] Address of user defined context passed to callback function.
571 * RETURNS
572 * Success: DS_OK
573 * Failure: DSERR_INVALIDPARAM
575 HRESULT WINAPI DirectSoundCaptureEnumerateA(
576 LPDSENUMCALLBACKA lpDSEnumCallback,
577 LPVOID lpContext)
579 struct morecontext context;
581 if (lpDSEnumCallback == NULL) {
582 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
583 return DSERR_INVALIDPARAM;
586 context.callA = lpDSEnumCallback;
587 context.data = lpContext;
589 return DirectSoundCaptureEnumerateW(a_to_w_callback, &context);
592 /***************************************************************************
593 * DirectSoundCaptureEnumerateW [DSOUND.8]
595 * Enumerate all DirectSound drivers installed in the system.
597 * PARAMS
598 * lpDSEnumCallback [I] Address of callback function.
599 * lpContext [I] Address of user defined context passed to callback function.
601 * RETURNS
602 * Success: DS_OK
603 * Failure: DSERR_INVALIDPARAM
605 HRESULT WINAPI
606 DirectSoundCaptureEnumerateW(
607 LPDSENUMCALLBACKW lpDSEnumCallback,
608 LPVOID lpContext)
610 HRESULT hr;
612 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext );
614 if (lpDSEnumCallback == NULL) {
615 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
616 return DSERR_INVALIDPARAM;
619 setup_dsound_options();
621 hr = enumerate_mmdevices(eCapture, DSOUND_capture_guids,
622 lpDSEnumCallback, lpContext);
623 return SUCCEEDED(hr) ? DS_OK : hr;
626 /*******************************************************************************
627 * DirectSound ClassFactory
630 typedef HRESULT (*FnCreateInstance)(REFIID riid, LPVOID *ppobj);
632 typedef struct {
633 IClassFactory IClassFactory_iface;
634 REFCLSID rclsid;
635 FnCreateInstance pfnCreateInstance;
636 } IClassFactoryImpl;
638 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
640 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
643 static HRESULT WINAPI
644 DSCF_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppobj)
646 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
647 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
648 if (ppobj == NULL)
649 return E_POINTER;
650 if (IsEqualIID(riid, &IID_IUnknown) ||
651 IsEqualIID(riid, &IID_IClassFactory))
653 *ppobj = iface;
654 IClassFactory_AddRef(iface);
655 return S_OK;
657 *ppobj = NULL;
658 return E_NOINTERFACE;
661 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
663 return 2;
666 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
668 /* static class, won't be freed */
669 return 1;
672 static HRESULT WINAPI DSCF_CreateInstance(
673 LPCLASSFACTORY iface,
674 LPUNKNOWN pOuter,
675 REFIID riid,
676 LPVOID *ppobj)
678 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
679 TRACE("(%p, %p, %s, %p)\n", This, pOuter, debugstr_guid(riid), ppobj);
681 if (pOuter)
682 return CLASS_E_NOAGGREGATION;
684 if (ppobj == NULL) {
685 WARN("invalid parameter\n");
686 return DSERR_INVALIDPARAM;
688 *ppobj = NULL;
689 return This->pfnCreateInstance(riid, ppobj);
692 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
694 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
695 FIXME("(%p, %d) stub!\n", This, dolock);
696 return S_OK;
699 static const IClassFactoryVtbl DSCF_Vtbl = {
700 DSCF_QueryInterface,
701 DSCF_AddRef,
702 DSCF_Release,
703 DSCF_CreateInstance,
704 DSCF_LockServer
707 static IClassFactoryImpl DSOUND_CF[] = {
708 { { &DSCF_Vtbl }, &CLSID_DirectSound, DSOUND_Create },
709 { { &DSCF_Vtbl }, &CLSID_DirectSound8, DSOUND_Create8 },
710 { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture, DSOUND_CaptureCreate },
711 { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture8, DSOUND_CaptureCreate8 },
712 { { &DSCF_Vtbl }, &CLSID_DirectSoundFullDuplex, DSOUND_FullDuplexCreate },
713 { { &DSCF_Vtbl }, &CLSID_DirectSoundPrivate, IKsPrivatePropertySetImpl_Create },
714 { { NULL }, NULL, NULL }
717 /*******************************************************************************
718 * DllGetClassObject [DSOUND.@]
719 * Retrieves class object from a DLL object
721 * NOTES
722 * Docs say returns STDAPI
724 * PARAMS
725 * rclsid [I] CLSID for the class object
726 * riid [I] Reference to identifier of interface for class object
727 * ppv [O] Address of variable to receive interface pointer for riid
729 * RETURNS
730 * Success: S_OK
731 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
732 * E_UNEXPECTED
734 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
736 int i = 0;
737 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
739 if (ppv == NULL) {
740 WARN("invalid parameter\n");
741 return E_INVALIDARG;
744 *ppv = NULL;
746 if (!IsEqualIID(riid, &IID_IClassFactory) &&
747 !IsEqualIID(riid, &IID_IUnknown)) {
748 WARN("no interface for %s\n", debugstr_guid(riid));
749 return E_NOINTERFACE;
752 while (NULL != DSOUND_CF[i].rclsid) {
753 if (IsEqualGUID(rclsid, DSOUND_CF[i].rclsid)) {
754 DSCF_AddRef(&DSOUND_CF[i].IClassFactory_iface);
755 *ppv = &DSOUND_CF[i];
756 return S_OK;
758 i++;
761 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid),
762 debugstr_guid(riid), ppv);
763 return CLASS_E_CLASSNOTAVAILABLE;
767 /*******************************************************************************
768 * DllCanUnloadNow [DSOUND.4]
769 * Determines whether the DLL is in use.
771 * RETURNS
772 * Can unload now: S_OK
773 * Cannot unload now (the DLL is still active): S_FALSE
775 HRESULT WINAPI DllCanUnloadNow(void)
777 return S_FALSE;
780 #define INIT_GUID(guid, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
781 guid.Data1 = l; guid.Data2 = w1; guid.Data3 = w2; \
782 guid.Data4[0] = b1; guid.Data4[1] = b2; guid.Data4[2] = b3; \
783 guid.Data4[3] = b4; guid.Data4[4] = b5; guid.Data4[5] = b6; \
784 guid.Data4[6] = b7; guid.Data4[7] = b8;
786 /***********************************************************************
787 * DllMain (DSOUND.init)
789 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
791 TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpvReserved);
793 switch (fdwReason) {
794 case DLL_PROCESS_ATTACH:
795 instance = hInstDLL;
796 DisableThreadLibraryCalls(hInstDLL);
797 /* Increase refcount on dsound by 1 */
798 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)hInstDLL, &hInstDLL);
799 break;
800 case DLL_PROCESS_DETACH:
801 if (lpvReserved) break;
802 DeleteCriticalSection(&DSOUND_renderers_lock);
803 DeleteCriticalSection(&DSOUND_capturers_lock);
804 break;
806 return TRUE;
809 /***********************************************************************
810 * DllRegisterServer (DSOUND.@)
812 HRESULT WINAPI DllRegisterServer(void)
814 return __wine_register_resources( instance );
817 /***********************************************************************
818 * DllUnregisterServer (DSOUND.@)
820 HRESULT WINAPI DllUnregisterServer(void)
822 return __wine_unregister_resources( instance );