comctl32/monthcal: Fix MCM_GETMONTHRANGE with regard to multiple calendars and parame...
[wine/multimedia.git] / dlls / dsound / dsound_main.c
blob81dd7dd91b721816a6727fabe2578cfeed9998e7
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 "initguid.h"
54 #include "ksmedia.h"
55 #include "dsdriver.h"
57 #include "dsound_private.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
61 DirectSoundDevice* DSOUND_renderer[MAXWAVEDRIVERS];
62 GUID DSOUND_renderer_guids[MAXWAVEDRIVERS];
63 GUID DSOUND_capture_guids[MAXWAVEDRIVERS];
65 HRESULT mmErr(UINT err)
67 switch(err) {
68 case MMSYSERR_NOERROR:
69 return DS_OK;
70 case MMSYSERR_ALLOCATED:
71 return DSERR_ALLOCATED;
72 case MMSYSERR_ERROR:
73 case MMSYSERR_INVALHANDLE:
74 case WAVERR_STILLPLAYING:
75 return DSERR_GENERIC; /* FIXME */
76 case MMSYSERR_NODRIVER:
77 return DSERR_NODRIVER;
78 case MMSYSERR_NOMEM:
79 return DSERR_OUTOFMEMORY;
80 case MMSYSERR_INVALPARAM:
81 case WAVERR_BADFORMAT:
82 case WAVERR_UNPREPARED:
83 return DSERR_INVALIDPARAM;
84 case MMSYSERR_NOTSUPPORTED:
85 return DSERR_UNSUPPORTED;
86 default:
87 FIXME("Unknown MMSYS error %d\n",err);
88 return DSERR_GENERIC;
92 /* All default settings, you most likely don't want to touch these, see wiki on UsefulRegistryKeys */
93 int ds_emuldriver = 0;
94 int ds_hel_buflen = 32768 * 2;
95 int ds_snd_queue_max = 10;
96 int ds_snd_queue_min = 6;
97 int ds_snd_shadow_maxsize = 2;
98 int ds_hw_accel = DS_HW_ACCEL_FULL;
99 int ds_default_sample_rate = 44100;
100 int ds_default_bits_per_sample = 16;
101 static int ds_default_playback;
102 static int ds_default_capture;
103 static HINSTANCE instance;
106 * Get a config key from either the app-specific or the default config
109 static inline DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
110 char *buffer, DWORD size )
112 if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
113 if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
114 return ERROR_FILE_NOT_FOUND;
119 * Setup the dsound options.
122 void setup_dsound_options(void)
124 char buffer[MAX_PATH+16];
125 HKEY hkey, appkey = 0;
126 DWORD len;
128 buffer[MAX_PATH]='\0';
130 /* @@ Wine registry key: HKCU\Software\Wine\DirectSound */
131 if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\DirectSound", &hkey )) hkey = 0;
133 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
134 if (len && len < MAX_PATH)
136 HKEY tmpkey;
137 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectSound */
138 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
140 char *p, *appname = buffer;
141 if ((p = strrchr( appname, '/' ))) appname = p + 1;
142 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
143 strcat( appname, "\\DirectSound" );
144 TRACE("appname = [%s]\n", appname);
145 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
146 RegCloseKey( tmpkey );
150 /* get options */
152 if (!get_config_key( hkey, appkey, "EmulDriver", buffer, MAX_PATH ))
153 ds_emuldriver = strcmp(buffer, "N");
155 if (!get_config_key( hkey, appkey, "HelBuflen", buffer, MAX_PATH ))
156 ds_hel_buflen = atoi(buffer);
158 if (!get_config_key( hkey, appkey, "SndQueueMax", buffer, MAX_PATH ))
159 ds_snd_queue_max = atoi(buffer);
161 if (!get_config_key( hkey, appkey, "SndQueueMin", buffer, MAX_PATH ))
162 ds_snd_queue_min = atoi(buffer);
164 if (!get_config_key( hkey, appkey, "HardwareAcceleration", buffer, MAX_PATH )) {
165 if (strcmp(buffer, "Full") == 0)
166 ds_hw_accel = DS_HW_ACCEL_FULL;
167 else if (strcmp(buffer, "Standard") == 0)
168 ds_hw_accel = DS_HW_ACCEL_STANDARD;
169 else if (strcmp(buffer, "Basic") == 0)
170 ds_hw_accel = DS_HW_ACCEL_BASIC;
171 else if (strcmp(buffer, "Emulation") == 0)
172 ds_hw_accel = DS_HW_ACCEL_EMULATION;
175 if (!get_config_key( hkey, appkey, "DefaultPlayback", buffer, MAX_PATH ))
176 ds_default_playback = atoi(buffer);
178 if (!get_config_key( hkey, appkey, "MaxShadowSize", buffer, MAX_PATH ))
179 ds_snd_shadow_maxsize = atoi(buffer);
181 if (!get_config_key( hkey, appkey, "DefaultCapture", buffer, MAX_PATH ))
182 ds_default_capture = atoi(buffer);
184 if (!get_config_key( hkey, appkey, "DefaultSampleRate", buffer, MAX_PATH ))
185 ds_default_sample_rate = atoi(buffer);
187 if (!get_config_key( hkey, appkey, "DefaultBitsPerSample", buffer, MAX_PATH ))
188 ds_default_bits_per_sample = atoi(buffer);
190 if (appkey) RegCloseKey( appkey );
191 if (hkey) RegCloseKey( hkey );
193 TRACE("ds_emuldriver = %d\n", ds_emuldriver);
194 TRACE("ds_hel_buflen = %d\n", ds_hel_buflen);
195 TRACE("ds_snd_queue_max = %d\n", ds_snd_queue_max);
196 TRACE("ds_snd_queue_min = %d\n", ds_snd_queue_min);
197 TRACE("ds_hw_accel = %s\n",
198 ds_hw_accel==DS_HW_ACCEL_FULL ? "Full" :
199 ds_hw_accel==DS_HW_ACCEL_STANDARD ? "Standard" :
200 ds_hw_accel==DS_HW_ACCEL_BASIC ? "Basic" :
201 ds_hw_accel==DS_HW_ACCEL_EMULATION ? "Emulation" :
202 "Unknown");
203 TRACE("ds_default_playback = %d\n", ds_default_playback);
204 TRACE("ds_default_capture = %d\n", ds_default_playback);
205 TRACE("ds_default_sample_rate = %d\n", ds_default_sample_rate);
206 TRACE("ds_default_bits_per_sample = %d\n", ds_default_bits_per_sample);
207 TRACE("ds_snd_shadow_maxsize = %d\n", ds_snd_shadow_maxsize);
210 static const char * get_device_id(LPCGUID pGuid)
212 if (IsEqualGUID(&DSDEVID_DefaultPlayback, pGuid))
213 return "DSDEVID_DefaultPlayback";
214 else if (IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuid))
215 return "DSDEVID_DefaultVoicePlayback";
216 else if (IsEqualGUID(&DSDEVID_DefaultCapture, pGuid))
217 return "DSDEVID_DefaultCapture";
218 else if (IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuid))
219 return "DSDEVID_DefaultVoiceCapture";
220 return debugstr_guid(pGuid);
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 TRACE("(%s,%p)\n", get_device_id(pGuidSrc),pGuidDest);
247 if ( pGuidSrc == NULL) {
248 WARN("invalid parameter: pGuidSrc == NULL\n");
249 return DSERR_INVALIDPARAM;
252 if ( pGuidDest == NULL ) {
253 WARN("invalid parameter: pGuidDest == NULL\n");
254 return DSERR_INVALIDPARAM;
257 if ( IsEqualGUID( &DSDEVID_DefaultPlayback, pGuidSrc ) ||
258 IsEqualGUID( &DSDEVID_DefaultVoicePlayback, pGuidSrc ) ) {
259 *pGuidDest = DSOUND_renderer_guids[ds_default_playback];
260 TRACE("returns %s\n", get_device_id(pGuidDest));
261 return DS_OK;
264 if ( IsEqualGUID( &DSDEVID_DefaultCapture, pGuidSrc ) ||
265 IsEqualGUID( &DSDEVID_DefaultVoiceCapture, pGuidSrc ) ) {
266 *pGuidDest = DSOUND_capture_guids[ds_default_capture];
267 TRACE("returns %s\n", get_device_id(pGuidDest));
268 return DS_OK;
271 *pGuidDest = *pGuidSrc;
272 TRACE("returns %s\n", get_device_id(pGuidDest));
274 return DS_OK;
277 struct morecontext
279 LPDSENUMCALLBACKA callA;
280 LPVOID data;
283 static BOOL CALLBACK a_to_w_callback(LPGUID guid, LPCWSTR descW, LPCWSTR modW, LPVOID data)
285 struct morecontext *context = data;
286 char descA[MAXPNAMELEN], modA[MAXPNAMELEN];
288 WideCharToMultiByte(CP_ACP, 0, descW, -1, descA, sizeof(descA), NULL, NULL);
289 WideCharToMultiByte(CP_ACP, 0, modW, -1, modA, sizeof(modA), NULL, NULL);
291 return context->callA(guid, descA, modA, context->data);
294 /***************************************************************************
295 * DirectSoundEnumerateA [DSOUND.2]
297 * Enumerate all DirectSound drivers installed in the system
299 * PARAMS
300 * lpDSEnumCallback [I] Address of callback function.
301 * lpContext [I] Address of user defined context passed to callback function.
303 * RETURNS
304 * Success: DS_OK
305 * Failure: DSERR_INVALIDPARAM
307 HRESULT WINAPI DirectSoundEnumerateA(
308 LPDSENUMCALLBACKA lpDSEnumCallback,
309 LPVOID lpContext)
311 struct morecontext context;
313 if (lpDSEnumCallback == NULL) {
314 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
315 return DSERR_INVALIDPARAM;
318 context.callA = lpDSEnumCallback;
319 context.data = lpContext;
321 return DirectSoundEnumerateW(a_to_w_callback, &context);
324 /***************************************************************************
325 * DirectSoundEnumerateW [DSOUND.3]
327 * Enumerate all DirectSound drivers installed in the system
329 * PARAMS
330 * lpDSEnumCallback [I] Address of callback function.
331 * lpContext [I] Address of user defined context passed to callback function.
333 * RETURNS
334 * Success: DS_OK
335 * Failure: DSERR_INVALIDPARAM
337 HRESULT WINAPI DirectSoundEnumerateW(
338 LPDSENUMCALLBACKW lpDSEnumCallback,
339 LPVOID lpContext )
341 unsigned devs, wod;
342 DSDRIVERDESC desc;
343 GUID guid;
344 int err;
345 WCHAR wDesc[MAXPNAMELEN];
346 WCHAR wName[MAXPNAMELEN];
348 TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
349 lpDSEnumCallback, lpContext);
351 if (lpDSEnumCallback == NULL) {
352 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
353 return DSERR_INVALIDPARAM;
356 setup_dsound_options();
358 devs = waveOutGetNumDevs();
359 if (devs > 0) {
360 if (GetDeviceID(&DSDEVID_DefaultPlayback, &guid) == DS_OK) {
361 static const WCHAR empty[] = { 0 };
362 for (wod = 0; wod < devs; ++wod) {
363 if (IsEqualGUID( &guid, &DSOUND_renderer_guids[wod] ) ) {
364 err = mmErr(waveOutMessage(UlongToHandle(wod),DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,ds_hw_accel));
365 if (err == DS_OK) {
366 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
367 "Primary Sound Driver",desc.szDrvname,lpContext);
368 MultiByteToWideChar( CP_ACP, 0, "Primary Sound Driver", -1,
369 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
370 if (lpDSEnumCallback(NULL, wDesc, empty, lpContext) == FALSE)
371 return DS_OK;
378 for (wod = 0; wod < devs; ++wod) {
379 err = mmErr(waveOutMessage(UlongToHandle(wod),DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,ds_hw_accel));
380 if (err == DS_OK) {
381 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
382 debugstr_guid(&DSOUND_renderer_guids[wod]),desc.szDesc,desc.szDrvname,lpContext);
383 MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1,
384 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
385 wDesc[(sizeof(wDesc)/sizeof(WCHAR)) - 1] = '\0';
387 MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1,
388 wName, sizeof(wName)/sizeof(WCHAR) );
389 wName[(sizeof(wName)/sizeof(WCHAR)) - 1] = '\0';
391 if (lpDSEnumCallback(&DSOUND_renderer_guids[wod], wDesc, wName, lpContext) == FALSE)
392 return DS_OK;
395 return DS_OK;
398 /***************************************************************************
399 * DirectSoundCaptureEnumerateA [DSOUND.7]
401 * Enumerate all DirectSound drivers installed in the system.
403 * PARAMS
404 * lpDSEnumCallback [I] Address of callback function.
405 * lpContext [I] Address of user defined context passed to callback function.
407 * RETURNS
408 * Success: DS_OK
409 * Failure: DSERR_INVALIDPARAM
411 HRESULT WINAPI DirectSoundCaptureEnumerateA(
412 LPDSENUMCALLBACKA lpDSEnumCallback,
413 LPVOID lpContext)
415 struct morecontext context;
417 if (lpDSEnumCallback == NULL) {
418 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
419 return DSERR_INVALIDPARAM;
422 context.callA = lpDSEnumCallback;
423 context.data = lpContext;
425 return DirectSoundCaptureEnumerateW(a_to_w_callback, &context);
428 /***************************************************************************
429 * DirectSoundCaptureEnumerateW [DSOUND.8]
431 * Enumerate all DirectSound drivers installed in the system.
433 * PARAMS
434 * lpDSEnumCallback [I] Address of callback function.
435 * lpContext [I] Address of user defined context passed to callback function.
437 * RETURNS
438 * Success: DS_OK
439 * Failure: DSERR_INVALIDPARAM
441 HRESULT WINAPI
442 DirectSoundCaptureEnumerateW(
443 LPDSENUMCALLBACKW lpDSEnumCallback,
444 LPVOID lpContext)
446 unsigned devs, wid;
447 DSDRIVERDESC desc;
448 GUID guid;
449 int err;
450 WCHAR wDesc[MAXPNAMELEN];
451 WCHAR wName[MAXPNAMELEN];
453 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext );
455 if (lpDSEnumCallback == NULL) {
456 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
457 return DSERR_INVALIDPARAM;
460 setup_dsound_options();
462 devs = waveInGetNumDevs();
463 if (devs > 0) {
464 if (GetDeviceID(&DSDEVID_DefaultCapture, &guid) == DS_OK) {
465 for (wid = 0; wid < devs; ++wid) {
466 if (IsEqualGUID( &guid, &DSOUND_capture_guids[wid] ) ) {
467 err = mmErr(waveInMessage(UlongToHandle(wid),DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,ds_hw_accel));
468 if (err == DS_OK) {
469 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
470 "Primary Sound Capture Driver",desc.szDrvname,lpContext);
471 MultiByteToWideChar( CP_ACP, 0, "Primary Sound Capture Driver", -1,
472 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
473 MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1,
474 wName, sizeof(wName)/sizeof(WCHAR) );
475 wName[(sizeof(wName)/sizeof(WCHAR)) - 1] = '\0';
477 if (lpDSEnumCallback(NULL, wDesc, wName, lpContext) == FALSE)
478 return DS_OK;
485 for (wid = 0; wid < devs; ++wid) {
486 err = mmErr(waveInMessage(UlongToHandle(wid),DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,ds_hw_accel));
487 if (err == DS_OK) {
488 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
489 debugstr_guid(&DSOUND_capture_guids[wid]),desc.szDesc,desc.szDrvname,lpContext);
490 MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1,
491 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
492 wDesc[(sizeof(wDesc)/sizeof(WCHAR)) - 1] = '\0';
494 MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1,
495 wName, sizeof(wName)/sizeof(WCHAR) );
496 wName[(sizeof(wName)/sizeof(WCHAR)) - 1] = '\0';
498 if (lpDSEnumCallback(&DSOUND_capture_guids[wid], wDesc, wName, lpContext) == FALSE)
499 return DS_OK;
503 return DS_OK;
506 /*******************************************************************************
507 * DirectSound ClassFactory
510 typedef HRESULT (*FnCreateInstance)(REFIID riid, LPVOID *ppobj);
512 typedef struct {
513 IClassFactory IClassFactory_iface;
514 REFCLSID rclsid;
515 FnCreateInstance pfnCreateInstance;
516 } IClassFactoryImpl;
518 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
520 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
523 static HRESULT WINAPI
524 DSCF_QueryInterface(LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj)
526 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
527 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
528 if (ppobj == NULL)
529 return E_POINTER;
530 if (IsEqualIID(riid, &IID_IUnknown) ||
531 IsEqualIID(riid, &IID_IClassFactory))
533 *ppobj = iface;
534 IUnknown_AddRef(iface);
535 return S_OK;
537 *ppobj = NULL;
538 return E_NOINTERFACE;
541 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
543 return 2;
546 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
548 /* static class, won't be freed */
549 return 1;
552 static HRESULT WINAPI DSCF_CreateInstance(
553 LPCLASSFACTORY iface,
554 LPUNKNOWN pOuter,
555 REFIID riid,
556 LPVOID *ppobj)
558 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
559 TRACE("(%p, %p, %s, %p)\n", This, pOuter, debugstr_guid(riid), ppobj);
561 if (pOuter)
562 return CLASS_E_NOAGGREGATION;
564 if (ppobj == NULL) {
565 WARN("invalid parameter\n");
566 return DSERR_INVALIDPARAM;
568 *ppobj = NULL;
569 return This->pfnCreateInstance(riid, ppobj);
572 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
574 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
575 FIXME("(%p, %d) stub!\n", This, dolock);
576 return S_OK;
579 static const IClassFactoryVtbl DSCF_Vtbl = {
580 DSCF_QueryInterface,
581 DSCF_AddRef,
582 DSCF_Release,
583 DSCF_CreateInstance,
584 DSCF_LockServer
587 static IClassFactoryImpl DSOUND_CF[] = {
588 { { &DSCF_Vtbl }, &CLSID_DirectSound, (FnCreateInstance)DSOUND_Create },
589 { { &DSCF_Vtbl }, &CLSID_DirectSound8, (FnCreateInstance)DSOUND_Create8 },
590 { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture, (FnCreateInstance)DSOUND_CaptureCreate },
591 { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture8, (FnCreateInstance)DSOUND_CaptureCreate8 },
592 { { &DSCF_Vtbl }, &CLSID_DirectSoundFullDuplex, (FnCreateInstance)DSOUND_FullDuplexCreate },
593 { { &DSCF_Vtbl }, &CLSID_DirectSoundPrivate, (FnCreateInstance)IKsPrivatePropertySetImpl_Create },
594 { { NULL }, NULL, NULL }
597 /*******************************************************************************
598 * DllGetClassObject [DSOUND.@]
599 * Retrieves class object from a DLL object
601 * NOTES
602 * Docs say returns STDAPI
604 * PARAMS
605 * rclsid [I] CLSID for the class object
606 * riid [I] Reference to identifier of interface for class object
607 * ppv [O] Address of variable to receive interface pointer for riid
609 * RETURNS
610 * Success: S_OK
611 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
612 * E_UNEXPECTED
614 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
616 int i = 0;
617 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
619 if (ppv == NULL) {
620 WARN("invalid parameter\n");
621 return E_INVALIDARG;
624 *ppv = NULL;
626 if (!IsEqualIID(riid, &IID_IClassFactory) &&
627 !IsEqualIID(riid, &IID_IUnknown)) {
628 WARN("no interface for %s\n", debugstr_guid(riid));
629 return E_NOINTERFACE;
632 while (NULL != DSOUND_CF[i].rclsid) {
633 if (IsEqualGUID(rclsid, DSOUND_CF[i].rclsid)) {
634 DSCF_AddRef(&DSOUND_CF[i].IClassFactory_iface);
635 *ppv = &DSOUND_CF[i];
636 return S_OK;
638 i++;
641 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid),
642 debugstr_guid(riid), ppv);
643 return CLASS_E_CLASSNOTAVAILABLE;
647 /*******************************************************************************
648 * DllCanUnloadNow [DSOUND.4]
649 * Determines whether the DLL is in use.
651 * RETURNS
652 * Can unload now: S_OK
653 * Cannot unload now (the DLL is still active): S_FALSE
655 HRESULT WINAPI DllCanUnloadNow(void)
657 return S_FALSE;
660 #define INIT_GUID(guid, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
661 guid.Data1 = l; guid.Data2 = w1; guid.Data3 = w2; \
662 guid.Data4[0] = b1; guid.Data4[1] = b2; guid.Data4[2] = b3; \
663 guid.Data4[3] = b4; guid.Data4[4] = b5; guid.Data4[5] = b6; \
664 guid.Data4[6] = b7; guid.Data4[7] = b8;
666 /***********************************************************************
667 * DllMain (DSOUND.init)
669 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
671 int i;
672 TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpvReserved);
674 switch (fdwReason) {
675 case DLL_PROCESS_ATTACH:
676 TRACE("DLL_PROCESS_ATTACH\n");
677 for (i = 0; i < MAXWAVEDRIVERS; i++) {
678 DSOUND_renderer[i] = NULL;
679 DSOUND_capture[i] = NULL;
680 INIT_GUID(DSOUND_renderer_guids[i], 0xbd6dd71a, 0x3deb, 0x11d1, 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 + i);
681 INIT_GUID(DSOUND_capture_guids[i], 0xbd6dd71b, 0x3deb, 0x11d1, 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 + i);
683 instance = hInstDLL;
684 DisableThreadLibraryCalls(hInstDLL);
685 /* Increase refcount on dsound by 1 */
686 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)hInstDLL, &hInstDLL);
687 break;
688 case DLL_PROCESS_DETACH:
689 TRACE("DLL_PROCESS_DETACH\n");
690 break;
691 default:
692 TRACE("UNKNOWN REASON\n");
693 break;
695 return TRUE;
698 /***********************************************************************
699 * DllRegisterServer (DSOUND.@)
701 HRESULT WINAPI DllRegisterServer(void)
703 return __wine_register_resources( instance );
706 /***********************************************************************
707 * DllUnregisterServer (DSOUND.@)
709 HRESULT WINAPI DllUnregisterServer(void)
711 return __wine_unregister_resources( instance );