2 * Copyright 2009 Maarten Lankhorst
3 * Copyright 2011 Andrew Eikum for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/port.h"
29 #include "wine/library.h"
35 #include "propkeydef.h"
36 #include "mmdeviceapi.h"
39 #include "audioclient.h"
40 #include "endpointvolume.h"
41 #include "audiopolicy.h"
46 #include "wine/debug.h"
47 #include "wine/unicode.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi
);
51 static HINSTANCE instance
;
55 const WCHAR drv_keyW
[] = {'S','o','f','t','w','a','r','e','\\',
56 'W','i','n','e','\\','D','r','i','v','e','r','s',0};
58 static const char *get_priority_string(int prio
)
61 case Priority_Unavailable
:
65 case Priority_Neutral
:
67 case Priority_Preferred
:
73 static BOOL
load_driver(const WCHAR
*name
, DriverFuncs
*driver
)
75 WCHAR driver_module
[264];
76 static const WCHAR wineW
[] = {'w','i','n','e',0};
77 static const WCHAR dotdrvW
[] = {'.','d','r','v',0};
79 lstrcpyW(driver_module
, wineW
);
80 lstrcatW(driver_module
, name
);
81 lstrcatW(driver_module
, dotdrvW
);
83 TRACE("Attempting to load %s\n", wine_dbgstr_w(driver_module
));
85 driver
->module
= LoadLibraryW(driver_module
);
87 TRACE("Unable to load %s: %u\n", wine_dbgstr_w(driver_module
),
92 #define LDFC(n) do { driver->p##n = (void*)GetProcAddress(driver->module, #n);\
93 if(!driver->p##n) { FreeLibrary(driver->module); return FALSE; } } while(0)
96 LDFC(GetAudioEndpoint
);
97 LDFC(GetAudioSessionManager
);
100 driver
->priority
= driver
->pGetPriority();
101 lstrcpyW(driver
->module_name
, driver_module
);
103 TRACE("Successfully loaded %s with priority %s\n",
104 wine_dbgstr_w(driver_module
), get_priority_string(driver
->priority
));
109 static BOOL
init_driver(void)
111 static const WCHAR drv_value
[] = {'A','u','d','i','o',0};
113 static WCHAR default_list
[] = {'a','l','s','a',',','o','s','s',',',
114 'c','o','r','e','a','u','d','i','o',0};
118 WCHAR reg_list
[256], *p
, *next
, *driver_list
= default_list
;
123 if(RegOpenKeyW(HKEY_CURRENT_USER
, drv_keyW
, &key
) == ERROR_SUCCESS
){
124 DWORD size
= sizeof(reg_list
);
126 if(RegQueryValueExW(key
, drv_value
, 0, NULL
, (BYTE
*)reg_list
,
127 &size
) == ERROR_SUCCESS
){
128 if(reg_list
[0] == '\0'){
129 TRACE("User explicitly chose no driver\n");
134 driver_list
= reg_list
;
140 TRACE("Loading driver list %s\n", wine_dbgstr_w(driver_list
));
141 for(next
= p
= driver_list
; next
; p
= next
+ 1){
142 next
= strchrW(p
, ',');
146 driver
.priority
= Priority_Unavailable
;
147 if(load_driver(p
, &driver
)){
148 if(driver
.priority
== Priority_Unavailable
)
149 FreeLibrary(driver
.module
);
150 else if(!drvs
.module
|| driver
.priority
> drvs
.priority
){
151 TRACE("Selecting driver %s with priority %s\n",
152 wine_dbgstr_w(p
), get_priority_string(driver
.priority
));
154 FreeLibrary(drvs
.module
);
157 FreeLibrary(driver
.module
);
159 TRACE("Failed to load driver %s\n", wine_dbgstr_w(p
));
165 return drvs
.module
!= 0;
168 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
170 TRACE("(0x%p, %d, %p)\n", hinstDLL
, fdwReason
, lpvReserved
);
174 case DLL_PROCESS_ATTACH
:
176 DisableThreadLibraryCalls(hinstDLL
);
178 case DLL_PROCESS_DETACH
:
188 HRESULT WINAPI
DllCanUnloadNow(void)
193 typedef HRESULT (*FnCreateInstance
)(REFIID riid
, LPVOID
*ppobj
);
196 IClassFactory IClassFactory_iface
;
198 FnCreateInstance pfnCreateInstance
;
201 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
203 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
206 static HRESULT WINAPI
207 MMCF_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppobj
)
209 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
210 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppobj
);
213 if (IsEqualIID(riid
, &IID_IUnknown
) ||
214 IsEqualIID(riid
, &IID_IClassFactory
))
217 IClassFactory_AddRef(iface
);
221 return E_NOINTERFACE
;
224 static ULONG WINAPI
MMCF_AddRef(LPCLASSFACTORY iface
)
229 static ULONG WINAPI
MMCF_Release(LPCLASSFACTORY iface
)
231 /* static class, won't be freed */
235 static HRESULT WINAPI
MMCF_CreateInstance(
236 LPCLASSFACTORY iface
,
241 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
242 TRACE("(%p, %p, %s, %p)\n", This
, pOuter
, debugstr_guid(riid
), ppobj
);
245 return CLASS_E_NOAGGREGATION
;
248 WARN("invalid parameter\n");
252 return This
->pfnCreateInstance(riid
, ppobj
);
255 static HRESULT WINAPI
MMCF_LockServer(LPCLASSFACTORY iface
, BOOL dolock
)
257 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
258 FIXME("(%p, %d) stub!\n", This
, dolock
);
262 static const IClassFactoryVtbl MMCF_Vtbl
= {
270 static IClassFactoryImpl MMDEVAPI_CF
[] = {
271 { { &MMCF_Vtbl
}, &CLSID_MMDeviceEnumerator
, (FnCreateInstance
)MMDevEnum_Create
}
274 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
277 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
280 ERR("Driver initialization failed\n");
285 WARN("invalid parameter\n");
291 if (!IsEqualIID(riid
, &IID_IClassFactory
) &&
292 !IsEqualIID(riid
, &IID_IUnknown
)) {
293 WARN("no interface for %s\n", debugstr_guid(riid
));
294 return E_NOINTERFACE
;
297 for (i
= 0; i
< sizeof(MMDEVAPI_CF
)/sizeof(MMDEVAPI_CF
[0]); ++i
)
299 if (IsEqualGUID(rclsid
, MMDEVAPI_CF
[i
].rclsid
)) {
300 IClassFactory_AddRef(&MMDEVAPI_CF
[i
].IClassFactory_iface
);
301 *ppv
= &MMDEVAPI_CF
[i
];
307 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid
),
308 debugstr_guid(riid
), ppv
);
309 return CLASS_E_CLASSNOTAVAILABLE
;
312 /***********************************************************************
313 * DllRegisterServer (MMDEVAPI.@)
315 HRESULT WINAPI
DllRegisterServer(void)
317 return __wine_register_resources( instance
);
320 /***********************************************************************
321 * DllUnregisterServer (MMDEVAPI.@)
323 HRESULT WINAPI
DllUnregisterServer(void)
325 return __wine_unregister_resources( instance
);