mirror of
https://github.com/encounter/SDL.git
synced 2025-12-13 07:06:10 +00:00
Use RoInitialize/RoUninitialize for Windows.Gaming.Input
Thanks @walbourn! Fixes https://github.com/libsdl-org/SDL/issues/5270
This commit is contained in:
@@ -565,22 +565,19 @@ RAWINPUT_InitWindowsGamingInput(RAWINPUT_DeviceContext *ctx)
|
||||
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())) {
|
||||
if (FAILED(WIN_RoInitialize())) {
|
||||
return;
|
||||
}
|
||||
wgi_state.initialized = SDL_TRUE;
|
||||
wgi_state.dirty = SDL_TRUE;
|
||||
|
||||
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);
|
||||
|
||||
WindowsCreateStringReference_t WindowsCreateStringReferenceFunc = (WindowsCreateStringReference_t)GetProcAddress(hModule, "WindowsCreateStringReference");
|
||||
RoGetActivationFactory_t RoGetActivationFactoryFunc = (RoGetActivationFactory_t)GetProcAddress(hModule, "RoGetActivationFactory");
|
||||
WindowsCreateStringReference_t WindowsCreateStringReferenceFunc = (WindowsCreateStringReference_t)WIN_LoadComBaseFunction("WindowsCreateStringReference");
|
||||
RoGetActivationFactory_t RoGetActivationFactoryFunc = (RoGetActivationFactory_t)WIN_LoadComBaseFunction("RoGetActivationFactory");
|
||||
if (WindowsCreateStringReferenceFunc && RoGetActivationFactoryFunc) {
|
||||
PCWSTR pNamespace = L"Windows.Gaming.Input.Gamepad";
|
||||
HSTRING_HEADER hNamespaceStringHeader;
|
||||
@@ -591,7 +588,6 @@ RAWINPUT_InitWindowsGamingInput(RAWINPUT_DeviceContext *ctx)
|
||||
RoGetActivationFactoryFunc(hNamespaceString, &SDL_IID_IGamepadStatics, (void **)&wgi_state.gamepad_statics);
|
||||
}
|
||||
}
|
||||
FreeLibrary(hModule);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -657,7 +653,7 @@ RAWINPUT_QuitWindowsGamingInput(RAWINPUT_DeviceContext *ctx)
|
||||
__x_ABI_CWindows_CGaming_CInput_CIGamepadStatics_Release(wgi_state.gamepad_statics);
|
||||
wgi_state.gamepad_statics = NULL;
|
||||
}
|
||||
WIN_CoUninitialize();
|
||||
WIN_RoUninitialize();
|
||||
wgi_state.initialized = SDL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,10 +260,9 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdde
|
||||
WindowsGetStringRawBufferFunc = WindowsGetStringRawBuffer;
|
||||
WindowsDeleteStringFunc = WindowsDeleteString;
|
||||
#else
|
||||
HMODULE hModule = LoadLibraryA("combase.dll");
|
||||
if (hModule != NULL) {
|
||||
WindowsGetStringRawBufferFunc = (WindowsGetStringRawBuffer_t)GetProcAddress(hModule, "WindowsGetStringRawBuffer");
|
||||
WindowsDeleteStringFunc = (WindowsDeleteString_t)GetProcAddress(hModule, "WindowsDeleteString");
|
||||
{
|
||||
WindowsGetStringRawBufferFunc = (WindowsGetStringRawBuffer_t)WIN_LoadComBaseFunction("WindowsGetStringRawBuffer");
|
||||
WindowsDeleteStringFunc = (WindowsDeleteString_t)WIN_LoadComBaseFunction("WindowsDeleteString");
|
||||
}
|
||||
#endif /* __WINRT__ */
|
||||
if (WindowsGetStringRawBufferFunc && WindowsDeleteStringFunc) {
|
||||
@@ -277,11 +276,6 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdde
|
||||
WindowsDeleteStringFunc(hString);
|
||||
}
|
||||
}
|
||||
#ifndef __WINRT__
|
||||
if (hModule != NULL) {
|
||||
FreeLibrary(hModule);
|
||||
}
|
||||
#endif
|
||||
__x_ABI_CWindows_CGaming_CInput_CIRawGameController2_Release(controller2);
|
||||
}
|
||||
if (!name) {
|
||||
@@ -444,23 +438,19 @@ WGI_JoystickInit(void)
|
||||
|
||||
WindowsCreateStringReference_t WindowsCreateStringReferenceFunc = NULL;
|
||||
RoGetActivationFactory_t RoGetActivationFactoryFunc = NULL;
|
||||
#ifndef __WINRT__
|
||||
HMODULE hModule;
|
||||
#endif
|
||||
HRESULT hr;
|
||||
|
||||
if (FAILED(WIN_CoInitialize())) {
|
||||
return SDL_SetError("CoInitialize() failed");
|
||||
if (FAILED(WIN_RoInitialize())) {
|
||||
return SDL_SetError("RoInitialize() failed");
|
||||
}
|
||||
|
||||
#ifdef __WINRT__
|
||||
WindowsCreateStringReferenceFunc = WindowsCreateStringReference;
|
||||
RoGetActivationFactoryFunc = RoGetActivationFactory;
|
||||
#else
|
||||
hModule = LoadLibraryA("combase.dll");
|
||||
if (hModule != NULL) {
|
||||
WindowsCreateStringReferenceFunc = (WindowsCreateStringReference_t)GetProcAddress(hModule, "WindowsCreateStringReference");
|
||||
RoGetActivationFactoryFunc = (RoGetActivationFactory_t)GetProcAddress(hModule, "RoGetActivationFactory");
|
||||
{
|
||||
WindowsCreateStringReferenceFunc = (WindowsCreateStringReference_t)WIN_LoadComBaseFunction("WindowsCreateStringReference");
|
||||
RoGetActivationFactoryFunc = (RoGetActivationFactory_t)WIN_LoadComBaseFunction("RoGetActivationFactory");
|
||||
}
|
||||
#endif /* __WINRT__ */
|
||||
if (WindowsCreateStringReferenceFunc && RoGetActivationFactoryFunc) {
|
||||
@@ -519,11 +509,6 @@ WGI_JoystickInit(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifndef __WINRT__
|
||||
if (hModule != NULL) {
|
||||
FreeLibrary(hModule);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (wgi.statics) {
|
||||
__FIVectorView_1_Windows__CGaming__CInput__CRawGameController *controllers;
|
||||
@@ -865,7 +850,7 @@ WGI_JoystickQuit(void)
|
||||
}
|
||||
SDL_zero(wgi);
|
||||
|
||||
WIN_CoUninitialize();
|
||||
WIN_RoUninitialize();
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
|
||||
Reference in New Issue
Block a user