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"
36 #include "propkeydef.h"
37 #include "mmdeviceapi.h"
40 #include "audioclient.h"
41 #include "endpointvolume.h"
42 #include "audiopolicy.h"
47 #include "wine/debug.h"
48 #include "wine/unicode.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi
);
52 static HINSTANCE instance
;
56 static BOOL
load_driver(const WCHAR
*name
)
58 WCHAR driver_module
[264];
59 static const WCHAR wineW
[] = {'w','i','n','e',0};
60 static const WCHAR dotdrvW
[] = {'.','d','r','v',0};
62 lstrcpyW(driver_module
, wineW
);
63 lstrcatW(driver_module
, name
);
64 lstrcatW(driver_module
, dotdrvW
);
66 TRACE("Attempting to load %s\n", wine_dbgstr_w(driver_module
));
68 drvs
.module
= LoadLibraryW(driver_module
);
70 TRACE("Unable to load %s: %u\n", wine_dbgstr_w(driver_module
),
75 #define LDFC(n) do { drvs.p##n = (void*)GetProcAddress(drvs.module, #n);\
76 if(!drvs.p##n) { FreeLibrary(drvs.module); return FALSE; } } while(0)
78 LDFC(GetAudioEndpoint
);
79 LDFC(GetAudioSessionManager
);
82 lstrcpyW(drvs
.module_name
, driver_module
);
83 TRACE("Successfully loaded %s\n", wine_dbgstr_w(driver_module
));
88 static BOOL
init_driver(void)
90 static const WCHAR alsaW
[] = {'a','l','s','a',0};
91 static const WCHAR ossW
[] = {'o','s','s',0};
92 static const WCHAR coreaudioW
[] = {'c','o','r','e','a','u','d','i','o',0};
93 static const WCHAR
*default_drivers
[] = { alsaW
, coreaudioW
, ossW
};
94 static const WCHAR drv_key
[] = {'S','o','f','t','w','a','r','e','\\',
95 'W','i','n','e','\\','D','r','i','v','e','r','s',0};
96 static const WCHAR drv_value
[] = {'A','u','d','i','o',0};
103 if(RegOpenKeyW(HKEY_CURRENT_USER
, drv_key
, &key
) == ERROR_SUCCESS
){
104 WCHAR driver_name
[256], *p
, *next
;
105 DWORD size
= sizeof(driver_name
);
107 if(RegQueryValueExW(key
, drv_value
, 0, NULL
, (BYTE
*)driver_name
,
108 &size
) == ERROR_SUCCESS
){
111 if(driver_name
[0] == '\0')
114 for(next
= p
= driver_name
; next
; p
= next
+ 1){
115 next
= strchrW(p
, ',');
122 TRACE("Failed to load driver: %s\n", wine_dbgstr_w(driver_name
));
125 ERR("No drivers in the registry loaded successfully!\n");
132 for(i
= 0; i
< sizeof(default_drivers
)/sizeof(*default_drivers
); ++i
)
133 if(load_driver(default_drivers
[i
]))
139 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
141 TRACE("(0x%p, %d, %p)\n", hinstDLL
, fdwReason
, lpvReserved
);
145 case DLL_PROCESS_ATTACH
:
147 DisableThreadLibraryCalls(hinstDLL
);
149 case DLL_PROCESS_DETACH
:
157 HRESULT WINAPI
DllCanUnloadNow(void)
162 typedef HRESULT (*FnCreateInstance
)(REFIID riid
, LPVOID
*ppobj
);
165 IClassFactory IClassFactory_iface
;
167 FnCreateInstance pfnCreateInstance
;
170 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
172 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
175 static HRESULT WINAPI
176 MMCF_QueryInterface(LPCLASSFACTORY iface
, REFIID riid
, LPVOID
*ppobj
)
178 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
179 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppobj
);
182 if (IsEqualIID(riid
, &IID_IUnknown
) ||
183 IsEqualIID(riid
, &IID_IClassFactory
))
186 IUnknown_AddRef(iface
);
190 return E_NOINTERFACE
;
193 static ULONG WINAPI
MMCF_AddRef(LPCLASSFACTORY iface
)
198 static ULONG WINAPI
MMCF_Release(LPCLASSFACTORY iface
)
200 /* static class, won't be freed */
204 static HRESULT WINAPI
MMCF_CreateInstance(
205 LPCLASSFACTORY iface
,
210 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
211 TRACE("(%p, %p, %s, %p)\n", This
, pOuter
, debugstr_guid(riid
), ppobj
);
214 return CLASS_E_NOAGGREGATION
;
217 WARN("invalid parameter\n");
221 return This
->pfnCreateInstance(riid
, ppobj
);
224 static HRESULT WINAPI
MMCF_LockServer(LPCLASSFACTORY iface
, BOOL dolock
)
226 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
227 FIXME("(%p, %d) stub!\n", This
, dolock
);
231 static const IClassFactoryVtbl MMCF_Vtbl
= {
239 static IClassFactoryImpl MMDEVAPI_CF
[] = {
240 { { &MMCF_Vtbl
}, &CLSID_MMDeviceEnumerator
, (FnCreateInstance
)MMDevEnum_Create
}
243 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
246 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
249 ERR("Driver initialization failed\n");
254 WARN("invalid parameter\n");
260 if (!IsEqualIID(riid
, &IID_IClassFactory
) &&
261 !IsEqualIID(riid
, &IID_IUnknown
)) {
262 WARN("no interface for %s\n", debugstr_guid(riid
));
263 return E_NOINTERFACE
;
266 for (i
= 0; i
< sizeof(MMDEVAPI_CF
)/sizeof(MMDEVAPI_CF
[0]); ++i
)
268 if (IsEqualGUID(rclsid
, MMDEVAPI_CF
[i
].rclsid
)) {
269 IUnknown_AddRef(&MMDEVAPI_CF
[i
].IClassFactory_iface
);
270 *ppv
= &MMDEVAPI_CF
[i
];
276 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid
),
277 debugstr_guid(riid
), ppv
);
278 return CLASS_E_CLASSNOTAVAILABLE
;
281 /***********************************************************************
282 * DllRegisterServer (MMDEVAPI.@)
284 HRESULT WINAPI
DllRegisterServer(void)
286 return __wine_register_resources( instance
);
289 /***********************************************************************
290 * DllUnregisterServer (MMDEVAPI.@)
292 HRESULT WINAPI
DllUnregisterServer(void)
294 return __wine_unregister_resources( instance
);