gdi32: Move the handling of font family fallbacks out of freetype.c.
[wine/zf.git] / dlls / dsound / dsound_main.c
blobca33ba480469cab4e3685eed418441e703bf6bd4
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;
95 static HINSTANCE instance;
98 * Get a config key from either the app-specific or the default config
101 static inline DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
102 char *buffer, DWORD size )
104 if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
105 if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
106 return ERROR_FILE_NOT_FOUND;
111 * Setup the dsound options.
114 void setup_dsound_options(void)
116 char buffer[MAX_PATH+16];
117 HKEY hkey, appkey = 0;
118 DWORD len;
120 buffer[MAX_PATH]='\0';
122 /* @@ Wine registry key: HKCU\Software\Wine\DirectSound */
123 if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\DirectSound", &hkey )) hkey = 0;
125 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
126 if (len && len < MAX_PATH)
128 HKEY tmpkey;
129 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectSound */
130 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
132 char *p, *appname = buffer;
133 if ((p = strrchr( appname, '/' ))) appname = p + 1;
134 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
135 strcat( appname, "\\DirectSound" );
136 TRACE("appname = [%s]\n", appname);
137 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
138 RegCloseKey( tmpkey );
142 /* get options */
144 if (!get_config_key( hkey, appkey, "HelBuflen", buffer, MAX_PATH ))
145 ds_hel_buflen = atoi(buffer);
147 if (appkey) RegCloseKey( appkey );
148 if (hkey) RegCloseKey( hkey );
150 TRACE("ds_hel_buflen = %d\n", ds_hel_buflen);
153 static const char * get_device_id(LPCGUID pGuid)
155 if (IsEqualGUID(&DSDEVID_DefaultPlayback, pGuid))
156 return "DSDEVID_DefaultPlayback";
157 else if (IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuid))
158 return "DSDEVID_DefaultVoicePlayback";
159 else if (IsEqualGUID(&DSDEVID_DefaultCapture, pGuid))
160 return "DSDEVID_DefaultCapture";
161 else if (IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuid))
162 return "DSDEVID_DefaultVoiceCapture";
163 return debugstr_guid(pGuid);
166 static HRESULT get_mmdevenum(IMMDeviceEnumerator **devenum)
168 HRESULT hr, init_hr;
170 init_hr = CoInitialize(NULL);
172 hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL,
173 CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)devenum);
174 if(FAILED(hr)){
175 if(SUCCEEDED(init_hr))
176 CoUninitialize();
177 *devenum = NULL;
178 ERR("CoCreateInstance failed: %08x\n", hr);
179 return hr;
182 return init_hr;
185 static void release_mmdevenum(IMMDeviceEnumerator *devenum, HRESULT init_hr)
187 IMMDeviceEnumerator_Release(devenum);
188 if(SUCCEEDED(init_hr))
189 CoUninitialize();
192 static HRESULT get_mmdevice_guid(IMMDevice *device, IPropertyStore *ps,
193 GUID *guid)
195 PROPVARIANT pv;
196 HRESULT hr;
198 if(!ps){
199 hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
200 if(FAILED(hr)){
201 WARN("OpenPropertyStore failed: %08x\n", hr);
202 return hr;
204 }else
205 IPropertyStore_AddRef(ps);
207 PropVariantInit(&pv);
209 hr = IPropertyStore_GetValue(ps, &PKEY_AudioEndpoint_GUID, &pv);
210 if(FAILED(hr)){
211 IPropertyStore_Release(ps);
212 WARN("GetValue(GUID) failed: %08x\n", hr);
213 return hr;
216 CLSIDFromString(pv.u.pwszVal, guid);
218 PropVariantClear(&pv);
219 IPropertyStore_Release(ps);
221 return S_OK;
224 /***************************************************************************
225 * GetDeviceID [DSOUND.9]
227 * Retrieves unique identifier of default device specified
229 * PARAMS
230 * pGuidSrc [I] Address of device GUID.
231 * pGuidDest [O] Address to receive unique device GUID.
233 * RETURNS
234 * Success: DS_OK
235 * Failure: DSERR_INVALIDPARAM
237 * NOTES
238 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
239 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
240 * DSDEVID_DefaultVoiceCapture.
241 * Returns pGuidSrc if pGuidSrc is a valid device or the device
242 * GUID for the specified constants.
244 HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest)
246 IMMDeviceEnumerator *devenum;
247 EDataFlow flow = (EDataFlow)-1;
248 ERole role = (ERole)-1;
249 HRESULT hr, init_hr;
251 TRACE("(%s,%p)\n", get_device_id(pGuidSrc),pGuidDest);
253 if(!pGuidSrc || !pGuidDest)
254 return DSERR_INVALIDPARAM;
256 init_hr = get_mmdevenum(&devenum);
257 if(!devenum)
258 return init_hr;
260 if(IsEqualGUID(&DSDEVID_DefaultPlayback, pGuidSrc)){
261 role = eMultimedia;
262 flow = eRender;
263 }else if(IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuidSrc)){
264 role = eCommunications;
265 flow = eRender;
266 }else if(IsEqualGUID(&DSDEVID_DefaultCapture, pGuidSrc)){
267 role = eMultimedia;
268 flow = eCapture;
269 }else if(IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuidSrc)){
270 role = eCommunications;
271 flow = eCapture;
274 if(role != (ERole)-1 && flow != (EDataFlow)-1){
275 IMMDevice *device;
277 hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum,
278 flow, role, &device);
279 if(FAILED(hr)){
280 WARN("GetDefaultAudioEndpoint failed: %08x\n", hr);
281 release_mmdevenum(devenum, init_hr);
282 return DSERR_NODRIVER;
285 hr = get_mmdevice_guid(device, NULL, pGuidDest);
286 IMMDevice_Release(device);
288 release_mmdevenum(devenum, init_hr);
290 return (hr == S_OK) ? DS_OK : hr;
293 release_mmdevenum(devenum, init_hr);
295 *pGuidDest = *pGuidSrc;
297 return DS_OK;
300 struct morecontext
302 LPDSENUMCALLBACKA callA;
303 LPVOID data;
306 static BOOL CALLBACK a_to_w_callback(LPGUID guid, LPCWSTR descW, LPCWSTR modW, LPVOID data)
308 struct morecontext *context = data;
309 char descA[MAXPNAMELEN], modA[MAXPNAMELEN];
311 WideCharToMultiByte(CP_ACP, 0, descW, -1, descA, sizeof(descA), NULL, NULL);
312 WideCharToMultiByte(CP_ACP, 0, modW, -1, modA, sizeof(modA), NULL, NULL);
314 return context->callA(guid, descA, modA, context->data);
317 /***************************************************************************
318 * DirectSoundEnumerateA [DSOUND.2]
320 * Enumerate all DirectSound drivers installed in the system
322 * PARAMS
323 * lpDSEnumCallback [I] Address of callback function.
324 * lpContext [I] Address of user defined context passed to callback function.
326 * RETURNS
327 * Success: DS_OK
328 * Failure: DSERR_INVALIDPARAM
330 HRESULT WINAPI DirectSoundEnumerateA(
331 LPDSENUMCALLBACKA lpDSEnumCallback,
332 LPVOID lpContext)
334 struct morecontext context;
336 if (lpDSEnumCallback == NULL) {
337 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
338 return DSERR_INVALIDPARAM;
341 context.callA = lpDSEnumCallback;
342 context.data = lpContext;
344 return DirectSoundEnumerateW(a_to_w_callback, &context);
347 HRESULT get_mmdevice(EDataFlow flow, const GUID *tgt, IMMDevice **device)
349 IMMDeviceEnumerator *devenum;
350 IMMDeviceCollection *coll;
351 UINT count, i;
352 HRESULT hr, init_hr;
354 init_hr = get_mmdevenum(&devenum);
355 if(!devenum)
356 return init_hr;
358 hr = IMMDeviceEnumerator_EnumAudioEndpoints(devenum, flow,
359 DEVICE_STATE_ACTIVE, &coll);
360 if(FAILED(hr)){
361 WARN("EnumAudioEndpoints failed: %08x\n", hr);
362 release_mmdevenum(devenum, init_hr);
363 return hr;
366 hr = IMMDeviceCollection_GetCount(coll, &count);
367 if(FAILED(hr)){
368 IMMDeviceCollection_Release(coll);
369 release_mmdevenum(devenum, init_hr);
370 WARN("GetCount failed: %08x\n", hr);
371 return hr;
374 for(i = 0; i < count; ++i){
375 GUID guid;
377 hr = IMMDeviceCollection_Item(coll, i, device);
378 if(FAILED(hr))
379 continue;
381 hr = get_mmdevice_guid(*device, NULL, &guid);
382 if(FAILED(hr)){
383 IMMDevice_Release(*device);
384 continue;
387 if(IsEqualGUID(&guid, tgt)){
388 IMMDeviceCollection_Release(coll);
389 release_mmdevenum(devenum, init_hr);
390 return DS_OK;
393 IMMDevice_Release(*device);
396 WARN("No device with GUID %s found!\n", wine_dbgstr_guid(tgt));
398 IMMDeviceCollection_Release(coll);
399 release_mmdevenum(devenum, init_hr);
401 return DSERR_INVALIDPARAM;
404 static BOOL send_device(IMMDevice *device, GUID *guid,
405 LPDSENUMCALLBACKW cb, void *user)
407 IPropertyStore *ps;
408 PROPVARIANT pv;
409 BOOL keep_going;
410 HRESULT hr;
412 PropVariantInit(&pv);
414 hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
415 if(FAILED(hr)){
416 WARN("OpenPropertyStore failed: %08x\n", hr);
417 return TRUE;
420 hr = get_mmdevice_guid(device, ps, guid);
421 if(FAILED(hr)){
422 IPropertyStore_Release(ps);
423 return TRUE;
426 hr = IPropertyStore_GetValue(ps,
427 (const PROPERTYKEY *)&DEVPKEY_Device_FriendlyName, &pv);
428 if(FAILED(hr)){
429 IPropertyStore_Release(ps);
430 WARN("GetValue(FriendlyName) failed: %08x\n", hr);
431 return TRUE;
434 TRACE("Calling back with %s (%s)\n", wine_dbgstr_guid(guid),
435 wine_dbgstr_w(pv.u.pwszVal));
437 keep_going = cb(guid, pv.u.pwszVal, wine_vxd_drv, user);
439 PropVariantClear(&pv);
440 IPropertyStore_Release(ps);
442 return keep_going;
445 /* S_FALSE means the callback returned FALSE at some point
446 * S_OK means the callback always returned TRUE */
447 HRESULT enumerate_mmdevices(EDataFlow flow, GUID *guids,
448 LPDSENUMCALLBACKW cb, void *user)
450 IMMDeviceEnumerator *devenum;
451 IMMDeviceCollection *coll;
452 IMMDevice *defdev = NULL;
453 UINT count, i, n;
454 BOOL keep_going;
455 HRESULT hr, init_hr;
457 init_hr = get_mmdevenum(&devenum);
458 if(!devenum)
459 return init_hr;
461 hr = IMMDeviceEnumerator_EnumAudioEndpoints(devenum, flow,
462 DEVICE_STATE_ACTIVE, &coll);
463 if(FAILED(hr)){
464 release_mmdevenum(devenum, init_hr);
465 WARN("EnumAudioEndpoints failed: %08x\n", hr);
466 return DS_OK;
469 hr = IMMDeviceCollection_GetCount(coll, &count);
470 if(FAILED(hr)){
471 IMMDeviceCollection_Release(coll);
472 release_mmdevenum(devenum, init_hr);
473 WARN("GetCount failed: %08x\n", hr);
474 return DS_OK;
477 if(count == 0){
478 IMMDeviceCollection_Release(coll);
479 release_mmdevenum(devenum, init_hr);
480 return DS_OK;
483 TRACE("Calling back with NULL (Primary Sound Driver)\n");
484 keep_going = cb(NULL, L"Primary Sound Driver", L"", user);
486 /* always send the default device first */
487 if(keep_going){
488 hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum, flow,
489 eMultimedia, &defdev);
490 if(FAILED(hr)){
491 defdev = NULL;
492 n = 0;
493 }else{
494 keep_going = send_device(defdev, &guids[0], cb, user);
495 n = 1;
499 for(i = 0; keep_going && i < count; ++i){
500 IMMDevice *device;
502 hr = IMMDeviceCollection_Item(coll, i, &device);
503 if(FAILED(hr)){
504 WARN("Item failed: %08x\n", hr);
505 continue;
508 if(device != defdev){
509 keep_going = send_device(device, &guids[n], cb, user);
510 ++n;
513 IMMDevice_Release(device);
516 if(defdev)
517 IMMDevice_Release(defdev);
518 IMMDeviceCollection_Release(coll);
520 release_mmdevenum(devenum, init_hr);
522 return keep_going ? S_OK : S_FALSE;
525 /***************************************************************************
526 * DirectSoundEnumerateW [DSOUND.3]
528 * Enumerate all DirectSound drivers installed in the system
530 * PARAMS
531 * lpDSEnumCallback [I] Address of callback function.
532 * lpContext [I] Address of user defined context passed to callback function.
534 * RETURNS
535 * Success: DS_OK
536 * Failure: DSERR_INVALIDPARAM
538 HRESULT WINAPI DirectSoundEnumerateW(
539 LPDSENUMCALLBACKW lpDSEnumCallback,
540 LPVOID lpContext )
542 HRESULT hr;
544 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext);
546 if (lpDSEnumCallback == NULL) {
547 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
548 return DSERR_INVALIDPARAM;
551 setup_dsound_options();
553 hr = enumerate_mmdevices(eRender, DSOUND_renderer_guids,
554 lpDSEnumCallback, lpContext);
555 return SUCCEEDED(hr) ? DS_OK : hr;
558 /***************************************************************************
559 * DirectSoundCaptureEnumerateA [DSOUND.7]
561 * Enumerate all DirectSound drivers installed in the system.
563 * PARAMS
564 * lpDSEnumCallback [I] Address of callback function.
565 * lpContext [I] Address of user defined context passed to callback function.
567 * RETURNS
568 * Success: DS_OK
569 * Failure: DSERR_INVALIDPARAM
571 HRESULT WINAPI DirectSoundCaptureEnumerateA(
572 LPDSENUMCALLBACKA lpDSEnumCallback,
573 LPVOID lpContext)
575 struct morecontext context;
577 if (lpDSEnumCallback == NULL) {
578 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
579 return DSERR_INVALIDPARAM;
582 context.callA = lpDSEnumCallback;
583 context.data = lpContext;
585 return DirectSoundCaptureEnumerateW(a_to_w_callback, &context);
588 /***************************************************************************
589 * DirectSoundCaptureEnumerateW [DSOUND.8]
591 * Enumerate all DirectSound drivers installed in the system.
593 * PARAMS
594 * lpDSEnumCallback [I] Address of callback function.
595 * lpContext [I] Address of user defined context passed to callback function.
597 * RETURNS
598 * Success: DS_OK
599 * Failure: DSERR_INVALIDPARAM
601 HRESULT WINAPI
602 DirectSoundCaptureEnumerateW(
603 LPDSENUMCALLBACKW lpDSEnumCallback,
604 LPVOID lpContext)
606 HRESULT hr;
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(eCapture, DSOUND_capture_guids,
618 lpDSEnumCallback, lpContext);
619 return SUCCEEDED(hr) ? DS_OK : hr;
622 /*******************************************************************************
623 * DirectSound ClassFactory
626 typedef HRESULT (*FnCreateInstance)(REFIID riid, LPVOID *ppobj);
628 typedef struct {
629 IClassFactory IClassFactory_iface;
630 REFCLSID rclsid;
631 FnCreateInstance pfnCreateInstance;
632 } IClassFactoryImpl;
634 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
636 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
639 static HRESULT WINAPI
640 DSCF_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppobj)
642 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
643 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
644 if (ppobj == NULL)
645 return E_POINTER;
646 if (IsEqualIID(riid, &IID_IUnknown) ||
647 IsEqualIID(riid, &IID_IClassFactory))
649 *ppobj = iface;
650 IClassFactory_AddRef(iface);
651 return S_OK;
653 *ppobj = NULL;
654 return E_NOINTERFACE;
657 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
659 return 2;
662 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
664 /* static class, won't be freed */
665 return 1;
668 static HRESULT WINAPI DSCF_CreateInstance(
669 LPCLASSFACTORY iface,
670 LPUNKNOWN pOuter,
671 REFIID riid,
672 LPVOID *ppobj)
674 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
675 TRACE("(%p, %p, %s, %p)\n", This, pOuter, debugstr_guid(riid), ppobj);
677 if (pOuter)
678 return CLASS_E_NOAGGREGATION;
680 if (ppobj == NULL) {
681 WARN("invalid parameter\n");
682 return DSERR_INVALIDPARAM;
684 *ppobj = NULL;
685 return This->pfnCreateInstance(riid, ppobj);
688 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
690 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
691 FIXME("(%p, %d) stub!\n", This, dolock);
692 return S_OK;
695 static const IClassFactoryVtbl DSCF_Vtbl = {
696 DSCF_QueryInterface,
697 DSCF_AddRef,
698 DSCF_Release,
699 DSCF_CreateInstance,
700 DSCF_LockServer
703 static IClassFactoryImpl DSOUND_CF[] = {
704 { { &DSCF_Vtbl }, &CLSID_DirectSound, DSOUND_Create },
705 { { &DSCF_Vtbl }, &CLSID_DirectSound8, DSOUND_Create8 },
706 { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture, DSOUND_CaptureCreate },
707 { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture8, DSOUND_CaptureCreate8 },
708 { { &DSCF_Vtbl }, &CLSID_DirectSoundFullDuplex, DSOUND_FullDuplexCreate },
709 { { &DSCF_Vtbl }, &CLSID_DirectSoundPrivate, IKsPrivatePropertySetImpl_Create },
710 { { NULL }, NULL, NULL }
713 /*******************************************************************************
714 * DllGetClassObject [DSOUND.@]
715 * Retrieves class object from a DLL object
717 * NOTES
718 * Docs say returns STDAPI
720 * PARAMS
721 * rclsid [I] CLSID for the class object
722 * riid [I] Reference to identifier of interface for class object
723 * ppv [O] Address of variable to receive interface pointer for riid
725 * RETURNS
726 * Success: S_OK
727 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
728 * E_UNEXPECTED
730 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
732 int i = 0;
733 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
735 if (ppv == NULL) {
736 WARN("invalid parameter\n");
737 return E_INVALIDARG;
740 *ppv = NULL;
742 if (!IsEqualIID(riid, &IID_IClassFactory) &&
743 !IsEqualIID(riid, &IID_IUnknown)) {
744 WARN("no interface for %s\n", debugstr_guid(riid));
745 return E_NOINTERFACE;
748 while (NULL != DSOUND_CF[i].rclsid) {
749 if (IsEqualGUID(rclsid, DSOUND_CF[i].rclsid)) {
750 DSCF_AddRef(&DSOUND_CF[i].IClassFactory_iface);
751 *ppv = &DSOUND_CF[i];
752 return S_OK;
754 i++;
757 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid),
758 debugstr_guid(riid), ppv);
759 return CLASS_E_CLASSNOTAVAILABLE;
763 /*******************************************************************************
764 * DllCanUnloadNow [DSOUND.4]
765 * Determines whether the DLL is in use.
767 * RETURNS
768 * Can unload now: S_OK
769 * Cannot unload now (the DLL is still active): S_FALSE
771 HRESULT WINAPI DllCanUnloadNow(void)
773 return S_FALSE;
776 #define INIT_GUID(guid, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
777 guid.Data1 = l; guid.Data2 = w1; guid.Data3 = w2; \
778 guid.Data4[0] = b1; guid.Data4[1] = b2; guid.Data4[2] = b3; \
779 guid.Data4[3] = b4; guid.Data4[4] = b5; guid.Data4[5] = b6; \
780 guid.Data4[6] = b7; guid.Data4[7] = b8;
782 /***********************************************************************
783 * DllMain (DSOUND.init)
785 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
787 TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpvReserved);
789 switch (fdwReason) {
790 case DLL_PROCESS_ATTACH:
791 instance = hInstDLL;
792 DisableThreadLibraryCalls(hInstDLL);
793 /* Increase refcount on dsound by 1 */
794 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)hInstDLL, &hInstDLL);
795 break;
796 case DLL_PROCESS_DETACH:
797 if (lpvReserved) break;
798 DeleteCriticalSection(&DSOUND_renderers_lock);
799 DeleteCriticalSection(&DSOUND_capturers_lock);
800 break;
802 return TRUE;
805 /***********************************************************************
806 * DllRegisterServer (DSOUND.@)
808 HRESULT WINAPI DllRegisterServer(void)
810 return __wine_register_resources( instance );
813 /***********************************************************************
814 * DllUnregisterServer (DSOUND.@)
816 HRESULT WINAPI DllUnregisterServer(void)
818 return __wine_unregister_resources( instance );