wine.inf: We should not override existing associations.
[wine/hacks.git] / dlls / dsound / dsound_main.c
blob593235dec764751ca544fdf90027918680b6d7f3
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
22 * Most thread locking is complete. There may be a few race
23 * conditions still lurking.
25 * Tested with a Soundblaster clone, a Gravis UltraSound Classic,
26 * and a Turtle Beach Tropez+.
28 * TODO:
29 * Implement SetCooperativeLevel properly (need to address focus issues)
30 * Implement DirectSound3DBuffers (stubs in place)
31 * Use hardware 3D support if available
32 * Add critical section locking inside Release and AddRef methods
33 * Handle static buffers - put those in hardware, non-static not in hardware
34 * Hardware DuplicateSoundBuffer
35 * Proper volume calculation, and setting volume in HEL primary buffer
36 * Optimize WINMM and negotiate fragment size, decrease DS_HEL_MARGIN
39 #include <stdarg.h>
41 #define COBJMACROS
42 #define NONAMELESSSTRUCT
43 #define NONAMELESSUNION
44 #include "windef.h"
45 #include "winbase.h"
46 #include "winuser.h"
47 #include "winnls.h"
48 #include "winreg.h"
49 #include "mmsystem.h"
50 #include "winternl.h"
51 #include "mmddk.h"
52 #include "wine/debug.h"
53 #include "dsound.h"
54 #include "dsdriver.h"
55 #include "dsound_private.h"
56 #include "dsconf.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
60 /* these are eligible for tuning... they must be high on slow machines... */
61 /* some stuff may get more responsive with lower values though... */
62 #define DS_EMULDRIVER 0 /* some games (Quake 2, UT) refuse to accept
63 emulated dsound devices. set to 0 ! */
64 #define DS_HEL_MARGIN 5 /* HEL only: number of waveOut fragments ahead to mix in new buffers
65 * (keep this close or equal to DS_HEL_QUEUE for best results) */
66 #define DS_HEL_QUEUE 5 /* HEL only: number of waveOut fragments ahead to queue to driver
67 * (this will affect HEL sound reliability and latency) */
69 #define DS_SND_QUEUE_MAX 28 /* max number of fragments to prebuffer */
70 #define DS_SND_QUEUE_MIN 12 /* min number of fragments to prebuffer */
72 DirectSoundDevice* DSOUND_renderer[MAXWAVEDRIVERS];
73 GUID DSOUND_renderer_guids[MAXWAVEDRIVERS];
74 GUID DSOUND_capture_guids[MAXWAVEDRIVERS];
76 HRESULT mmErr(UINT err)
78 switch(err) {
79 case MMSYSERR_NOERROR:
80 return DS_OK;
81 case MMSYSERR_ALLOCATED:
82 return DSERR_ALLOCATED;
83 case MMSYSERR_ERROR:
84 case MMSYSERR_INVALHANDLE:
85 case WAVERR_STILLPLAYING:
86 return DSERR_GENERIC; /* FIXME */
87 case MMSYSERR_NODRIVER:
88 return DSERR_NODRIVER;
89 case MMSYSERR_NOMEM:
90 return DSERR_OUTOFMEMORY;
91 case MMSYSERR_INVALPARAM:
92 case WAVERR_BADFORMAT:
93 case WAVERR_UNPREPARED:
94 return DSERR_INVALIDPARAM;
95 case MMSYSERR_NOTSUPPORTED:
96 return DSERR_UNSUPPORTED;
97 default:
98 FIXME("Unknown MMSYS error %d\n",err);
99 return DSERR_GENERIC;
103 int ds_emuldriver = DS_EMULDRIVER;
104 int ds_hel_margin = DS_HEL_MARGIN;
105 int ds_hel_queue = DS_HEL_QUEUE;
106 int ds_snd_queue_max = DS_SND_QUEUE_MAX;
107 int ds_snd_queue_min = DS_SND_QUEUE_MIN;
108 int ds_hw_accel = DS_HW_ACCEL_FULL;
109 int ds_default_playback = 0;
110 int ds_default_capture = 0;
111 int ds_default_sample_rate = 22050;
112 int ds_default_bits_per_sample = 8;
115 * Get a config key from either the app-specific or the default config
118 inline static DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
119 char *buffer, DWORD size )
121 if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
122 if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
123 return ERROR_FILE_NOT_FOUND;
128 * Setup the dsound options.
131 void setup_dsound_options(void)
133 char buffer[MAX_PATH+16];
134 HKEY hkey, appkey = 0;
135 DWORD len;
137 buffer[MAX_PATH]='\0';
139 /* @@ Wine registry key: HKCU\Software\Wine\DirectSound */
140 if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\DirectSound", &hkey )) hkey = 0;
142 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
143 if (len && len < MAX_PATH)
145 HKEY tmpkey;
146 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectSound */
147 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
149 char *p, *appname = buffer;
150 if ((p = strrchr( appname, '/' ))) appname = p + 1;
151 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
152 strcat( appname, "\\DirectSound" );
153 TRACE("appname = [%s]\n", appname);
154 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
155 RegCloseKey( tmpkey );
159 /* get options */
161 if (!get_config_key( hkey, appkey, "EmulDriver", buffer, MAX_PATH ))
162 ds_emuldriver = strcmp(buffer, "N");
164 if (!get_config_key( hkey, appkey, "HELmargin", buffer, MAX_PATH ))
165 ds_hel_margin = atoi(buffer);
167 if (!get_config_key( hkey, appkey, "HELqueue", buffer, MAX_PATH ))
168 ds_hel_queue = atoi(buffer);
170 if (!get_config_key( hkey, appkey, "SndQueueMax", buffer, MAX_PATH ))
171 ds_snd_queue_max = atoi(buffer);
173 if (!get_config_key( hkey, appkey, "SndQueueMin", buffer, MAX_PATH ))
174 ds_snd_queue_min = atoi(buffer);
176 if (!get_config_key( hkey, appkey, "HardwareAcceleration", buffer, MAX_PATH )) {
177 if (strcmp(buffer, "Full") == 0)
178 ds_hw_accel = DS_HW_ACCEL_FULL;
179 else if (strcmp(buffer, "Standard") == 0)
180 ds_hw_accel = DS_HW_ACCEL_STANDARD;
181 else if (strcmp(buffer, "Basic") == 0)
182 ds_hw_accel = DS_HW_ACCEL_BASIC;
183 else if (strcmp(buffer, "Emulation") == 0)
184 ds_hw_accel = DS_HW_ACCEL_EMULATION;
187 if (!get_config_key( hkey, appkey, "DefaultPlayback", buffer, MAX_PATH ))
188 ds_default_playback = atoi(buffer);
190 if (!get_config_key( hkey, appkey, "DefaultCapture", buffer, MAX_PATH ))
191 ds_default_capture = atoi(buffer);
193 if (!get_config_key( hkey, appkey, "DefaultSampleRate", buffer, MAX_PATH ))
194 ds_default_sample_rate = atoi(buffer);
196 if (!get_config_key( hkey, appkey, "DefaultBitsPerSample", buffer, MAX_PATH ))
197 ds_default_bits_per_sample = atoi(buffer);
199 if (appkey) RegCloseKey( appkey );
200 if (hkey) RegCloseKey( hkey );
202 if (ds_emuldriver != DS_EMULDRIVER )
203 WARN("ds_emuldriver = %d (default=%d)\n",ds_emuldriver, DS_EMULDRIVER);
204 if (ds_hel_margin != DS_HEL_MARGIN )
205 WARN("ds_hel_margin = %d (default=%d)\n",ds_hel_margin, DS_HEL_MARGIN );
206 if (ds_hel_queue != DS_HEL_QUEUE )
207 WARN("ds_hel_queue = %d (default=%d)\n",ds_hel_queue, DS_HEL_QUEUE );
208 if (ds_snd_queue_max != DS_SND_QUEUE_MAX)
209 WARN("ds_snd_queue_max = %d (default=%d)\n",ds_snd_queue_max ,DS_SND_QUEUE_MAX);
210 if (ds_snd_queue_min != DS_SND_QUEUE_MIN)
211 WARN("ds_snd_queue_min = %d (default=%d)\n",ds_snd_queue_min ,DS_SND_QUEUE_MIN);
212 if (ds_hw_accel != DS_HW_ACCEL_FULL)
213 WARN("ds_hw_accel = %s (default=Full)\n",
214 ds_hw_accel==DS_HW_ACCEL_FULL ? "Full" :
215 ds_hw_accel==DS_HW_ACCEL_STANDARD ? "Standard" :
216 ds_hw_accel==DS_HW_ACCEL_BASIC ? "Basic" :
217 ds_hw_accel==DS_HW_ACCEL_EMULATION ? "Emulation" :
218 "Unknown");
219 if (ds_default_playback != 0)
220 WARN("ds_default_playback = %d (default=0)\n",ds_default_playback);
221 if (ds_default_capture != 0)
222 WARN("ds_default_capture = %d (default=0)\n",ds_default_playback);
223 if (ds_default_sample_rate != 22050)
224 WARN("ds_default_sample_rate = %d (default=22050)\n",ds_default_sample_rate);
225 if (ds_default_bits_per_sample != 8)
226 WARN("ds_default_bits_per_sample = %d (default=8)\n",ds_default_bits_per_sample);
229 static const char * get_device_id(LPCGUID pGuid)
231 if (IsEqualGUID(&DSDEVID_DefaultPlayback, pGuid))
232 return "DSDEVID_DefaultPlayback";
233 else if (IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuid))
234 return "DSDEVID_DefaultVoicePlayback";
235 else if (IsEqualGUID(&DSDEVID_DefaultCapture, pGuid))
236 return "DSDEVID_DefaultCapture";
237 else if (IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuid))
238 return "DSDEVID_DefaultVoiceCapture";
239 return debugstr_guid(pGuid);
242 /***************************************************************************
243 * GetDeviceID [DSOUND.9]
245 * Retrieves unique identifier of default device specified
247 * PARAMS
248 * pGuidSrc [I] Address of device GUID.
249 * pGuidDest [O] Address to receive unique device GUID.
251 * RETURNS
252 * Success: DS_OK
253 * Failure: DSERR_INVALIDPARAM
255 * NOTES
256 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
257 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
258 * DSDEVID_DefaultVoiceCapture.
259 * Returns pGuidSrc if pGuidSrc is a valid device or the device
260 * GUID for the specified constants.
262 HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest)
264 TRACE("(%s,%p)\n", get_device_id(pGuidSrc),pGuidDest);
266 if ( pGuidSrc == NULL) {
267 WARN("invalid parameter: pGuidSrc == NULL\n");
268 return DSERR_INVALIDPARAM;
271 if ( pGuidDest == NULL ) {
272 WARN("invalid parameter: pGuidDest == NULL\n");
273 return DSERR_INVALIDPARAM;
276 if ( IsEqualGUID( &DSDEVID_DefaultPlayback, pGuidSrc ) ||
277 IsEqualGUID( &DSDEVID_DefaultVoicePlayback, pGuidSrc ) ) {
278 CopyMemory(pGuidDest, &DSOUND_renderer_guids[ds_default_playback], sizeof(GUID));
279 TRACE("returns %s\n", get_device_id(pGuidDest));
280 return DS_OK;
283 if ( IsEqualGUID( &DSDEVID_DefaultCapture, pGuidSrc ) ||
284 IsEqualGUID( &DSDEVID_DefaultVoiceCapture, pGuidSrc ) ) {
285 CopyMemory(pGuidDest, &DSOUND_capture_guids[ds_default_capture], sizeof(GUID));
286 TRACE("returns %s\n", get_device_id(pGuidDest));
287 return DS_OK;
290 CopyMemory(pGuidDest, pGuidSrc, sizeof(GUID));
291 TRACE("returns %s\n", get_device_id(pGuidDest));
293 return DS_OK;
297 /***************************************************************************
298 * DirectSoundEnumerateA [DSOUND.2]
300 * Enumerate all DirectSound drivers installed in the system
302 * PARAMS
303 * lpDSEnumCallback [I] Address of callback function.
304 * lpContext [I] Address of user defined context passed to callback function.
306 * RETURNS
307 * Success: DS_OK
308 * Failure: DSERR_INVALIDPARAM
310 HRESULT WINAPI DirectSoundEnumerateA(
311 LPDSENUMCALLBACKA lpDSEnumCallback,
312 LPVOID lpContext)
314 unsigned devs, wod;
315 DSDRIVERDESC desc;
316 GUID guid;
317 int err;
319 TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
320 lpDSEnumCallback, lpContext);
322 if (lpDSEnumCallback == NULL) {
323 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
324 return DSERR_INVALIDPARAM;
327 devs = waveOutGetNumDevs();
328 if (devs > 0) {
329 if (GetDeviceID(&DSDEVID_DefaultPlayback, &guid) == DS_OK) {
330 for (wod = 0; wod < devs; ++wod) {
331 if (IsEqualGUID( &guid, &DSOUND_renderer_guids[wod]) ) {
332 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
333 if (err == DS_OK) {
334 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
335 "Primary Sound Driver",desc.szDrvname,lpContext);
336 if (lpDSEnumCallback(NULL, "Primary Sound Driver", desc.szDrvname, lpContext) == FALSE)
337 return DS_OK;
344 for (wod = 0; wod < devs; ++wod) {
345 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
346 if (err == DS_OK) {
347 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
348 debugstr_guid(&DSOUND_renderer_guids[wod]),desc.szDesc,desc.szDrvname,lpContext);
349 if (lpDSEnumCallback(&DSOUND_renderer_guids[wod], desc.szDesc, desc.szDrvname, lpContext) == FALSE)
350 return DS_OK;
353 return DS_OK;
356 /***************************************************************************
357 * DirectSoundEnumerateW [DSOUND.3]
359 * Enumerate all DirectSound drivers installed in the system
361 * PARAMS
362 * lpDSEnumCallback [I] Address of callback function.
363 * lpContext [I] Address of user defined context passed to callback function.
365 * RETURNS
366 * Success: DS_OK
367 * Failure: DSERR_INVALIDPARAM
369 HRESULT WINAPI DirectSoundEnumerateW(
370 LPDSENUMCALLBACKW lpDSEnumCallback,
371 LPVOID lpContext )
373 unsigned devs, wod;
374 DSDRIVERDESC desc;
375 GUID guid;
376 int err;
377 WCHAR wDesc[MAXPNAMELEN];
378 WCHAR wName[MAXPNAMELEN];
380 TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
381 lpDSEnumCallback, lpContext);
383 if (lpDSEnumCallback == NULL) {
384 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
385 return DSERR_INVALIDPARAM;
388 devs = waveOutGetNumDevs();
389 if (devs > 0) {
390 if (GetDeviceID(&DSDEVID_DefaultPlayback, &guid) == DS_OK) {
391 for (wod = 0; wod < devs; ++wod) {
392 if (IsEqualGUID( &guid, &DSOUND_renderer_guids[wod] ) ) {
393 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
394 if (err == DS_OK) {
395 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
396 "Primary Sound Driver",desc.szDrvname,lpContext);
397 MultiByteToWideChar( CP_ACP, 0, "Primary Sound Driver", -1,
398 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
399 MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1,
400 wName, sizeof(wName)/sizeof(WCHAR) );
401 if (lpDSEnumCallback(NULL, wDesc, wName, lpContext) == FALSE)
402 return DS_OK;
409 for (wod = 0; wod < devs; ++wod) {
410 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
411 if (err == DS_OK) {
412 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
413 debugstr_guid(&DSOUND_renderer_guids[wod]),desc.szDesc,desc.szDrvname,lpContext);
414 MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1,
415 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
416 MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1,
417 wName, sizeof(wName)/sizeof(WCHAR) );
418 if (lpDSEnumCallback(&DSOUND_renderer_guids[wod], wDesc, wName, lpContext) == FALSE)
419 return DS_OK;
422 return DS_OK;
425 /*******************************************************************************
426 * DirectSound ClassFactory
429 static HRESULT WINAPI
430 DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
431 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
433 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
434 return E_NOINTERFACE;
437 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
439 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
440 ULONG ref = InterlockedIncrement(&(This->ref));
441 TRACE("(%p) ref was %ld\n", This, ref - 1);
442 return ref;
445 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
447 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
448 ULONG ref = InterlockedDecrement(&(This->ref));
449 TRACE("(%p) ref was %ld\n", This, ref + 1);
450 /* static class, won't be freed */
451 return ref;
454 static HRESULT WINAPI DSCF_CreateInstance(
455 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
457 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
458 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
460 if (pOuter)
461 return CLASS_E_NOAGGREGATION;
463 if (ppobj == NULL) {
464 WARN("invalid parameter\n");
465 return DSERR_INVALIDPARAM;
468 *ppobj = NULL;
470 if ( IsEqualIID( &IID_IDirectSound, riid ) )
471 return DSOUND_Create((LPDIRECTSOUND*)ppobj,pOuter);
473 if ( IsEqualIID( &IID_IDirectSound8, riid ) )
474 return DSOUND_Create8((LPDIRECTSOUND8*)ppobj,pOuter);
476 WARN("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
477 return E_NOINTERFACE;
480 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
481 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
482 FIXME("(%p)->(%d),stub!\n",This,dolock);
483 return S_OK;
486 static const IClassFactoryVtbl DSCF_Vtbl = {
487 DSCF_QueryInterface,
488 DSCF_AddRef,
489 DSCF_Release,
490 DSCF_CreateInstance,
491 DSCF_LockServer
494 static IClassFactoryImpl DSOUND_CF = { &DSCF_Vtbl, 1 };
496 /*******************************************************************************
497 * DirectSoundPrivate ClassFactory
500 static HRESULT WINAPI
501 DSPCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
502 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
504 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
505 return E_NOINTERFACE;
508 static ULONG WINAPI DSPCF_AddRef(LPCLASSFACTORY iface)
510 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
511 ULONG ref = InterlockedIncrement(&(This->ref));
512 TRACE("(%p) ref was %ld\n", This, ref - 1);
513 return ref;
516 static ULONG WINAPI DSPCF_Release(LPCLASSFACTORY iface)
518 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
519 ULONG ref = InterlockedDecrement(&(This->ref));
520 TRACE("(%p) ref was %ld\n", This, ref + 1);
521 /* static class, won't be freed */
522 return ref;
525 static HRESULT WINAPI
526 DSPCF_CreateInstance(
527 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
529 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
530 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
532 if (ppobj == NULL) {
533 WARN("invalid parameter\n");
534 return DSERR_INVALIDPARAM;
537 *ppobj = NULL;
539 if ( IsEqualGUID( &IID_IKsPropertySet, riid ) ) {
540 return IKsPrivatePropertySetImpl_Create((IKsPrivatePropertySetImpl**)ppobj);
543 WARN("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
544 return E_NOINTERFACE;
547 static HRESULT WINAPI
548 DSPCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
549 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
550 FIXME("(%p)->(%d),stub!\n",This,dolock);
551 return S_OK;
554 static const IClassFactoryVtbl DSPCF_Vtbl = {
555 DSPCF_QueryInterface,
556 DSPCF_AddRef,
557 DSPCF_Release,
558 DSPCF_CreateInstance,
559 DSPCF_LockServer
562 static IClassFactoryImpl DSOUND_PRIVATE_CF = { &DSPCF_Vtbl, 1 };
564 /*******************************************************************************
565 * DllGetClassObject [DSOUND.@]
566 * Retrieves class object from a DLL object
568 * NOTES
569 * Docs say returns STDAPI
571 * PARAMS
572 * rclsid [I] CLSID for the class object
573 * riid [I] Reference to identifier of interface for class object
574 * ppv [O] Address of variable to receive interface pointer for riid
576 * RETURNS
577 * Success: S_OK
578 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
579 * E_UNEXPECTED
581 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
583 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
585 if (ppv == NULL) {
586 WARN("invalid parameter\n");
587 return E_INVALIDARG;
590 *ppv = NULL;
592 if ( IsEqualCLSID( &CLSID_DirectSound, rclsid ) ||
593 IsEqualCLSID( &CLSID_DirectSound8, rclsid ) ) {
594 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
595 *ppv = (LPVOID)&DSOUND_CF;
596 IClassFactory_AddRef((IClassFactory*)*ppv);
597 return S_OK;
599 WARN("(%s,%s,%p): no interface found.\n",
600 debugstr_guid(rclsid), debugstr_guid(riid), ppv);
601 return S_FALSE;
604 if ( IsEqualCLSID( &CLSID_DirectSoundCapture, rclsid ) ||
605 IsEqualCLSID( &CLSID_DirectSoundCapture8, rclsid ) ) {
606 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
607 *ppv = (LPVOID)&DSOUND_CAPTURE_CF;
608 IClassFactory_AddRef((IClassFactory*)*ppv);
609 return S_OK;
611 WARN("(%s,%s,%p): no interface found.\n",
612 debugstr_guid(rclsid), debugstr_guid(riid), ppv);
613 return S_FALSE;
616 if ( IsEqualCLSID( &CLSID_DirectSoundFullDuplex, rclsid ) ) {
617 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
618 *ppv = (LPVOID)&DSOUND_FULLDUPLEX_CF;
619 IClassFactory_AddRef((IClassFactory*)*ppv);
620 return S_OK;
622 WARN("(%s,%s,%p): no interface found.\n",
623 debugstr_guid(rclsid), debugstr_guid(riid), ppv);
624 return S_FALSE;
627 if ( IsEqualCLSID( &CLSID_DirectSoundPrivate, rclsid ) ) {
628 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
629 *ppv = (LPVOID)&DSOUND_PRIVATE_CF;
630 IClassFactory_AddRef((IClassFactory*)*ppv);
631 return S_OK;
633 WARN("(%s,%s,%p): no interface found.\n",
634 debugstr_guid(rclsid), debugstr_guid(riid), ppv);
635 return S_FALSE;
638 WARN("(%s,%s,%p): no class found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
639 return CLASS_E_CLASSNOTAVAILABLE;
643 /*******************************************************************************
644 * DllCanUnloadNow [DSOUND.4]
645 * Determines whether the DLL is in use.
647 * RETURNS
648 * Success: S_OK
649 * Failure: S_FALSE
651 HRESULT WINAPI DllCanUnloadNow(void)
653 FIXME("(void): stub\n");
654 return S_FALSE;
657 #define INIT_GUID(guid, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
658 guid.Data1 = l; guid.Data2 = w1; guid.Data3 = w2; \
659 guid.Data4[0] = b1; guid.Data4[1] = b2; guid.Data4[2] = b3; \
660 guid.Data4[3] = b4; guid.Data4[4] = b5; guid.Data4[5] = b6; \
661 guid.Data4[6] = b7; guid.Data4[7] = b8;
663 /***********************************************************************
664 * DllMain (DSOUND.init)
666 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
668 int i;
669 TRACE("(%p %ld %p)\n", hInstDLL, fdwReason, lpvReserved);
671 switch (fdwReason) {
672 case DLL_PROCESS_ATTACH:
673 TRACE("DLL_PROCESS_ATTACH\n");
674 for (i = 0; i < MAXWAVEDRIVERS; i++) {
675 DSOUND_renderer[i] = NULL;
676 DSOUND_capture[i] = NULL;
677 INIT_GUID(DSOUND_renderer_guids[i], 0xbd6dd71a, 0x3deb, 0x11d1, 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 + i);
678 INIT_GUID(DSOUND_capture_guids[i], 0xbd6dd71b, 0x3deb, 0x11d1, 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 + i);
680 break;
681 case DLL_PROCESS_DETACH:
682 TRACE("DLL_PROCESS_DETACH\n");
683 break;
684 case DLL_THREAD_ATTACH:
685 TRACE("DLL_THREAD_ATTACH\n");
686 break;
687 case DLL_THREAD_DETACH:
688 TRACE("DLL_THREAD_DETACH\n");
689 break;
690 default:
691 TRACE("UNKNOWN REASON\n");
692 break;
694 return TRUE;