From 3eb9bfac7ad1a1dc75d514d6dd0e95007602e6a5 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Sun, 14 Nov 2021 22:22:50 +0300 Subject: [PATCH] win32 rawinput & wgi joystick: avoid -Werror=declaration-after-statement --- src/joystick/windows/SDL_rawinputjoystick.c | 16 ++++++++++------ src/joystick/windows/SDL_windows_gaming_input.c | 8 +++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c index 5765686ab..12dd1e7a4 100644 --- a/src/joystick/windows/SDL_rawinputjoystick.c +++ b/src/joystick/windows/SDL_rawinputjoystick.c @@ -452,12 +452,12 @@ RAWINPUT_UpdateWindowsGamingInput() wgi_state.dirty = SDL_FALSE; if (wgi_state.need_device_list_update) { + HRESULT hr; + __FIVectorView_1_Windows__CGaming__CInput__CGamepad *gamepads; wgi_state.need_device_list_update = SDL_FALSE; for (ii = 0; ii < wgi_state.per_gamepad_count; ii++) { wgi_state.per_gamepad[ii]->connected = SDL_FALSE; } - HRESULT hr; - __FIVectorView_1_Windows__CGaming__CInput__CGamepad *gamepads; hr = __x_ABI_CWindows_CGaming_CInput_CIGamepadStatics_get_Gamepads(wgi_state.gamepad_statics, &gamepads); if (SUCCEEDED(hr)) { @@ -482,13 +482,15 @@ RAWINPUT_UpdateWindowsGamingInput() } if (!found) { /* New device, add it */ + WindowsGamingInputGamepadState *gamepad_state; + wgi_state.per_gamepad_count++; wgi_state.per_gamepad = SDL_realloc(wgi_state.per_gamepad, sizeof(wgi_state.per_gamepad[0]) * wgi_state.per_gamepad_count); if (!wgi_state.per_gamepad) { SDL_OutOfMemory(); return; } - WindowsGamingInputGamepadState *gamepad_state = SDL_calloc(1, sizeof(*gamepad_state)); + gamepad_state = SDL_calloc(1, sizeof(*gamepad_state)); if (!gamepad_state) { SDL_OutOfMemory(); return; @@ -534,6 +536,10 @@ RAWINPUT_InitWindowsGamingInput(RAWINPUT_DeviceContext *ctx) wgi_state.need_device_list_update = SDL_TRUE; wgi_state.ref_count++; if (!wgi_state.initialized) { + static const IID SDL_IID_IGamepadStatics = { 0x8BBCE529, 0xD49C, 0x39E9, { 0x95, 0x60, 0xE4, 0x7D, 0xDE, 0x96, 0xB7, 0xC8 } }; + HRESULT hr; + HMODULE hModule; + /* I think this takes care of RoInitialize() in a way that is compatible with the rest of SDL */ if (FAILED(WIN_CoInitialize())) { return; @@ -541,9 +547,7 @@ RAWINPUT_InitWindowsGamingInput(RAWINPUT_DeviceContext *ctx) wgi_state.initialized = SDL_TRUE; wgi_state.dirty = SDL_TRUE; - static const IID SDL_IID_IGamepadStatics = { 0x8BBCE529, 0xD49C, 0x39E9, { 0x95, 0x60, 0xE4, 0x7D, 0xDE, 0x96, 0xB7, 0xC8 } }; - HRESULT hr; - HMODULE hModule = LoadLibraryA("combase.dll"); + hModule = LoadLibraryA("combase.dll"); if (hModule != NULL) { typedef HRESULT (WINAPI *WindowsCreateStringReference_t)(PCWSTR sourceString, UINT32 length, HSTRING_HEADER *hstringHeader, HSTRING* string); typedef HRESULT (WINAPI *RoGetActivationFactory_t)(HSTRING activatableClassId, REFIID iid, void** factory); diff --git a/src/joystick/windows/SDL_windows_gaming_input.c b/src/joystick/windows/SDL_windows_gaming_input.c index 33b4eb5a0..950fe7cd8 100644 --- a/src/joystick/windows/SDL_windows_gaming_input.c +++ b/src/joystick/windows/SDL_windows_gaming_input.c @@ -103,7 +103,7 @@ SDL_IsXInputDevice(Uint16 vendor, Uint16 product) #ifdef SDL_JOYSTICK_RAWINPUT && !RAWINPUT_IsEnabled() #endif - ) { + ) { return SDL_FALSE; } @@ -424,12 +424,14 @@ static __FIEventHandler_1_Windows__CGaming__CInput__CRawGameController controlle static int WGI_JoystickInit(void) { + HMODULE hModule; + HRESULT hr; + if (FAILED(WIN_CoInitialize())) { return SDL_SetError("CoInitialize() failed"); } - HRESULT hr; - HMODULE hModule = LoadLibraryA("combase.dll"); + hModule = LoadLibraryA("combase.dll"); if (hModule != NULL) { typedef HRESULT (WINAPI *WindowsCreateStringReference_t)(PCWSTR sourceString, UINT32 length, HSTRING_HEADER *hstringHeader, HSTRING* string); typedef HRESULT (WINAPI *WindowsDeleteString_t)(HSTRING string);