win32u: Use the dummy surface for empty layered window surfaces.
[wine.git] / dlls / dsound / dsound_main.c
blobbb373a4304d343cf5b32488f48610fd066985ad6
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 #include "windef.h"
39 #include "winbase.h"
40 #include "winuser.h"
41 #include "winnls.h"
42 #include "winreg.h"
43 #include "mmsystem.h"
44 #include "mmddk.h"
45 #include "wine/debug.h"
46 #include "dsound.h"
47 #include "dsconf.h"
48 #include "ks.h"
49 #include "rpcproxy.h"
50 #include "rpc.h"
51 #include "rpcndr.h"
52 #include "unknwn.h"
53 #include "oleidl.h"
54 #include "shobjidl.h"
55 #include "propkey.h"
57 #include "initguid.h"
58 #include "propkeydef.h"
59 #include "ksmedia.h"
60 #include "devpkey.h"
62 #include "dsound_private.h"
64 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
66 struct list DSOUND_renderers = LIST_INIT(DSOUND_renderers);
67 CRITICAL_SECTION DSOUND_renderers_lock;
68 static CRITICAL_SECTION_DEBUG DSOUND_renderers_lock_debug =
70 0, 0, &DSOUND_renderers_lock,
71 { &DSOUND_renderers_lock_debug.ProcessLocksList, &DSOUND_renderers_lock_debug.ProcessLocksList },
72 0, 0, { (DWORD_PTR)(__FILE__ ": DSOUND_renderers_lock") }
74 CRITICAL_SECTION DSOUND_renderers_lock = { &DSOUND_renderers_lock_debug, -1, 0, 0, 0, 0 };
76 /* Some applications expect the GUID pointers emitted from DirectSoundCaptureEnumerate to remain
77 * valid at least until the next time DirectSoundCaptureEnumerate is called, so we store them in
78 * these dynamically allocated arrays. */
79 GUID *DSOUND_renderer_guids;
80 GUID *DSOUND_capture_guids;
82 const WCHAR wine_vxd_drv[] = L"winemm.vxd";
84 /* All default settings, you most likely don't want to touch these, see wiki on UsefulRegistryKeys */
85 int ds_hel_buflen = 32768 * 2;
88 * Get a config key from either the app-specific or the default config
91 static inline DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
92 char *buffer, DWORD size )
94 if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
95 if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
96 return ERROR_FILE_NOT_FOUND;
101 * Setup the dsound options.
104 void setup_dsound_options(void)
106 char buffer[MAX_PATH+16];
107 HKEY hkey, appkey = 0;
108 DWORD len;
110 buffer[MAX_PATH]='\0';
112 /* @@ Wine registry key: HKCU\Software\Wine\DirectSound */
113 if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\DirectSound", &hkey )) hkey = 0;
115 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
116 if (len && len < MAX_PATH)
118 HKEY tmpkey;
119 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectSound */
120 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
122 char *p, *appname = buffer;
123 if ((p = strrchr( appname, '/' ))) appname = p + 1;
124 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
125 strcat( appname, "\\DirectSound" );
126 TRACE("appname = [%s]\n", appname);
127 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
128 RegCloseKey( tmpkey );
132 /* get options */
134 if (!get_config_key( hkey, appkey, "HelBuflen", buffer, MAX_PATH ))
135 ds_hel_buflen = atoi(buffer);
137 if (appkey) RegCloseKey( appkey );
138 if (hkey) RegCloseKey( hkey );
140 TRACE("ds_hel_buflen = %d\n", ds_hel_buflen);
143 static const char * get_device_id(LPCGUID pGuid)
145 if (IsEqualGUID(&DSDEVID_DefaultPlayback, pGuid))
146 return "DSDEVID_DefaultPlayback";
147 else if (IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuid))
148 return "DSDEVID_DefaultVoicePlayback";
149 else if (IsEqualGUID(&DSDEVID_DefaultCapture, pGuid))
150 return "DSDEVID_DefaultCapture";
151 else if (IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuid))
152 return "DSDEVID_DefaultVoiceCapture";
153 return debugstr_guid(pGuid);
156 static HRESULT get_mmdevenum(IMMDeviceEnumerator **devenum)
158 HRESULT hr, init_hr;
160 init_hr = CoInitialize(NULL);
162 hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL,
163 CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)devenum);
164 if(FAILED(hr)){
165 if(SUCCEEDED(init_hr))
166 CoUninitialize();
167 *devenum = NULL;
168 ERR("CoCreateInstance failed: %08lx\n", hr);
169 return hr;
172 return init_hr;
175 static void release_mmdevenum(IMMDeviceEnumerator *devenum, HRESULT init_hr)
177 IMMDeviceEnumerator_Release(devenum);
178 if(SUCCEEDED(init_hr))
179 CoUninitialize();
182 static HRESULT get_mmdevice_guid(IMMDevice *device, IPropertyStore *ps,
183 GUID *guid)
185 PROPVARIANT pv;
186 HRESULT hr;
188 if(!ps){
189 hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
190 if(FAILED(hr)){
191 WARN("OpenPropertyStore failed: %08lx\n", hr);
192 return hr;
194 }else
195 IPropertyStore_AddRef(ps);
197 PropVariantInit(&pv);
199 hr = IPropertyStore_GetValue(ps, &PKEY_AudioEndpoint_GUID, &pv);
200 if(FAILED(hr)){
201 IPropertyStore_Release(ps);
202 WARN("GetValue(GUID) failed: %08lx\n", hr);
203 return hr;
206 CLSIDFromString(pv.pwszVal, guid);
208 PropVariantClear(&pv);
209 IPropertyStore_Release(ps);
211 return S_OK;
214 /***************************************************************************
215 * GetDeviceID [DSOUND.9]
217 * Retrieves unique identifier of default device specified
219 * PARAMS
220 * pGuidSrc [I] Address of device GUID.
221 * pGuidDest [O] Address to receive unique device GUID.
223 * RETURNS
224 * Success: DS_OK
225 * Failure: DSERR_INVALIDPARAM
227 * NOTES
228 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
229 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
230 * DSDEVID_DefaultVoiceCapture.
231 * Returns pGuidSrc if pGuidSrc is a valid device or the device
232 * GUID for the specified constants.
234 HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest)
236 IMMDeviceEnumerator *devenum;
237 EDataFlow flow = (EDataFlow)-1;
238 ERole role = (ERole)-1;
239 HRESULT hr, init_hr;
241 TRACE("(%s,%p)\n", get_device_id(pGuidSrc),pGuidDest);
243 if(!pGuidSrc || !pGuidDest)
244 return DSERR_INVALIDPARAM;
246 init_hr = get_mmdevenum(&devenum);
247 if(!devenum)
248 return init_hr;
250 if(IsEqualGUID(&DSDEVID_DefaultPlayback, pGuidSrc)){
251 role = eMultimedia;
252 flow = eRender;
253 }else if(IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuidSrc)){
254 role = eCommunications;
255 flow = eRender;
256 }else if(IsEqualGUID(&DSDEVID_DefaultCapture, pGuidSrc)){
257 role = eMultimedia;
258 flow = eCapture;
259 }else if(IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuidSrc)){
260 role = eCommunications;
261 flow = eCapture;
264 if(role != (ERole)-1 && flow != (EDataFlow)-1){
265 IMMDevice *device;
267 hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum,
268 flow, role, &device);
269 if(FAILED(hr)){
270 WARN("GetDefaultAudioEndpoint failed: %08lx\n", hr);
271 release_mmdevenum(devenum, init_hr);
272 return DSERR_NODRIVER;
275 hr = get_mmdevice_guid(device, NULL, pGuidDest);
276 IMMDevice_Release(device);
278 release_mmdevenum(devenum, init_hr);
280 return (hr == S_OK) ? DS_OK : hr;
283 release_mmdevenum(devenum, init_hr);
285 *pGuidDest = *pGuidSrc;
287 return DS_OK;
290 struct morecontext
292 LPDSENUMCALLBACKA callA;
293 LPVOID data;
296 static BOOL CALLBACK a_to_w_callback(LPGUID guid, LPCWSTR descW, LPCWSTR modW, LPVOID data)
298 struct morecontext *context = data;
299 char descA[MAXPNAMELEN], modA[MAXPNAMELEN];
301 WideCharToMultiByte(CP_ACP, 0, descW, -1, descA, sizeof(descA), NULL, NULL);
302 WideCharToMultiByte(CP_ACP, 0, modW, -1, modA, sizeof(modA), NULL, NULL);
304 return context->callA(guid, descA, modA, context->data);
307 /***************************************************************************
308 * DirectSoundEnumerateA [DSOUND.2]
310 * Enumerate all DirectSound drivers installed in the system
312 * PARAMS
313 * lpDSEnumCallback [I] Address of callback function.
314 * lpContext [I] Address of user defined context passed to callback function.
316 * RETURNS
317 * Success: DS_OK
318 * Failure: DSERR_INVALIDPARAM
320 HRESULT WINAPI DirectSoundEnumerateA(
321 LPDSENUMCALLBACKA lpDSEnumCallback,
322 LPVOID lpContext)
324 struct morecontext context;
326 if (lpDSEnumCallback == NULL) {
327 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
328 return DSERR_INVALIDPARAM;
331 context.callA = lpDSEnumCallback;
332 context.data = lpContext;
334 return DirectSoundEnumerateW(a_to_w_callback, &context);
337 HRESULT get_mmdevice(EDataFlow flow, const GUID *tgt, IMMDevice **device)
339 IMMDeviceEnumerator *devenum;
340 IMMDeviceCollection *coll;
341 UINT count, i;
342 HRESULT hr, init_hr;
344 init_hr = get_mmdevenum(&devenum);
345 if(!devenum)
346 return init_hr;
348 hr = IMMDeviceEnumerator_EnumAudioEndpoints(devenum, flow,
349 DEVICE_STATE_ACTIVE, &coll);
350 if(FAILED(hr)){
351 WARN("EnumAudioEndpoints failed: %08lx\n", hr);
352 release_mmdevenum(devenum, init_hr);
353 return hr;
356 hr = IMMDeviceCollection_GetCount(coll, &count);
357 if(FAILED(hr)){
358 IMMDeviceCollection_Release(coll);
359 release_mmdevenum(devenum, init_hr);
360 WARN("GetCount failed: %08lx\n", hr);
361 return hr;
364 for(i = 0; i < count; ++i){
365 GUID guid;
367 hr = IMMDeviceCollection_Item(coll, i, device);
368 if(FAILED(hr))
369 continue;
371 hr = get_mmdevice_guid(*device, NULL, &guid);
372 if(FAILED(hr)){
373 IMMDevice_Release(*device);
374 continue;
377 if(IsEqualGUID(&guid, tgt)){
378 IMMDeviceCollection_Release(coll);
379 release_mmdevenum(devenum, init_hr);
380 return DS_OK;
383 IMMDevice_Release(*device);
386 WARN("No device with GUID %s found!\n", wine_dbgstr_guid(tgt));
388 IMMDeviceCollection_Release(coll);
389 release_mmdevenum(devenum, init_hr);
391 return DSERR_INVALIDPARAM;
394 static BOOL send_device(IMMDevice *device, GUID *guid,
395 LPDSENUMCALLBACKW cb, void *user)
397 IPropertyStore *ps;
398 PROPVARIANT pv;
399 BOOL keep_going;
400 HRESULT hr;
402 PropVariantInit(&pv);
404 hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
405 if(FAILED(hr)){
406 WARN("OpenPropertyStore failed: %08lx\n", hr);
407 return TRUE;
410 hr = get_mmdevice_guid(device, ps, guid);
411 if(FAILED(hr)){
412 IPropertyStore_Release(ps);
413 return TRUE;
416 hr = IPropertyStore_GetValue(ps,
417 (const PROPERTYKEY *)&DEVPKEY_Device_FriendlyName, &pv);
418 if(FAILED(hr)){
419 IPropertyStore_Release(ps);
420 WARN("GetValue(FriendlyName) failed: %08lx\n", hr);
421 return TRUE;
424 TRACE("Calling back with %s (%s)\n", wine_dbgstr_guid(guid),
425 wine_dbgstr_w(pv.pwszVal));
427 keep_going = cb(guid, pv.pwszVal, wine_vxd_drv, user);
429 PropVariantClear(&pv);
430 IPropertyStore_Release(ps);
432 return keep_going;
435 /* S_FALSE means the callback returned FALSE at some point
436 * S_OK means the callback always returned TRUE */
437 HRESULT enumerate_mmdevices(EDataFlow flow, GUID *guids,
438 LPDSENUMCALLBACKW cb, void *user)
440 IMMDeviceEnumerator *devenum;
441 IMMDeviceCollection *coll;
442 IMMDevice *defdev = NULL;
443 UINT count, i, n;
444 BOOL keep_going;
445 HRESULT hr, init_hr;
447 init_hr = get_mmdevenum(&devenum);
448 if(!devenum)
449 return init_hr;
451 hr = IMMDeviceEnumerator_EnumAudioEndpoints(devenum, flow,
452 DEVICE_STATE_ACTIVE, &coll);
453 if(FAILED(hr)){
454 release_mmdevenum(devenum, init_hr);
455 WARN("EnumAudioEndpoints failed: %08lx\n", hr);
456 return DS_OK;
459 hr = IMMDeviceCollection_GetCount(coll, &count);
460 if(FAILED(hr)){
461 IMMDeviceCollection_Release(coll);
462 release_mmdevenum(devenum, init_hr);
463 WARN("GetCount failed: %08lx\n", hr);
464 return DS_OK;
467 free(guids);
468 if(count == 0){
469 IMMDeviceCollection_Release(coll);
470 release_mmdevenum(devenum, init_hr);
471 guids = NULL;
472 return DS_OK;
474 guids = malloc((count + 1) * sizeof(GUID));
475 if(!guids){
476 IMMDeviceCollection_Release(coll);
477 release_mmdevenum(devenum, init_hr);
478 return E_OUTOFMEMORY;
481 TRACE("Calling back with NULL (Primary Sound Driver)\n");
482 keep_going = cb(NULL, L"Primary Sound Driver", L"", user);
484 /* always send the default device first */
485 if(keep_going){
486 hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum, flow,
487 eMultimedia, &defdev);
488 if(FAILED(hr)){
489 defdev = NULL;
490 n = 0;
491 }else{
492 keep_going = send_device(defdev, &guids[0], cb, user);
493 n = 1;
497 for(i = 0; keep_going && i < count; ++i){
498 IMMDevice *device;
500 hr = IMMDeviceCollection_Item(coll, i, &device);
501 if(FAILED(hr)){
502 WARN("Item failed: %08lx\n", hr);
503 continue;
506 if(device != defdev){
507 keep_going = send_device(device, &guids[n], cb, user);
508 ++n;
511 IMMDevice_Release(device);
514 if(defdev)
515 IMMDevice_Release(defdev);
516 IMMDeviceCollection_Release(coll);
518 release_mmdevenum(devenum, init_hr);
520 return keep_going ? S_OK : S_FALSE;
523 /***************************************************************************
524 * DirectSoundEnumerateW [DSOUND.3]
526 * Enumerate all DirectSound drivers installed in the system
528 * PARAMS
529 * lpDSEnumCallback [I] Address of callback function.
530 * lpContext [I] Address of user defined context passed to callback function.
532 * RETURNS
533 * Success: DS_OK
534 * Failure: DSERR_INVALIDPARAM
536 HRESULT WINAPI DirectSoundEnumerateW(
537 LPDSENUMCALLBACKW lpDSEnumCallback,
538 LPVOID lpContext )
540 HRESULT hr;
542 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext);
544 if (lpDSEnumCallback == NULL) {
545 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
546 return DSERR_INVALIDPARAM;
549 setup_dsound_options();
551 hr = enumerate_mmdevices(eRender, DSOUND_renderer_guids,
552 lpDSEnumCallback, lpContext);
553 return SUCCEEDED(hr) ? DS_OK : hr;
556 /***************************************************************************
557 * DirectSoundCaptureEnumerateA [DSOUND.7]
559 * Enumerate all DirectSound drivers installed in the system.
561 * PARAMS
562 * lpDSEnumCallback [I] Address of callback function.
563 * lpContext [I] Address of user defined context passed to callback function.
565 * RETURNS
566 * Success: DS_OK
567 * Failure: DSERR_INVALIDPARAM
569 HRESULT WINAPI DirectSoundCaptureEnumerateA(
570 LPDSENUMCALLBACKA lpDSEnumCallback,
571 LPVOID lpContext)
573 struct morecontext context;
575 if (lpDSEnumCallback == NULL) {
576 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
577 return DSERR_INVALIDPARAM;
580 context.callA = lpDSEnumCallback;
581 context.data = lpContext;
583 return DirectSoundCaptureEnumerateW(a_to_w_callback, &context);
586 /***************************************************************************
587 * DirectSoundCaptureEnumerateW [DSOUND.8]
589 * Enumerate all DirectSound drivers installed in the system.
591 * PARAMS
592 * lpDSEnumCallback [I] Address of callback function.
593 * lpContext [I] Address of user defined context passed to callback function.
595 * RETURNS
596 * Success: DS_OK
597 * Failure: DSERR_INVALIDPARAM
599 HRESULT WINAPI
600 DirectSoundCaptureEnumerateW(
601 LPDSENUMCALLBACKW lpDSEnumCallback,
602 LPVOID lpContext)
604 HRESULT hr;
606 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext );
608 if (lpDSEnumCallback == NULL) {
609 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
610 return DSERR_INVALIDPARAM;
613 setup_dsound_options();
615 hr = enumerate_mmdevices(eCapture, DSOUND_capture_guids,
616 lpDSEnumCallback, lpContext);
617 return SUCCEEDED(hr) ? DS_OK : hr;
620 /*******************************************************************************
621 * DirectSound ClassFactory
624 typedef HRESULT (*FnCreateInstance)(REFIID riid, LPVOID *ppobj);
626 typedef struct {
627 IClassFactory IClassFactory_iface;
628 REFCLSID rclsid;
629 FnCreateInstance pfnCreateInstance;
630 } IClassFactoryImpl;
632 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
634 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
637 static HRESULT WINAPI
638 DSCF_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppobj)
640 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
641 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
642 if (ppobj == NULL)
643 return E_POINTER;
644 if (IsEqualIID(riid, &IID_IUnknown) ||
645 IsEqualIID(riid, &IID_IClassFactory))
647 *ppobj = iface;
648 IClassFactory_AddRef(iface);
649 return S_OK;
651 *ppobj = NULL;
652 return E_NOINTERFACE;
655 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
657 return 2;
660 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
662 /* static class, won't be freed */
663 return 1;
666 static HRESULT WINAPI DSCF_CreateInstance(
667 LPCLASSFACTORY iface,
668 LPUNKNOWN pOuter,
669 REFIID riid,
670 LPVOID *ppobj)
672 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
673 TRACE("(%p, %p, %s, %p)\n", This, pOuter, debugstr_guid(riid), ppobj);
675 if (pOuter)
676 return CLASS_E_NOAGGREGATION;
678 if (ppobj == NULL) {
679 WARN("invalid parameter\n");
680 return DSERR_INVALIDPARAM;
682 *ppobj = NULL;
683 return This->pfnCreateInstance(riid, ppobj);
686 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
688 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
689 FIXME("(%p, %d) stub!\n", This, dolock);
690 return S_OK;
693 static const IClassFactoryVtbl DSCF_Vtbl = {
694 DSCF_QueryInterface,
695 DSCF_AddRef,
696 DSCF_Release,
697 DSCF_CreateInstance,
698 DSCF_LockServer
701 static IClassFactoryImpl DSOUND_CF[] = {
702 { { &DSCF_Vtbl }, &CLSID_DirectSound, DSOUND_Create },
703 { { &DSCF_Vtbl }, &CLSID_DirectSound8, DSOUND_Create8 },
704 { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture, DSOUND_CaptureCreate },
705 { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture8, DSOUND_CaptureCreate8 },
706 { { &DSCF_Vtbl }, &CLSID_DirectSoundFullDuplex, DSOUND_FullDuplexCreate },
707 { { &DSCF_Vtbl }, &CLSID_DirectSoundPrivate, IKsPrivatePropertySetImpl_Create },
708 { { NULL }, NULL, NULL }
711 /*******************************************************************************
712 * DllGetClassObject [DSOUND.@]
713 * Retrieves class object from a DLL object
715 * NOTES
716 * Docs say returns STDAPI
718 * PARAMS
719 * rclsid [I] CLSID for the class object
720 * riid [I] Reference to identifier of interface for class object
721 * ppv [O] Address of variable to receive interface pointer for riid
723 * RETURNS
724 * Success: S_OK
725 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
726 * E_UNEXPECTED
728 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
730 int i = 0;
731 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
733 if (ppv == NULL) {
734 WARN("invalid parameter\n");
735 return E_INVALIDARG;
738 *ppv = NULL;
740 if (!IsEqualIID(riid, &IID_IClassFactory) &&
741 !IsEqualIID(riid, &IID_IUnknown)) {
742 WARN("no interface for %s\n", debugstr_guid(riid));
743 return E_NOINTERFACE;
746 while (NULL != DSOUND_CF[i].rclsid) {
747 if (IsEqualGUID(rclsid, DSOUND_CF[i].rclsid)) {
748 DSCF_AddRef(&DSOUND_CF[i].IClassFactory_iface);
749 *ppv = &DSOUND_CF[i];
750 return S_OK;
752 i++;
755 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid),
756 debugstr_guid(riid), ppv);
757 return CLASS_E_CLASSNOTAVAILABLE;
761 #define INIT_GUID(guid, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
762 guid.Data1 = l; guid.Data2 = w1; guid.Data3 = w2; \
763 guid.Data4[0] = b1; guid.Data4[1] = b2; guid.Data4[2] = b3; \
764 guid.Data4[3] = b4; guid.Data4[4] = b5; guid.Data4[5] = b6; \
765 guid.Data4[6] = b7; guid.Data4[7] = b8;
767 /***********************************************************************
768 * DllMain (DSOUND.init)
770 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
772 TRACE("(%p %ld %p)\n", hInstDLL, fdwReason, lpvReserved);
774 switch (fdwReason) {
775 case DLL_PROCESS_ATTACH:
776 DisableThreadLibraryCalls(hInstDLL);
777 /* Increase refcount on dsound by 1 */
778 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)hInstDLL, &hInstDLL);
779 break;
780 case DLL_PROCESS_DETACH:
781 if (lpvReserved) break;
782 DeleteCriticalSection(&DSOUND_renderers_lock);
783 break;
785 return TRUE;