Don't prefix the functions DllCanUnloadNow, DllGetClassObject and
[wine/testsucceed.git] / dlls / dsound / dsound_main.c
blob3efb67dd5c0788f75509f5e1372da80b4cf98715
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 "winnls.h"
47 #include "winreg.h"
48 #include "mmsystem.h"
49 #include "winternl.h"
50 #include "mmddk.h"
51 #include "wine/debug.h"
52 #include "dsound.h"
53 #include "dsdriver.h"
54 #include "dsound_private.h"
55 #include "dsconf.h"
57 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
59 /* these are eligible for tuning... they must be high on slow machines... */
60 /* some stuff may get more responsive with lower values though... */
61 #define DS_EMULDRIVER 0 /* some games (Quake 2, UT) refuse to accept
62 emulated dsound devices. set to 0 ! */
63 #define DS_HEL_MARGIN 5 /* HEL only: number of waveOut fragments ahead to mix in new buffers
64 * (keep this close or equal to DS_HEL_QUEUE for best results) */
65 #define DS_HEL_QUEUE 5 /* HEL only: number of waveOut fragments ahead to queue to driver
66 * (this will affect HEL sound reliability and latency) */
68 #define DS_SND_QUEUE_MAX 28 /* max number of fragments to prebuffer */
69 #define DS_SND_QUEUE_MIN 12 /* min number of fragments to prebuffer */
71 DirectSoundDevice* DSOUND_renderer[MAXWAVEDRIVERS];
72 GUID DSOUND_renderer_guids[MAXWAVEDRIVERS];
73 GUID DSOUND_capture_guids[MAXWAVEDRIVERS];
75 HRESULT mmErr(UINT err)
77 switch(err) {
78 case MMSYSERR_NOERROR:
79 return DS_OK;
80 case MMSYSERR_ALLOCATED:
81 return DSERR_ALLOCATED;
82 case MMSYSERR_ERROR:
83 case MMSYSERR_INVALHANDLE:
84 case WAVERR_STILLPLAYING:
85 return DSERR_GENERIC; /* FIXME */
86 case MMSYSERR_NODRIVER:
87 return DSERR_NODRIVER;
88 case MMSYSERR_NOMEM:
89 return DSERR_OUTOFMEMORY;
90 case MMSYSERR_INVALPARAM:
91 case WAVERR_BADFORMAT:
92 case WAVERR_UNPREPARED:
93 return DSERR_INVALIDPARAM;
94 case MMSYSERR_NOTSUPPORTED:
95 return DSERR_UNSUPPORTED;
96 default:
97 FIXME("Unknown MMSYS error %d\n",err);
98 return DSERR_GENERIC;
102 int ds_emuldriver = DS_EMULDRIVER;
103 int ds_hel_margin = DS_HEL_MARGIN;
104 int ds_hel_queue = DS_HEL_QUEUE;
105 int ds_snd_queue_max = DS_SND_QUEUE_MAX;
106 int ds_snd_queue_min = DS_SND_QUEUE_MIN;
107 int ds_hw_accel = DS_HW_ACCEL_FULL;
108 int ds_default_playback = 0;
109 int ds_default_capture = 0;
112 * Get a config key from either the app-specific or the default config
115 inline static DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
116 char *buffer, DWORD size )
118 if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
119 if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
120 return ERROR_FILE_NOT_FOUND;
125 * Setup the dsound options.
128 void setup_dsound_options(void)
130 char buffer[MAX_PATH+16];
131 HKEY hkey, appkey = 0;
132 DWORD len;
134 buffer[MAX_PATH]='\0';
136 /* @@ Wine registry key: HKCU\Software\Wine\DirectSound */
137 if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\DirectSound", &hkey )) hkey = 0;
139 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
140 if (len && len < MAX_PATH)
142 HKEY tmpkey;
143 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectSound */
144 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
146 char *p, *appname = buffer;
147 if ((p = strrchr( appname, '/' ))) appname = p + 1;
148 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
149 strcat( appname, "\\DirectSound" );
150 TRACE("appname = [%s] \n",appname);
151 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
152 RegCloseKey( tmpkey );
156 /* get options */
158 if (!get_config_key( hkey, appkey, "EmulDriver", buffer, MAX_PATH ))
159 ds_emuldriver = strcmp(buffer, "N");
161 if (!get_config_key( hkey, appkey, "HELmargin", buffer, MAX_PATH ))
162 ds_hel_margin = atoi(buffer);
164 if (!get_config_key( hkey, appkey, "HELqueue", buffer, MAX_PATH ))
165 ds_hel_queue = atoi(buffer);
167 if (!get_config_key( hkey, appkey, "SndQueueMax", buffer, MAX_PATH ))
168 ds_snd_queue_max = atoi(buffer);
170 if (!get_config_key( hkey, appkey, "SndQueueMin", buffer, MAX_PATH ))
171 ds_snd_queue_min = atoi(buffer);
173 if (!get_config_key( hkey, appkey, "HardwareAcceleration", buffer, MAX_PATH )) {
174 if (strcmp(buffer, "Full") == 0)
175 ds_hw_accel = DS_HW_ACCEL_FULL;
176 else if (strcmp(buffer, "Standard") == 0)
177 ds_hw_accel = DS_HW_ACCEL_STANDARD;
178 else if (strcmp(buffer, "Basic") == 0)
179 ds_hw_accel = DS_HW_ACCEL_BASIC;
180 else if (strcmp(buffer, "Emulation") == 0)
181 ds_hw_accel = DS_HW_ACCEL_EMULATION;
184 if (!get_config_key( hkey, appkey, "DefaultPlayback", buffer, MAX_PATH ))
185 ds_default_playback = atoi(buffer);
187 if (!get_config_key( hkey, appkey, "DefaultCapture", buffer, MAX_PATH ))
188 ds_default_capture = atoi(buffer);
190 if (appkey) RegCloseKey( appkey );
191 if (hkey) RegCloseKey( hkey );
193 if (ds_emuldriver != DS_EMULDRIVER )
194 WARN("ds_emuldriver = %d (default=%d)\n",ds_emuldriver, DS_EMULDRIVER);
195 if (ds_hel_margin != DS_HEL_MARGIN )
196 WARN("ds_hel_margin = %d (default=%d)\n",ds_hel_margin, DS_HEL_MARGIN );
197 if (ds_hel_queue != DS_HEL_QUEUE )
198 WARN("ds_hel_queue = %d (default=%d)\n",ds_hel_queue, DS_HEL_QUEUE );
199 if (ds_snd_queue_max != DS_SND_QUEUE_MAX)
200 WARN("ds_snd_queue_max = %d (default=%d)\n",ds_snd_queue_max ,DS_SND_QUEUE_MAX);
201 if (ds_snd_queue_min != DS_SND_QUEUE_MIN)
202 WARN("ds_snd_queue_min = %d (default=%d)\n",ds_snd_queue_min ,DS_SND_QUEUE_MIN);
203 if (ds_hw_accel != DS_HW_ACCEL_FULL)
204 WARN("ds_hw_accel = %s (default=Full)\n",
205 ds_hw_accel==DS_HW_ACCEL_FULL ? "Full" :
206 ds_hw_accel==DS_HW_ACCEL_STANDARD ? "Standard" :
207 ds_hw_accel==DS_HW_ACCEL_BASIC ? "Basic" :
208 ds_hw_accel==DS_HW_ACCEL_EMULATION ? "Emulation" :
209 "Unknown");
210 if (ds_default_playback != 0)
211 WARN("ds_default_playback = %d (default=0)\n",ds_default_playback);
212 if (ds_default_capture != 0)
213 WARN("ds_default_capture = %d (default=0)\n",ds_default_playback);
216 const char * get_device_id(LPCGUID pGuid)
218 if (IsEqualGUID(&DSDEVID_DefaultPlayback, pGuid))
219 return "DSDEVID_DefaultPlayback";
220 else if (IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuid))
221 return "DSDEVID_DefaultVoicePlayback";
222 else if (IsEqualGUID(&DSDEVID_DefaultCapture, pGuid))
223 return "DSDEVID_DefaultCapture";
224 else if (IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuid))
225 return "DSDEVID_DefaultVoiceCapture";
226 return debugstr_guid(pGuid);
229 /***************************************************************************
230 * GetDeviceID [DSOUND.9]
232 * Retrieves unique identifier of default device specified
234 * PARAMS
235 * pGuidSrc [I] Address of device GUID.
236 * pGuidDest [O] Address to receive unique device GUID.
238 * RETURNS
239 * Success: DS_OK
240 * Failure: DSERR_INVALIDPARAM
242 * NOTES
243 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
244 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
245 * DSDEVID_DefaultVoiceCapture.
246 * Returns pGuidSrc if pGuidSrc is a valid device or the device
247 * GUID for the specified constants.
249 HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest)
251 TRACE("(%s,%p)\n", get_device_id(pGuidSrc),pGuidDest);
253 if ( pGuidSrc == NULL) {
254 WARN("invalid parameter: pGuidSrc == NULL\n");
255 return DSERR_INVALIDPARAM;
258 if ( pGuidDest == NULL ) {
259 WARN("invalid parameter: pGuidDest == NULL\n");
260 return DSERR_INVALIDPARAM;
263 if ( IsEqualGUID( &DSDEVID_DefaultPlayback, pGuidSrc ) ||
264 IsEqualGUID( &DSDEVID_DefaultVoicePlayback, pGuidSrc ) ) {
265 CopyMemory(pGuidDest, &DSOUND_renderer_guids[ds_default_playback], sizeof(GUID));
266 TRACE("returns %s\n", get_device_id(pGuidDest));
267 return DS_OK;
270 if ( IsEqualGUID( &DSDEVID_DefaultCapture, pGuidSrc ) ||
271 IsEqualGUID( &DSDEVID_DefaultVoiceCapture, pGuidSrc ) ) {
272 CopyMemory(pGuidDest, &DSOUND_capture_guids[ds_default_capture], sizeof(GUID));
273 TRACE("returns %s\n", get_device_id(pGuidDest));
274 return DS_OK;
277 CopyMemory(pGuidDest, pGuidSrc, sizeof(GUID));
278 TRACE("returns %s\n", get_device_id(pGuidDest));
280 return DS_OK;
284 /***************************************************************************
285 * DirectSoundEnumerateA [DSOUND.2]
287 * Enumerate all DirectSound drivers installed in the system
289 * PARAMS
290 * lpDSEnumCallback [I] Address of callback function.
291 * lpContext [I] Address of user defined context passed to callback function.
293 * RETURNS
294 * Success: DS_OK
295 * Failure: DSERR_INVALIDPARAM
297 HRESULT WINAPI DirectSoundEnumerateA(
298 LPDSENUMCALLBACKA lpDSEnumCallback,
299 LPVOID lpContext)
301 unsigned devs, wod;
302 DSDRIVERDESC desc;
303 GUID guid;
304 int err;
306 TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
307 lpDSEnumCallback, lpContext);
309 if (lpDSEnumCallback == NULL) {
310 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
311 return DSERR_INVALIDPARAM;
314 devs = waveOutGetNumDevs();
315 if (devs > 0) {
316 if (GetDeviceID(&DSDEVID_DefaultPlayback, &guid) == DS_OK) {
317 for (wod = 0; wod < devs; ++wod) {
318 if (IsEqualGUID( &guid, &DSOUND_renderer_guids[wod]) ) {
319 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
320 if (err == DS_OK) {
321 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
322 "Primary Sound Driver",desc.szDrvname,lpContext);
323 if (lpDSEnumCallback(NULL, "Primary Sound Driver", desc.szDrvname, lpContext) == FALSE)
324 return DS_OK;
331 for (wod = 0; wod < devs; ++wod) {
332 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
333 if (err == DS_OK) {
334 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
335 debugstr_guid(&DSOUND_renderer_guids[wod]),desc.szDesc,desc.szDrvname,lpContext);
336 if (lpDSEnumCallback(&DSOUND_renderer_guids[wod], desc.szDesc, desc.szDrvname, lpContext) == FALSE)
337 return DS_OK;
340 return DS_OK;
343 /***************************************************************************
344 * DirectSoundEnumerateW [DSOUND.3]
346 * Enumerate all DirectSound drivers installed in the system
348 * PARAMS
349 * lpDSEnumCallback [I] Address of callback function.
350 * lpContext [I] Address of user defined context passed to callback function.
352 * RETURNS
353 * Success: DS_OK
354 * Failure: DSERR_INVALIDPARAM
356 HRESULT WINAPI DirectSoundEnumerateW(
357 LPDSENUMCALLBACKW lpDSEnumCallback,
358 LPVOID lpContext )
360 unsigned devs, wod;
361 DSDRIVERDESC desc;
362 GUID guid;
363 int err;
364 WCHAR wDesc[MAXPNAMELEN];
365 WCHAR wName[MAXPNAMELEN];
367 TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
368 lpDSEnumCallback, lpContext);
370 if (lpDSEnumCallback == NULL) {
371 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
372 return DSERR_INVALIDPARAM;
375 devs = waveOutGetNumDevs();
376 if (devs > 0) {
377 if (GetDeviceID(&DSDEVID_DefaultPlayback, &guid) == DS_OK) {
378 for (wod = 0; wod < devs; ++wod) {
379 if (IsEqualGUID( &guid, &DSOUND_renderer_guids[wod] ) ) {
380 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
381 if (err == DS_OK) {
382 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
383 "Primary Sound Driver",desc.szDrvname,lpContext);
384 MultiByteToWideChar( CP_ACP, 0, "Primary Sound Driver", -1,
385 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
386 MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1,
387 wName, sizeof(wName)/sizeof(WCHAR) );
388 if (lpDSEnumCallback(NULL, wDesc, wName, lpContext) == FALSE)
389 return DS_OK;
396 for (wod = 0; wod < devs; ++wod) {
397 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
398 if (err == DS_OK) {
399 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
400 debugstr_guid(&DSOUND_renderer_guids[wod]),desc.szDesc,desc.szDrvname,lpContext);
401 MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1,
402 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
403 MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1,
404 wName, sizeof(wName)/sizeof(WCHAR) );
405 if (lpDSEnumCallback(&DSOUND_renderer_guids[wod], wDesc, wName, lpContext) == FALSE)
406 return DS_OK;
409 return DS_OK;
412 /*******************************************************************************
413 * DirectSound ClassFactory
416 static HRESULT WINAPI
417 DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
418 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
420 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
421 return E_NOINTERFACE;
424 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
426 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
427 ULONG ref = InterlockedIncrement(&(This->ref));
428 TRACE("(%p) ref was %ld\n", This, ref - 1);
429 return ref;
432 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
434 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
435 ULONG ref = InterlockedDecrement(&(This->ref));
436 TRACE("(%p) ref was %ld\n", This, ref + 1);
437 /* static class, won't be freed */
438 return ref;
441 static HRESULT WINAPI DSCF_CreateInstance(
442 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
444 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
445 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
447 if (pOuter)
448 return CLASS_E_NOAGGREGATION;
450 if (ppobj == NULL) {
451 WARN("invalid parameter\n");
452 return DSERR_INVALIDPARAM;
455 *ppobj = NULL;
457 if ( IsEqualIID( &IID_IDirectSound, riid ) )
458 return DSOUND_Create((LPDIRECTSOUND*)ppobj,pOuter);
460 if ( IsEqualIID( &IID_IDirectSound8, riid ) )
461 return DSOUND_Create8((LPDIRECTSOUND8*)ppobj,pOuter);
463 WARN("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
464 return E_NOINTERFACE;
467 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
468 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
469 FIXME("(%p)->(%d),stub!\n",This,dolock);
470 return S_OK;
473 static const IClassFactoryVtbl DSCF_Vtbl = {
474 DSCF_QueryInterface,
475 DSCF_AddRef,
476 DSCF_Release,
477 DSCF_CreateInstance,
478 DSCF_LockServer
481 static IClassFactoryImpl DSOUND_CF = { &DSCF_Vtbl, 1 };
483 /*******************************************************************************
484 * DirectSoundPrivate ClassFactory
487 static HRESULT WINAPI
488 DSPCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
489 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
491 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
492 return E_NOINTERFACE;
495 static ULONG WINAPI DSPCF_AddRef(LPCLASSFACTORY iface)
497 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
498 ULONG ref = InterlockedIncrement(&(This->ref));
499 TRACE("(%p) ref was %ld\n", This, ref - 1);
500 return ref;
503 static ULONG WINAPI DSPCF_Release(LPCLASSFACTORY iface)
505 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
506 ULONG ref = InterlockedDecrement(&(This->ref));
507 TRACE("(%p) ref was %ld\n", This, ref + 1);
508 /* static class, won't be freed */
509 return ref;
512 static HRESULT WINAPI
513 DSPCF_CreateInstance(
514 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
516 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
517 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
519 if (ppobj == NULL) {
520 WARN("invalid parameter\n");
521 return DSERR_INVALIDPARAM;
524 *ppobj = NULL;
526 if ( IsEqualGUID( &IID_IKsPropertySet, riid ) ) {
527 return IKsPrivatePropertySetImpl_Create((IKsPrivatePropertySetImpl**)ppobj);
530 WARN("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
531 return E_NOINTERFACE;
534 static HRESULT WINAPI
535 DSPCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
536 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
537 FIXME("(%p)->(%d),stub!\n",This,dolock);
538 return S_OK;
541 static const IClassFactoryVtbl DSPCF_Vtbl = {
542 DSPCF_QueryInterface,
543 DSPCF_AddRef,
544 DSPCF_Release,
545 DSPCF_CreateInstance,
546 DSPCF_LockServer
549 static IClassFactoryImpl DSOUND_PRIVATE_CF = { &DSPCF_Vtbl, 1 };
551 /*******************************************************************************
552 * DllGetClassObject [DSOUND.@]
553 * Retrieves class object from a DLL object
555 * NOTES
556 * Docs say returns STDAPI
558 * PARAMS
559 * rclsid [I] CLSID for the class object
560 * riid [I] Reference to identifier of interface for class object
561 * ppv [O] Address of variable to receive interface pointer for riid
563 * RETURNS
564 * Success: S_OK
565 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
566 * E_UNEXPECTED
568 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
570 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
572 if (ppv == NULL) {
573 WARN("invalid parameter\n");
574 return E_INVALIDARG;
577 *ppv = NULL;
579 if ( IsEqualCLSID( &CLSID_DirectSound, rclsid ) ||
580 IsEqualCLSID( &CLSID_DirectSound8, rclsid ) ) {
581 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
582 *ppv = (LPVOID)&DSOUND_CF;
583 IClassFactory_AddRef((IClassFactory*)*ppv);
584 return S_OK;
586 WARN("(%s,%s,%p): no interface found.\n",
587 debugstr_guid(rclsid), debugstr_guid(riid), ppv);
588 return S_FALSE;
591 if ( IsEqualCLSID( &CLSID_DirectSoundCapture, rclsid ) ||
592 IsEqualCLSID( &CLSID_DirectSoundCapture8, rclsid ) ) {
593 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
594 *ppv = (LPVOID)&DSOUND_CAPTURE_CF;
595 IClassFactory_AddRef((IClassFactory*)*ppv);
596 return S_OK;
598 WARN("(%s,%s,%p): no interface found.\n",
599 debugstr_guid(rclsid), debugstr_guid(riid), ppv);
600 return S_FALSE;
603 if ( IsEqualCLSID( &CLSID_DirectSoundFullDuplex, rclsid ) ) {
604 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
605 *ppv = (LPVOID)&DSOUND_FULLDUPLEX_CF;
606 IClassFactory_AddRef((IClassFactory*)*ppv);
607 return S_OK;
609 WARN("(%s,%s,%p): no interface found.\n",
610 debugstr_guid(rclsid), debugstr_guid(riid), ppv);
611 return S_FALSE;
614 if ( IsEqualCLSID( &CLSID_DirectSoundPrivate, rclsid ) ) {
615 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
616 *ppv = (LPVOID)&DSOUND_PRIVATE_CF;
617 IClassFactory_AddRef((IClassFactory*)*ppv);
618 return S_OK;
620 WARN("(%s,%s,%p): no interface found.\n",
621 debugstr_guid(rclsid), debugstr_guid(riid), ppv);
622 return S_FALSE;
625 WARN("(%s,%s,%p): no class found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
626 return CLASS_E_CLASSNOTAVAILABLE;
630 /*******************************************************************************
631 * DllCanUnloadNow [DSOUND.4]
632 * Determines whether the DLL is in use.
634 * RETURNS
635 * Success: S_OK
636 * Failure: S_FALSE
638 HRESULT WINAPI DllCanUnloadNow(void)
640 FIXME("(void): stub\n");
641 return S_FALSE;
644 #define INIT_GUID(guid, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
645 guid.Data1 = l; guid.Data2 = w1; guid.Data3 = w2; \
646 guid.Data4[0] = b1; guid.Data4[1] = b2; guid.Data4[2] = b3; \
647 guid.Data4[3] = b4; guid.Data4[4] = b5; guid.Data4[5] = b6; \
648 guid.Data4[6] = b7; guid.Data4[7] = b8;
650 /***********************************************************************
651 * DllMain (DSOUND.init)
653 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
655 int i;
656 TRACE("(%p 0x%lx %p)\n", hInstDLL, fdwReason, lpvReserved);
658 switch (fdwReason) {
659 case DLL_PROCESS_ATTACH:
660 TRACE("DLL_PROCESS_ATTACH\n");
661 for (i = 0; i < MAXWAVEDRIVERS; i++) {
662 DSOUND_renderer[i] = NULL;
663 DSOUND_capture[i] = NULL;
664 INIT_GUID(DSOUND_renderer_guids[i], 0xbd6dd71a, 0x3deb, 0x11d1, 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 + i);
665 INIT_GUID(DSOUND_capture_guids[i], 0xbd6dd71b, 0x3deb, 0x11d1, 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 + i);
667 break;
668 case DLL_PROCESS_DETACH:
669 TRACE("DLL_PROCESS_DETACH\n");
670 break;
671 case DLL_THREAD_ATTACH:
672 TRACE("DLL_THREAD_ATTACH\n");
673 break;
674 case DLL_THREAD_DETACH:
675 TRACE("DLL_THREAD_DETACH\n");
676 break;
677 default:
678 TRACE("UNKNOWN REASON\n");
679 break;
681 return TRUE;