Atlas - SDL_gameinput.cpp
Home / ext / SDL / src / core / windows Lines: 1 | Size: 3009 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21#include "SDL_internal.h" 22 23#ifdef HAVE_GAMEINPUT_H 24 25#include "SDL_windows.h" 26#include "SDL_gameinput.h" 27 28static SDL_SharedObject *g_hGameInputDLL; 29static IGameInput *g_pGameInput; 30static int g_nGameInputRefCount; 31 32 33bool SDL_InitGameInput(IGameInput **ppGameInput) 34{ 35 if (g_nGameInputRefCount == 0) { 36 g_hGameInputDLL = SDL_LoadObject("gameinput.dll"); 37 if (!g_hGameInputDLL) { 38 return false; 39 } 40 41 typedef HRESULT (WINAPI *pfnGameInputCreate)(IGameInput **gameInput); 42 pfnGameInputCreate pGameInputCreate = (pfnGameInputCreate)SDL_LoadFunction(g_hGameInputDLL, "GameInputCreate"); 43 if (!pGameInputCreate) { 44 SDL_UnloadObject(g_hGameInputDLL); 45 return false; 46 } 47 48 IGameInput *pGameInput = NULL; 49 HRESULT hr = pGameInputCreate(&pGameInput); 50 if (FAILED(hr)) { 51 SDL_UnloadObject(g_hGameInputDLL); 52 return WIN_SetErrorFromHRESULT("GameInputCreate failed", hr); 53 } 54 55#ifdef SDL_PLATFORM_WIN32 56#if GAMEINPUT_API_VERSION >= 1 57 hr = pGameInput->QueryInterface(IID_IGameInput, (void **)&g_pGameInput); 58#else 59 // We require GameInput v1.1 or newer 60 hr = E_NOINTERFACE; 61#endif 62 pGameInput->Release(); 63 if (FAILED(hr)) { 64 SDL_UnloadObject(g_hGameInputDLL); 65 return WIN_SetErrorFromHRESULT("GameInput QueryInterface failed", hr); 66 } 67#else 68 // Assume that the version we get is compatible with the current SDK 69 g_pGameInput = pGameInput; 70#endif 71 } 72 ++g_nGameInputRefCount; 73 74 if (ppGameInput) { 75 *ppGameInput = g_pGameInput; 76 } 77 return true; 78} 79 80void SDL_QuitGameInput(void) 81{ 82 SDL_assert(g_nGameInputRefCount > 0); 83 84 --g_nGameInputRefCount; 85 if (g_nGameInputRefCount == 0) { 86 if (g_pGameInput) { 87 g_pGameInput->Release(); 88 g_pGameInput = NULL; 89 } 90 if (g_hGameInputDLL) { 91 SDL_UnloadObject(g_hGameInputDLL); 92 g_hGameInputDLL = NULL; 93 } 94 } 95} 96 97#endif // HAVE_GAMEINPUT_H 98[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.