winebus.sys: Move SDL function loading to a separate helper.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2021-08-13 09:46:17 +02:00 committed by Alexandre Julliard
parent 5d6419a53c
commit 90b8a97237
1 changed files with 64 additions and 52 deletions

View File

@ -968,22 +968,19 @@ void sdl_driver_unload( void )
dlclose(sdl_handle);
}
NTSTATUS sdl_driver_init(void)
static BOOL sdl_initialize(void)
{
static const WCHAR controller_modeW[] = {'M','a','p',' ','C','o','n','t','r','o','l','l','e','r','s',0};
static const UNICODE_STRING controller_mode = {sizeof(controller_modeW) - sizeof(WCHAR), sizeof(controller_modeW), (WCHAR*)controller_modeW};
HANDLE events[2];
DWORD result;
if (sdl_handle == NULL)
if (!(sdl_handle = dlopen(SONAME_LIBSDL2, RTLD_NOW)))
{
sdl_handle = dlopen(SONAME_LIBSDL2, RTLD_NOW);
if (!sdl_handle) {
WARN("could not load %s\n", SONAME_LIBSDL2);
return STATUS_UNSUCCESSFUL;
return FALSE;
}
#define LOAD_FUNCPTR(f) \
if ((p##f = dlsym(sdl_handle, #f)) == NULL) \
{ \
WARN("could not find symbol %s\n", #f); \
goto failed; \
}
#define LOAD_FUNCPTR(f) if((p##f = dlsym(sdl_handle, #f)) == NULL){WARN("Can't find symbol %s\n", #f); goto sym_not_found;}
LOAD_FUNCPTR(SDL_GetError);
LOAD_FUNCPTR(SDL_Init);
LOAD_FUNCPTR(SDL_JoystickClose);
@ -1026,8 +1023,24 @@ NTSTATUS sdl_driver_init(void)
pSDL_JoystickGetProduct = dlsym(sdl_handle, "SDL_JoystickGetProduct");
pSDL_JoystickGetProductVersion = dlsym(sdl_handle, "SDL_JoystickGetProductVersion");
pSDL_JoystickGetVendor = dlsym(sdl_handle, "SDL_JoystickGetVendor");
return TRUE;
failed:
dlclose(sdl_handle);
sdl_handle = NULL;
return FALSE;
}
NTSTATUS sdl_driver_init(void)
{
static const WCHAR controller_modeW[] = {'M','a','p',' ','C','o','n','t','r','o','l','l','e','r','s',0};
static const UNICODE_STRING controller_mode = {sizeof(controller_modeW) - sizeof(WCHAR), sizeof(controller_modeW), (WCHAR*)controller_modeW};
HANDLE events[2];
DWORD result;
if (!sdl_handle && !sdl_initialize()) return STATUS_UNSUCCESSFUL;
map_controllers = check_bus_option(&controller_mode, 1);
if (!(events[0] = CreateEventW(NULL, TRUE, FALSE, NULL)))
@ -1052,7 +1065,6 @@ NTSTATUS sdl_driver_init(void)
}
CloseHandle(events[1]);
sym_not_found:
dlclose(sdl_handle);
sdl_handle = NULL;
return STATUS_UNSUCCESSFUL;