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"
49 WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi
);
51 static HINSTANCE instance
;
55 static BOOL
load_driver(const WCHAR
*name
)
57 WCHAR driver_module
[264];
58 static const WCHAR wineW
[] = {'w','i','n','e',0};
59 static const WCHAR dotdrvW
[] = {'.','d','r','v',0};
61 lstrcpyW(driver_module
, wineW
);
62 lstrcatW(driver_module
, name
);
63 lstrcatW(driver_module
, dotdrvW
);
65 TRACE("Attempting to load %s\n", wine_dbgstr_w(driver_module
));
67 drvs
.module
= LoadLibraryW(driver_module
);
69 TRACE("Unable to load %s: %u\n", wine_dbgstr_w(driver_module
),
74 #define LDFC(n) do { drvs.p##n = (void*)GetProcAddress(drvs.module, #n);\
75 if(!drvs.p##n) { FreeLibrary(drvs.module); return FALSE; } } while(0)
77 LDFC(GetAudioEndpoint
);
78 LDFC(GetAudioSessionManager
);
81 TRACE("Successfully loaded %s\n", wine_dbgstr_w(driver_module
));
86 static BOOL
init_driver(void)
88 static const WCHAR alsaW
[] = {'a','l','s','a',0};
89 static const WCHAR ossW
[] = {'o','s','s',0};
90 static const WCHAR coreaudioW
[] = {'c','o','r','e','a','u','d','i','o',0};
91 static const WCHAR
*default_drivers
[] = { alsaW
, coreaudioW
, ossW
};
92 static const WCHAR drv_key
[] = {'S','o','f','t','w','a','r','e','\\',
93 'W','i','n','e','\\','D','r','i','v','e','r','s',0};
94 static const WCHAR drv_value
[] = {'A','u','d','i','o',0};
101 if(RegOpenKeyW(HKEY_CURRENT_USER
, drv_key
, &key
) == ERROR_SUCCESS
){
102 WCHAR driver_name
[256];
103 DWORD size
= sizeof(driver_name
);
105 if(RegQueryValueExW(key
, drv_value
, 0, NULL
, (BYTE
*)driver_name
,
106 &size
) == ERROR_SUCCESS
){
107 BOOL ret
= load_driver(driver_name
);
110 ERR("Failed to load driver: %s\n", wine_dbgstr_w(driver_name
));
117 for(i
= 0; i
< sizeof(default_drivers
)/sizeof(*default_drivers
); ++i
)
118 if(load_driver(default_drivers
[i
]))
124 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
126 TRACE("(0x%p, %d, %p)\n", hinstDLL
, fdwReason
, lpvReserved
);
130 case DLL_PROCESS_ATTACH
:
132 DisableThreadLibraryCalls(hinstDLL
);
134 case DLL_PROCESS_DETACH
:
142 HRESULT WINAPI
DllCanUnloadNow(void)
147 typedef HRESULT (*FnCreateInstance
)(REFIID riid
, LPVOID
*ppobj
);
150 IClassFactory IClassFactory_iface
;
152 FnCreateInstance pfnCreateInstance
;
155 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
157 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
160 static HRESULT WINAPI
161 MMCF_QueryInterface(LPCLASSFACTORY iface
, REFIID riid
, LPVOID
*ppobj
)
163 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
164 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppobj
);
167 if (IsEqualIID(riid
, &IID_IUnknown
) ||
168 IsEqualIID(riid
, &IID_IClassFactory
))
171 IUnknown_AddRef(iface
);
175 return E_NOINTERFACE
;
178 static ULONG WINAPI
MMCF_AddRef(LPCLASSFACTORY iface
)
183 static ULONG WINAPI
MMCF_Release(LPCLASSFACTORY iface
)
185 /* static class, won't be freed */
189 static HRESULT WINAPI
MMCF_CreateInstance(
190 LPCLASSFACTORY iface
,
195 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
196 TRACE("(%p, %p, %s, %p)\n", This
, pOuter
, debugstr_guid(riid
), ppobj
);
199 return CLASS_E_NOAGGREGATION
;
202 WARN("invalid parameter\n");
206 return This
->pfnCreateInstance(riid
, ppobj
);
209 static HRESULT WINAPI
MMCF_LockServer(LPCLASSFACTORY iface
, BOOL dolock
)
211 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
212 FIXME("(%p, %d) stub!\n", This
, dolock
);
216 static const IClassFactoryVtbl MMCF_Vtbl
= {
224 static IClassFactoryImpl MMDEVAPI_CF
[] = {
225 { { &MMCF_Vtbl
}, &CLSID_MMDeviceEnumerator
, (FnCreateInstance
)MMDevEnum_Create
}
228 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
231 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
234 ERR("Driver initialization failed\n");
239 WARN("invalid parameter\n");
245 if (!IsEqualIID(riid
, &IID_IClassFactory
) &&
246 !IsEqualIID(riid
, &IID_IUnknown
)) {
247 WARN("no interface for %s\n", debugstr_guid(riid
));
248 return E_NOINTERFACE
;
251 for (i
= 0; i
< sizeof(MMDEVAPI_CF
)/sizeof(MMDEVAPI_CF
[0]); ++i
)
253 if (IsEqualGUID(rclsid
, MMDEVAPI_CF
[i
].rclsid
)) {
254 IUnknown_AddRef(&MMDEVAPI_CF
[i
].IClassFactory_iface
);
255 *ppv
= &MMDEVAPI_CF
[i
];
261 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid
),
262 debugstr_guid(riid
), ppv
);
263 return CLASS_E_CLASSNOTAVAILABLE
;
266 /***********************************************************************
267 * DllRegisterServer (MMDEVAPI.@)
269 HRESULT WINAPI
DllRegisterServer(void)
271 return __wine_register_resources( instance
, NULL
);
274 /***********************************************************************
275 * DllUnregisterServer (MMDEVAPI.@)
277 HRESULT WINAPI
DllUnregisterServer(void)
279 return __wine_unregister_resources( instance
, NULL
);