Path: blob/master/thirdparty/sdl/core/windows/SDL_gameinput.c
9905 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/20#include "SDL_internal.h"2122#ifdef HAVE_GAMEINPUT_H2324#include "SDL_windows.h"25#include "SDL_gameinput.h"2627#ifdef SDL_PLATFORM_WIN3228#include <initguid.h>29// {11BE2A7E-4254-445A-9C09-FFC40F006918}30DEFINE_GUID(SDL_IID_GameInput, 0x11BE2A7E, 0x4254, 0x445A, 0x9C, 0x09, 0xFF, 0xC4, 0x0F, 0x00, 0x69, 0x18);31#endif3233static SDL_SharedObject *g_hGameInputDLL;34static IGameInput *g_pGameInput;35static int g_nGameInputRefCount;3637bool SDL_InitGameInput(IGameInput **ppGameInput)38{39if (g_nGameInputRefCount == 0) {40g_hGameInputDLL = SDL_LoadObject("gameinput.dll");41if (!g_hGameInputDLL) {42return false;43}4445typedef HRESULT (WINAPI *GameInputCreate_t)(IGameInput * *gameInput);46GameInputCreate_t GameInputCreateFunc = (GameInputCreate_t)SDL_LoadFunction(g_hGameInputDLL, "GameInputCreate");47if (!GameInputCreateFunc) {48SDL_UnloadObject(g_hGameInputDLL);49return false;50}5152IGameInput *pGameInput = NULL;53HRESULT hr = GameInputCreateFunc(&pGameInput);54if (FAILED(hr)) {55SDL_UnloadObject(g_hGameInputDLL);56return WIN_SetErrorFromHRESULT("GameInputCreate failed", hr);57}5859#ifdef SDL_PLATFORM_WIN3260hr = IGameInput_QueryInterface(pGameInput, &SDL_IID_GameInput, (void **)&g_pGameInput);61IGameInput_Release(pGameInput);62if (FAILED(hr)) {63SDL_UnloadObject(g_hGameInputDLL);64return WIN_SetErrorFromHRESULT("GameInput QueryInterface failed", hr);65}66#else67// Assume that the version we get is compatible with the current SDK68// If that isn't the case, define the correct GUID for SDL_IID_GameInput above69g_pGameInput = pGameInput;70#endif71}72++g_nGameInputRefCount;7374if (ppGameInput) {75*ppGameInput = g_pGameInput;76}77return true;78}7980void SDL_QuitGameInput(void)81{82SDL_assert(g_nGameInputRefCount > 0);8384--g_nGameInputRefCount;85if (g_nGameInputRefCount == 0) {86if (g_pGameInput) {87IGameInput_Release(g_pGameInput);88g_pGameInput = NULL;89}90if (g_hGameInputDLL) {91SDL_UnloadObject(g_hGameInputDLL);92g_hGameInputDLL = NULL;93}94}95}9697#endif // HAVE_GAMEINPUT_H9899100