Use system metrics values in TOOLBAR_DrawPattern instead of hardcoded
[wine] / dlls / dsound / dsound_main.c
1 /*                      DirectSound
2  *
3  * Copyright 1998 Marcus Meissner
4  * Copyright 1998 Rob Riggs
5  * Copyright 2000-2002 TransGaming Technologies, Inc.
6  *
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.
11  *
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.
16  *
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
20  */
21 /*
22  * Most thread locking is complete. There may be a few race
23  * conditions still lurking.
24  *
25  * Tested with a Soundblaster clone, a Gravis UltraSound Classic,
26  * and a Turtle Beach Tropez+.
27  *
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
37  */
38
39 #include "config.h"
40 #include "wine/port.h"
41
42 #include <assert.h>
43 #include <stdarg.h>
44 #include <stdio.h>
45 #include <sys/types.h>
46 #include <sys/fcntl.h>
47 #ifdef HAVE_UNISTD_H
48 # include <unistd.h>
49 #endif
50 #include <stdlib.h>
51 #include <string.h>
52 #include <math.h>
53
54 #define NONAMELESSSTRUCT
55 #define NONAMELESSUNION
56 #include "windef.h"
57 #include "winbase.h"
58 #include "winreg.h"
59 #include "winuser.h"
60 #include "wingdi.h"
61 #include "winuser.h"
62 #include "winerror.h"
63 #include "mmsystem.h"
64 #include "winternl.h"
65 #include "mmddk.h"
66 #include "wine/windef16.h"
67 #include "wine/winbase16.h"
68 #include "wine/debug.h"
69 #include "dsound.h"
70 #include "dsdriver.h"
71 #include "dsound_private.h"
72 #include "dsconf.h"
73
74 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
75
76 /* these are eligible for tuning... they must be high on slow machines... */
77 /* some stuff may get more responsive with lower values though... */
78 #define DS_EMULDRIVER 0 /* some games (Quake 2, UT) refuse to accept
79                                 emulated dsound devices. set to 0 ! */
80 #define DS_HEL_MARGIN 5 /* HEL only: number of waveOut fragments ahead to mix in new buffers
81                          * (keep this close or equal to DS_HEL_QUEUE for best results) */
82 #define DS_HEL_QUEUE  5 /* HEL only: number of waveOut fragments ahead to queue to driver
83                          * (this will affect HEL sound reliability and latency) */
84
85 #define DS_SND_QUEUE_MAX 28 /* max number of fragments to prebuffer */
86 #define DS_SND_QUEUE_MIN 12 /* min number of fragments to prebuffer */
87
88 IDirectSoundImpl*       dsound = NULL;
89
90 HRESULT mmErr(UINT err)
91 {
92         switch(err) {
93         case MMSYSERR_NOERROR:
94                 return DS_OK;
95         case MMSYSERR_ALLOCATED:
96                 return DSERR_ALLOCATED;
97         case MMSYSERR_ERROR:
98         case MMSYSERR_INVALHANDLE:
99         case WAVERR_STILLPLAYING:
100                 return DSERR_GENERIC; /* FIXME */
101         case MMSYSERR_NODRIVER:
102                 return DSERR_NODRIVER;
103         case MMSYSERR_NOMEM:
104                 return DSERR_OUTOFMEMORY;
105         case MMSYSERR_INVALPARAM:
106         case WAVERR_BADFORMAT:
107         case WAVERR_UNPREPARED:
108                 return DSERR_INVALIDPARAM;
109         case MMSYSERR_NOTSUPPORTED:
110                 return DSERR_UNSUPPORTED;
111         default:
112                 FIXME("Unknown MMSYS error %d\n",err);
113                 return DSERR_GENERIC;
114         }
115 }
116
117 int ds_emuldriver = DS_EMULDRIVER;
118 int ds_hel_margin = DS_HEL_MARGIN;
119 int ds_hel_queue = DS_HEL_QUEUE;
120 int ds_snd_queue_max = DS_SND_QUEUE_MAX;
121 int ds_snd_queue_min = DS_SND_QUEUE_MIN;
122 int ds_hw_accel = DS_HW_ACCEL_FULL;
123 int ds_default_playback = 0;
124 int ds_default_capture = 0;
125
126 /*
127  * Get a config key from either the app-specific or the default config
128  */
129
130 inline static DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
131                                     char *buffer, DWORD size )
132 {
133     if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, buffer, &size )) return 0;
134     return RegQueryValueExA( defkey, name, 0, NULL, buffer, &size );
135 }
136
137
138 /*
139  * Setup the dsound options.
140  */
141
142 void setup_dsound_options(void)
143 {
144     char buffer[MAX_PATH+1];
145     HKEY hkey, appkey = 0;
146     DWORD len;
147
148     buffer[MAX_PATH]='\0';
149
150     if (RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\dsound", 0, NULL,
151                          REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL ))
152     {
153         ERR("Cannot create config registry key\n" );
154         ExitProcess(1);
155     }
156
157     len = GetModuleFileNameA( 0, buffer, MAX_PATH );
158     if (len && len < MAX_PATH)
159     {
160         HKEY tmpkey;
161
162         if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\AppDefaults", &tmpkey ))
163         {
164            char appname[MAX_PATH+16];
165            char *p = strrchr( buffer, '\\' );
166            if (p!=NULL) {
167                    appname[MAX_PATH]='\0';
168                    strncpy(appname,p+1,MAX_PATH);
169                    strcat(appname,"\\dsound");
170                    TRACE("appname = [%s] \n",appname);
171                    if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
172                        RegCloseKey( tmpkey );
173            }
174         }
175     }
176
177     /* get options */
178
179     if (!get_config_key( hkey, appkey, "EmulDriver", buffer, MAX_PATH ))
180         ds_emuldriver = strcmp(buffer, "N");
181
182     if (!get_config_key( hkey, appkey, "HELmargin", buffer, MAX_PATH ))
183         ds_hel_margin = atoi(buffer);
184
185     if (!get_config_key( hkey, appkey, "HELqueue", buffer, MAX_PATH ))
186         ds_hel_queue = atoi(buffer);
187
188     if (!get_config_key( hkey, appkey, "SndQueueMax", buffer, MAX_PATH ))
189         ds_snd_queue_max = atoi(buffer);
190
191     if (!get_config_key( hkey, appkey, "SndQueueMin", buffer, MAX_PATH ))
192         ds_snd_queue_min = atoi(buffer);
193
194     if (!get_config_key( hkey, appkey, "HardwareAcceleration", buffer, MAX_PATH )) {
195         if (strcmp(buffer, "Full") == 0)
196             ds_hw_accel = DS_HW_ACCEL_FULL;
197         else if (strcmp(buffer, "Standard") == 0)
198             ds_hw_accel = DS_HW_ACCEL_STANDARD;
199         else if (strcmp(buffer, "Basic") == 0)
200             ds_hw_accel = DS_HW_ACCEL_BASIC;
201         else if (strcmp(buffer, "Emulation") == 0)
202             ds_hw_accel = DS_HW_ACCEL_EMULATION;
203     }
204
205     if (!get_config_key( hkey, appkey, "DefaultPlayback", buffer, MAX_PATH ))
206             ds_default_playback = atoi(buffer);
207
208     if (!get_config_key( hkey, appkey, "DefaultCapture", buffer, MAX_PATH ))
209             ds_default_capture = atoi(buffer);
210
211     if (appkey) RegCloseKey( appkey );
212     RegCloseKey( hkey );
213
214     if (ds_emuldriver != DS_EMULDRIVER )
215        WARN("ds_emuldriver = %d (default=%d)\n",ds_emuldriver, DS_EMULDRIVER);
216     if (ds_hel_margin != DS_HEL_MARGIN )
217        WARN("ds_hel_margin = %d (default=%d)\n",ds_hel_margin, DS_HEL_MARGIN );
218     if (ds_hel_queue != DS_HEL_QUEUE )
219        WARN("ds_hel_queue = %d (default=%d)\n",ds_hel_queue, DS_HEL_QUEUE );
220     if (ds_snd_queue_max != DS_SND_QUEUE_MAX)
221        WARN("ds_snd_queue_max = %d (default=%d)\n",ds_snd_queue_max ,DS_SND_QUEUE_MAX);
222     if (ds_snd_queue_min != DS_SND_QUEUE_MIN)
223        WARN("ds_snd_queue_min = %d (default=%d)\n",ds_snd_queue_min ,DS_SND_QUEUE_MIN);
224     if (ds_hw_accel != DS_HW_ACCEL_FULL)
225         WARN("ds_hw_accel = %s (default=Full)\n", 
226             ds_hw_accel==DS_HW_ACCEL_FULL ? "Full" :
227             ds_hw_accel==DS_HW_ACCEL_STANDARD ? "Standard" :
228             ds_hw_accel==DS_HW_ACCEL_BASIC ? "Basic" :
229             ds_hw_accel==DS_HW_ACCEL_EMULATION ? "Emulation" :
230             "Unknown");
231     if (ds_default_playback != 0)
232         WARN("ds_default_playback = %d (default=0)\n",ds_default_playback);
233     if (ds_default_capture != 0)
234         WARN("ds_default_capture = %d (default=0)\n",ds_default_playback);
235 }
236
237
238
239 /***************************************************************************
240  * GetDeviceID  [DSOUND.9]
241  *
242  * Retrieves unique identifier of default device specified
243  *
244  * PARAMS
245  *    pGuidSrc  [I] Address of device GUID.
246  *    pGuidDest [O] Address to receive unique device GUID.
247  *
248  * RETURNS
249  *    Success: DS_OK
250  *    Failure: DSERR_INVALIDPARAM
251  *
252  * NOTES
253  *    pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
254  *    DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or 
255  *    DSDEVID_DefaultVoiceCapture.
256  *    Returns pGuidSrc if pGuidSrc is a valid device or the device
257  *    GUID for the specified constants.
258  */
259 HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest)
260 {
261     TRACE("(%p,%p)\n",pGuidSrc,pGuidDest);
262
263     if ( pGuidSrc == NULL) {
264         WARN("invalid parameter: pGuidSrc == NULL\n");
265         return DSERR_INVALIDPARAM;
266     }
267
268     if ( pGuidDest == NULL ) {
269         WARN("invalid parameter: pGuidDest == NULL\n");
270         return DSERR_INVALIDPARAM;
271     }
272
273     if ( IsEqualGUID( &DSDEVID_DefaultPlayback, pGuidSrc ) ||
274         IsEqualGUID( &DSDEVID_DefaultVoicePlayback, pGuidSrc ) ) {
275         GUID guid;
276         int err = mmErr(waveOutMessage((HWAVEOUT)ds_default_playback,DRV_QUERYDSOUNDGUID,(DWORD)&guid,0));
277         if (err == DS_OK) {
278             memcpy(pGuidDest, &guid, sizeof(GUID));
279             return DS_OK;
280         }
281     }
282
283     if ( IsEqualGUID( &DSDEVID_DefaultCapture, pGuidSrc ) ||
284         IsEqualGUID( &DSDEVID_DefaultVoiceCapture, pGuidSrc ) ) {
285         GUID guid;
286         int err = mmErr(waveInMessage((HWAVEIN)ds_default_capture,DRV_QUERYDSOUNDGUID,(DWORD)&guid,0));
287         if (err == DS_OK) {
288             memcpy(pGuidDest, &guid, sizeof(GUID));
289             return DS_OK;
290         }
291     }
292
293     memcpy(pGuidDest, pGuidSrc, sizeof(GUID));
294
295     return DS_OK;
296 }
297
298
299 /***************************************************************************
300  * DirectSoundEnumerateA [DSOUND.2]
301  *
302  * Enumerate all DirectSound drivers installed in the system
303  *
304  * PARAMS
305  *    lpDSEnumCallback  [I] Address of callback function.
306  *    lpContext         [I] Address of user defined context passed to callback function.
307  *
308  * RETURNS
309  *    Success: DS_OK
310  *    Failure: DSERR_INVALIDPARAM
311  */
312 HRESULT WINAPI DirectSoundEnumerateA(
313     LPDSENUMCALLBACKA lpDSEnumCallback,
314     LPVOID lpContext)
315 {
316     unsigned devs, wod;
317     DSDRIVERDESC desc;
318     GUID guid;
319     int err;
320
321     TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
322         lpDSEnumCallback, lpContext);
323
324     if (lpDSEnumCallback == NULL) {
325         WARN("invalid parameter: lpDSEnumCallback == NULL\n");
326         return DSERR_INVALIDPARAM;
327     }
328
329     devs = waveOutGetNumDevs();
330     if (devs > 0) {
331         if (GetDeviceID(&DSDEVID_DefaultPlayback, &guid) == DS_OK) {
332             GUID temp;
333             for (wod = 0; wod < devs; ++wod) {
334                 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDGUID,(DWORD)&temp,0));
335                 if (err == DS_OK) {
336                     if (IsEqualGUID( &guid, &temp ) ) {
337                         err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
338                         if (err == DS_OK) {
339                             TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
340                                 "Primary Sound Driver",desc.szDrvName,lpContext);
341                             if (lpDSEnumCallback(NULL, "Primary Sound Driver", desc.szDrvName, lpContext) == FALSE)
342                                 return DS_OK;
343                         }
344                     }
345                 }
346             }
347         }
348     }
349
350     for (wod = 0; wod < devs; ++wod) {
351         err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
352         if (err == DS_OK) {
353             err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDGUID,(DWORD)&guid,0));
354             if (err == DS_OK) {
355                 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
356                     debugstr_guid(&guid),desc.szDesc,desc.szDrvName,lpContext);
357                 if (lpDSEnumCallback(&guid, desc.szDesc, desc.szDrvName, lpContext) == FALSE)
358                     return DS_OK;
359             }
360         }
361     }
362     return DS_OK;
363 }
364
365 /***************************************************************************
366  * DirectSoundEnumerateW [DSOUND.3]
367  *
368  * Enumerate all DirectSound drivers installed in the system
369  *
370  * PARAMS
371  *    lpDSEnumCallback  [I] Address of callback function.
372  *    lpContext         [I] Address of user defined context passed to callback function.
373  *
374  * RETURNS
375  *    Success: DS_OK
376  *    Failure: DSERR_INVALIDPARAM
377  */
378 HRESULT WINAPI DirectSoundEnumerateW(
379         LPDSENUMCALLBACKW lpDSEnumCallback,
380         LPVOID lpContext )
381 {
382     unsigned devs, wod;
383     DSDRIVERDESC desc;
384     GUID guid;
385     int err;
386     WCHAR wDesc[MAXPNAMELEN];
387     WCHAR wName[MAXPNAMELEN];
388
389     TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
390         lpDSEnumCallback, lpContext);
391
392     if (lpDSEnumCallback == NULL) {
393         WARN("invalid parameter: lpDSEnumCallback == NULL\n");
394         return DSERR_INVALIDPARAM;
395     }
396
397     devs = waveOutGetNumDevs();
398     if (devs > 0) {
399         if (GetDeviceID(&DSDEVID_DefaultPlayback, &guid) == DS_OK) {
400             GUID temp;
401             for (wod = 0; wod < devs; ++wod) {
402                 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDGUID,(DWORD)&temp,0));
403                 if (err == DS_OK) {
404                     if (IsEqualGUID( &guid, &temp ) ) {
405                         err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
406                         if (err == DS_OK) {
407                             TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
408                                 "Primary Sound Driver",desc.szDrvName,lpContext);
409                             MultiByteToWideChar( CP_ACP, 0, "Primary Sound Driver", -1,
410                                 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
411                                 MultiByteToWideChar( CP_ACP, 0, desc.szDrvName, -1,
412                                 wName, sizeof(wName)/sizeof(WCHAR) );
413                             if (lpDSEnumCallback(NULL, wDesc, wName, lpContext) == FALSE)
414                                 return DS_OK;
415                         }
416                     }
417                 }
418             }
419         }
420     }
421
422     for (wod = 0; wod < devs; ++wod) {
423         err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
424         if (err == DS_OK) {
425             err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDGUID,(DWORD)&guid,0));
426             if (err == DS_OK) {
427                 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
428                     debugstr_guid(&guid),desc.szDesc,desc.szDrvName,lpContext);
429                 MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1,
430                     wDesc, sizeof(wDesc)/sizeof(WCHAR) );
431                     MultiByteToWideChar( CP_ACP, 0, desc.szDrvName, -1,
432                     wName, sizeof(wName)/sizeof(WCHAR) );
433                 if (lpDSEnumCallback(&guid, wDesc, wName, lpContext) == FALSE)
434                     return DS_OK;
435             }
436         }
437     }
438     return DS_OK;
439 }
440
441 /*******************************************************************************
442  * DirectSound ClassFactory
443  */
444
445 static HRESULT WINAPI
446 DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
447         ICOM_THIS(IClassFactoryImpl,iface);
448
449         FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
450         return E_NOINTERFACE;
451 }
452
453 static ULONG WINAPI
454 DSCF_AddRef(LPCLASSFACTORY iface) {
455         ICOM_THIS(IClassFactoryImpl,iface);
456         TRACE("(%p) ref was %ld\n", This, This->ref);
457         return ++(This->ref);
458 }
459
460 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface) {
461         ICOM_THIS(IClassFactoryImpl,iface);
462         /* static class, won't be  freed */
463         TRACE("(%p) ref was %ld\n", This, This->ref);
464         return --(This->ref);
465 }
466
467 static HRESULT WINAPI DSCF_CreateInstance(
468         LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
469 ) {
470         ICOM_THIS(IClassFactoryImpl,iface);
471         TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
472
473         if (ppobj == NULL) {
474                 WARN("invalid parameter\n");
475                 return DSERR_INVALIDPARAM;
476         }
477
478         *ppobj = NULL;
479
480         if ( IsEqualIID( &IID_IDirectSound, riid ) )
481                 return DirectSoundCreate(0,(LPDIRECTSOUND*)ppobj,pOuter);
482
483         if ( IsEqualIID( &IID_IDirectSound8, riid ) )
484                 return DirectSoundCreate8(0,(LPDIRECTSOUND8*)ppobj,pOuter);
485
486         WARN("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);     
487         return E_NOINTERFACE;
488 }
489
490 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
491         ICOM_THIS(IClassFactoryImpl,iface);
492         FIXME("(%p)->(%d),stub!\n",This,dolock);
493         return S_OK;
494 }
495
496 static ICOM_VTABLE(IClassFactory) DSCF_Vtbl = {
497         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
498         DSCF_QueryInterface,
499         DSCF_AddRef,
500         DSCF_Release,
501         DSCF_CreateInstance,
502         DSCF_LockServer
503 };
504
505 static IClassFactoryImpl DSOUND_CF = { &DSCF_Vtbl, 1 };
506
507 /*******************************************************************************
508  * DirectSoundPrivate ClassFactory
509  */
510
511 static HRESULT WINAPI
512 DSPCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
513         ICOM_THIS(IClassFactoryImpl,iface);
514
515         FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
516         return E_NOINTERFACE;
517 }
518
519 static ULONG WINAPI
520 DSPCF_AddRef(LPCLASSFACTORY iface) {
521         ICOM_THIS(IClassFactoryImpl,iface);
522         TRACE("(%p) ref was %ld\n", This, This->ref);
523         return ++(This->ref);
524 }
525
526 static ULONG WINAPI 
527 DSPCF_Release(LPCLASSFACTORY iface) {
528         ICOM_THIS(IClassFactoryImpl,iface);
529         /* static class, won't be  freed */
530         TRACE("(%p) ref was %ld\n", This, This->ref);
531         return --(This->ref);
532 }
533
534 static HRESULT WINAPI 
535 DSPCF_CreateInstance(
536         LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
537 ) {
538         ICOM_THIS(IClassFactoryImpl,iface);
539         TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
540
541         if (ppobj == NULL) {
542                 WARN("invalid parameter\n");
543                 return DSERR_INVALIDPARAM;
544         }
545
546         *ppobj = NULL;
547
548         if ( IsEqualGUID( &IID_IKsPropertySet, riid ) ) {
549                 return IKsPrivatePropertySetImpl_Create((IKsPrivatePropertySetImpl**)ppobj);
550         }
551
552         WARN("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);     
553         return E_NOINTERFACE;
554 }
555
556 static HRESULT WINAPI 
557 DSPCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
558         ICOM_THIS(IClassFactoryImpl,iface);
559         FIXME("(%p)->(%d),stub!\n",This,dolock);
560         return S_OK;
561 }
562
563 static ICOM_VTABLE(IClassFactory) DSPCF_Vtbl = {
564         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
565         DSPCF_QueryInterface,
566         DSPCF_AddRef,
567         DSPCF_Release,
568         DSPCF_CreateInstance,
569         DSPCF_LockServer
570 };
571
572 static IClassFactoryImpl DSOUND_PRIVATE_CF = { &DSPCF_Vtbl, 1 };
573
574 /*******************************************************************************
575  * DllGetClassObject [DSOUND.5]
576  * Retrieves class object from a DLL object
577  *
578  * NOTES
579  *    Docs say returns STDAPI
580  *
581  * PARAMS
582  *    rclsid [I] CLSID for the class object
583  *    riid   [I] Reference to identifier of interface for class object
584  *    ppv    [O] Address of variable to receive interface pointer for riid
585  *
586  * RETURNS
587  *    Success: S_OK
588  *    Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
589  *             E_UNEXPECTED
590  */
591 DWORD WINAPI DSOUND_DllGetClassObject(REFCLSID rclsid,REFIID riid,LPVOID *ppv)
592 {
593     TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
594
595     if (ppv == NULL) {
596         WARN("invalid parameter\n");
597         return E_INVALIDARG;
598     }
599
600     *ppv = NULL;
601
602     if ( IsEqualCLSID( &CLSID_DirectSound, rclsid ) ||
603          IsEqualCLSID( &CLSID_DirectSound8, rclsid ) ) {
604         if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
605             *ppv = (LPVOID)&DSOUND_CF;
606             IClassFactory_AddRef((IClassFactory*)*ppv);
607             return S_OK;
608         }
609         WARN("(%s,%s,%p): no interface found.\n",
610             debugstr_guid(rclsid), debugstr_guid(riid), ppv);
611         return S_FALSE;
612     }
613     
614     if ( IsEqualCLSID( &CLSID_DirectSoundCapture, rclsid ) ||
615          IsEqualCLSID( &CLSID_DirectSoundCapture8, rclsid ) ) {
616         if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
617             *ppv = (LPVOID)&DSOUND_CAPTURE_CF;
618             IClassFactory_AddRef((IClassFactory*)*ppv);
619             return S_OK;
620         }
621         WARN("(%s,%s,%p): no interface found.\n",
622             debugstr_guid(rclsid), debugstr_guid(riid), ppv);
623         return S_FALSE;
624     }
625     
626     if ( IsEqualCLSID( &CLSID_DirectSoundFullDuplex, rclsid ) ) {
627         if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
628             *ppv = (LPVOID)&DSOUND_FULLDUPLEX_CF;
629             IClassFactory_AddRef((IClassFactory*)*ppv);
630             return S_OK;
631         }
632         WARN("(%s,%s,%p): no interface found.\n",
633             debugstr_guid(rclsid), debugstr_guid(riid), ppv);
634         return S_FALSE;
635     }
636     
637     if ( IsEqualCLSID( &CLSID_DirectSoundPrivate, rclsid ) ) {
638         if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
639             *ppv = (LPVOID)&DSOUND_PRIVATE_CF;
640             IClassFactory_AddRef((IClassFactory*)*ppv);
641             return S_OK;
642         }
643         WARN("(%s,%s,%p): no interface found.\n",
644             debugstr_guid(rclsid), debugstr_guid(riid), ppv);
645         return S_FALSE;
646     }
647
648     WARN("(%s,%s,%p): no class found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
649     return CLASS_E_CLASSNOTAVAILABLE;
650 }
651
652
653 /*******************************************************************************
654  * DllCanUnloadNow [DSOUND.4]  
655  * Determines whether the DLL is in use.
656  *
657  * RETURNS
658  *    Success: S_OK
659  *    Failure: S_FALSE
660  */
661 DWORD WINAPI DSOUND_DllCanUnloadNow(void)
662 {
663     FIXME("(void): stub\n");
664     return S_FALSE;
665 }