Signed-off-by: Rémi Bernon rbernon@codeweavers.com ---
Not completely sure what was wrong with this patch but I've split it to avoid having non executed code and to leave the detail of COM aggregation for later.
dlls/windows.gaming.input/manager.c | 265 +++++++++++++++++++++++++++- dlls/windows.gaming.input/private.h | 1 + 2 files changed, 264 insertions(+), 2 deletions(-)
diff --git a/dlls/windows.gaming.input/manager.c b/dlls/windows.gaming.input/manager.c index e6366256fe7..15388f7df5d 100644 --- a/dlls/windows.gaming.input/manager.c +++ b/dlls/windows.gaming.input/manager.c @@ -18,12 +18,209 @@ */
#include "private.h" +#include "provider.h"
#include "wine/debug.h" #include "wine/list.h"
WINE_DEFAULT_DEBUG_CHANNEL(input);
+static CRITICAL_SECTION manager_cs; +static CRITICAL_SECTION_DEBUG manager_cs_debug = +{ + 0, 0, &manager_cs, + { &manager_cs_debug.ProcessLocksList, &manager_cs_debug.ProcessLocksList }, + 0, 0, { (DWORD_PTR)(__FILE__ ": manager_cs") } +}; +static CRITICAL_SECTION manager_cs = { &manager_cs_debug, -1, 0, 0, 0, 0 }; + +static struct list controller_list = LIST_INIT( controller_list ); + +struct controller +{ + IGameController IGameController_iface; + IGameControllerBatteryInfo IGameControllerBatteryInfo_iface; + LONG ref; + + struct list entry; + IGameControllerProvider *provider; + ICustomGameControllerFactory *factory; +}; + +static inline struct controller *impl_from_IGameController( IGameController *iface ) +{ + return CONTAINING_RECORD( iface, struct controller, IGameController_iface ); +} + +static HRESULT WINAPI controller_QueryInterface( IGameController *iface, REFIID iid, void **out ) +{ + struct controller *impl = impl_from_IGameController( iface ); + + TRACE( "iface %p, iid %s, out %p.\n", iface, debugstr_guid( iid ), out ); + + if (IsEqualGUID( iid, &IID_IUnknown ) || + IsEqualGUID( iid, &IID_IInspectable ) || + IsEqualGUID( iid, &IID_IAgileObject ) || + IsEqualGUID( iid, &IID_IGameController )) + { + IInspectable_AddRef( (*out = &impl->IGameController_iface) ); + return S_OK; + } + + if (IsEqualGUID( iid, &IID_IGameControllerBatteryInfo )) + { + IInspectable_AddRef( (*out = &impl->IGameControllerBatteryInfo_iface) ); + return S_OK; + } + + FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) ); + *out = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI controller_AddRef( IGameController *iface ) +{ + struct controller *impl = impl_from_IGameController( iface ); + ULONG ref = InterlockedIncrement( &impl->ref ); + TRACE( "iface %p increasing refcount to %lu.\n", iface, ref ); + return ref; +} + +static ULONG WINAPI controller_Release( IGameController *iface ) +{ + struct controller *impl = impl_from_IGameController( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + + TRACE( "iface %p decreasing refcount to %lu.\n", iface, ref ); + + if (!ref) + { + ICustomGameControllerFactory_Release( impl->factory ); + IGameControllerProvider_Release( impl->provider ); + free( impl ); + } + + return ref; +} + +static HRESULT WINAPI controller_GetIids( IGameController *iface, ULONG *iid_count, IID **iids ) +{ + FIXME( "iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids ); + return E_NOTIMPL; +} + +static HRESULT WINAPI controller_GetRuntimeClassName( IGameController *iface, HSTRING *class_name ) +{ + FIXME( "iface %p, class_name %p stub!\n", iface, class_name ); + return E_NOTIMPL; +} + +static HRESULT WINAPI controller_GetTrustLevel( IGameController *iface, TrustLevel *trust_level ) +{ + FIXME( "iface %p, trust_level %p stub!\n", iface, trust_level ); + return E_NOTIMPL; +} + +static HRESULT WINAPI controller_add_HeadsetConnected( IGameController *iface, ITypedEventHandler_IGameController_Headset *handler, + EventRegistrationToken *token ) +{ + FIXME( "iface %p, handler %p, token %p stub!\n", iface, handler, token ); + return E_NOTIMPL; +} + +static HRESULT WINAPI controller_remove_HeadsetConnected( IGameController *iface, EventRegistrationToken token ) +{ + FIXME( "iface %p, token %I64x stub!\n", iface, token.value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI controller_add_HeadsetDisconnected( IGameController *iface, ITypedEventHandler_IGameController_Headset *handler, + EventRegistrationToken *token ) +{ + FIXME( "iface %p, handler %p, token %p stub!\n", iface, handler, token ); + return E_NOTIMPL; +} + +static HRESULT WINAPI controller_remove_HeadsetDisconnected( IGameController *iface, EventRegistrationToken token ) +{ + FIXME( "iface %p, token %I64x stub!\n", iface, token.value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI controller_add_UserChanged( IGameController *iface, + ITypedEventHandler_IGameController_UserChangedEventArgs *handler, + EventRegistrationToken *token ) +{ + FIXME( "iface %p, handler %p, token %p stub!\n", iface, handler, token ); + return E_NOTIMPL; +} + +static HRESULT WINAPI controller_remove_UserChanged( IGameController *iface, EventRegistrationToken token ) +{ + FIXME( "iface %p, token %I64x stub!\n", iface, token.value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI controller_get_Headset( IGameController *iface, IHeadset **value ) +{ + FIXME( "iface %p, value %p stub!\n", iface, value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI controller_get_IsWireless( IGameController *iface, boolean *value ) +{ + FIXME( "iface %p, value %p stub!\n", iface, value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI controller_get_User( IGameController *iface, __x_ABI_CWindows_CSystem_CIUser **value ) +{ + FIXME( "iface %p, value %p stub!\n", iface, value ); + return E_NOTIMPL; +} + +static const struct IGameControllerVtbl controller_vtbl = +{ + controller_QueryInterface, + controller_AddRef, + controller_Release, + /* IInspectable methods */ + controller_GetIids, + controller_GetRuntimeClassName, + controller_GetTrustLevel, + /* IGameController methods */ + controller_add_HeadsetConnected, + controller_remove_HeadsetConnected, + controller_add_HeadsetDisconnected, + controller_remove_HeadsetDisconnected, + controller_add_UserChanged, + controller_remove_UserChanged, + controller_get_Headset, + controller_get_IsWireless, + controller_get_User, +}; + +DEFINE_IINSPECTABLE( battery, IGameControllerBatteryInfo, struct controller, IGameController_iface ) + +static HRESULT WINAPI battery_TryGetBatteryReport( IGameControllerBatteryInfo *iface, IBatteryReport **value ) +{ + FIXME( "iface %p, value %p stub!\n", iface, value ); + return E_NOTIMPL; +} + +static const struct IGameControllerBatteryInfoVtbl battery_vtbl = +{ + battery_QueryInterface, + battery_AddRef, + battery_Release, + /* IInspectable methods */ + battery_GetIids, + battery_GetRuntimeClassName, + battery_GetTrustLevel, + /* IGameControllerBatteryInfo methods */ + battery_TryGetBatteryReport, +}; + struct manager_statics { IActivationFactory IActivationFactory_iface; @@ -200,12 +397,76 @@ static struct manager_statics manager_statics =
IActivationFactory *manager_factory = &manager_statics.IActivationFactory_iface;
+static HRESULT controller_create( ICustomGameControllerFactory *factory, IGameControllerProvider *provider, + struct controller **out ) +{ + struct controller *impl; + + if (!(impl = malloc(sizeof(*impl)))) return E_OUTOFMEMORY; + impl->IGameController_iface.lpVtbl = &controller_vtbl; + impl->IGameControllerBatteryInfo_iface.lpVtbl = &battery_vtbl; + impl->ref = 1; + + ICustomGameControllerFactory_AddRef( (impl->factory = factory) ); + IGameControllerProvider_AddRef( (impl->provider = provider) ); + + *out = impl; + return S_OK; +} + void manager_on_provider_created( IGameControllerProvider *provider ) { - FIXME( "provider %p stub!\n", provider ); + struct list *entry, *next, *list; + struct controller *controller; + HRESULT hr; + + TRACE( "provider %p\n", provider ); + + EnterCriticalSection( &manager_cs ); + + if (list_empty( &controller_list )) list = &controller_list; + else list = list_tail( &controller_list ); + + if (SUCCEEDED(controller_create( controller_factory, provider, &controller ))) + list_add_tail( &controller_list, &controller->entry ); + + LIST_FOR_EACH_SAFE( entry, next, list ) + { + controller = LIST_ENTRY( entry, struct controller, entry ); + hr = ICustomGameControllerFactory_OnGameControllerAdded( controller->factory, + &controller->IGameController_iface ); + if (FAILED(hr)) + { + list_remove( &controller->entry ); + IGameController_Release( &controller->IGameController_iface ); + } + if (next == &controller_list) break; + } + + LeaveCriticalSection( &manager_cs ); }
void manager_on_provider_removed( IGameControllerProvider *provider ) { - FIXME( "provider %p stub!\n", provider ); + struct controller *controller, *next; + + TRACE( "provider %p\n", provider ); + + EnterCriticalSection( &manager_cs ); + + LIST_FOR_EACH_ENTRY( controller, &controller_list, struct controller, entry ) + { + if (controller->provider != provider) continue; + ICustomGameControllerFactory_OnGameControllerRemoved( controller->factory, + &controller->IGameController_iface ); + } + + LIST_FOR_EACH_ENTRY_SAFE( controller, next, &controller_list, struct controller, entry ) + { + if (controller->provider != provider) continue; + list_remove( &controller->entry ); + IGameController_Release( &controller->IGameController_iface ); + } + + LeaveCriticalSection( &manager_cs ); } diff --git a/dlls/windows.gaming.input/private.h b/dlls/windows.gaming.input/private.h index 24d0609aa7e..27dbdb8416c 100644 --- a/dlls/windows.gaming.input/private.h +++ b/dlls/windows.gaming.input/private.h @@ -31,6 +31,7 @@ #define WIDL_using_Windows_Foundation #define WIDL_using_Windows_Foundation_Collections #include "windows.foundation.h" +#define WIDL_using_Windows_Devices_Power #define WIDL_using_Windows_Gaming_Input #define WIDL_using_Windows_Gaming_Input_Custom #include "windows.gaming.input.custom.h"
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/windows.gaming.input/controller.c | 16 +++++++++++++-- dlls/windows.gaming.input/main.c | 7 +++---- dlls/windows.gaming.input/manager.c | 27 +++++++++++++++++++++++--- dlls/windows.gaming.input/private.h | 2 +- 4 files changed, 42 insertions(+), 10 deletions(-)
diff --git a/dlls/windows.gaming.input/controller.c b/dlls/windows.gaming.input/controller.c index 27c5d6ebd32..94343c0927d 100644 --- a/dlls/windows.gaming.input/controller.c +++ b/dlls/windows.gaming.input/controller.c @@ -174,8 +174,20 @@ static HRESULT WINAPI statics_get_RawGameControllers( IRawGameControllerStatics static HRESULT WINAPI statics_FromGameController( IRawGameControllerStatics *iface, IGameController *game_controller, IRawGameController **value ) { - FIXME( "iface %p, game_controller %p, value %p stub!\n", iface, game_controller, value ); - return E_NOTIMPL; + struct controller_statics *impl = impl_from_IRawGameControllerStatics( iface ); + IGameController *controller; + HRESULT hr; + + TRACE( "iface %p, game_controller %p, value %p.\n", iface, game_controller, value ); + + hr = IGameControllerFactoryManagerStatics2_TryGetFactoryControllerFromGameController( manager_factory, &impl->ICustomGameControllerFactory_iface, + game_controller, &controller ); + if (FAILED(hr)) return hr; + + hr = IGameController_QueryInterface( controller, &IID_IRawGameController, (void **)value ); + IGameController_Release( controller ); + + return hr; }
static const struct IRawGameControllerStaticsVtbl statics_vtbl = diff --git a/dlls/windows.gaming.input/main.c b/dlls/windows.gaming.input/main.c index e71043fcb0f..c5b7f19c987 100644 --- a/dlls/windows.gaming.input/main.c +++ b/dlls/windows.gaming.input/main.c @@ -169,7 +169,7 @@ HRESULT WINAPI DllGetActivationFactory( HSTRING class_str, IActivationFactory ** { static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT; const WCHAR *buffer = WindowsGetStringRawBuffer( class_str, NULL ); - HRESULT hr = S_OK; + HRESULT hr = REGDB_E_CLASSNOTREG;
TRACE( "class %s, factory %p.\n", debugstr_w(buffer), factory );
@@ -182,10 +182,9 @@ HRESULT WINAPI DllGetActivationFactory( HSTRING class_str, IActivationFactory ** if (!wcscmp( buffer, RuntimeClass_Windows_Gaming_Input_Gamepad )) hr = ICustomGameControllerFactory_QueryInterface( gamepad_factory, &IID_IActivationFactory, (void **)factory ); if (!wcscmp( buffer, RuntimeClass_Windows_Gaming_Input_Custom_GameControllerFactoryManager )) - IActivationFactory_AddRef( (*factory = manager_factory) ); + hr = IGameControllerFactoryManagerStatics2_QueryInterface( manager_factory, &IID_IActivationFactory, (void **)factory );
- if (SUCCEEDED(hr) && *factory) return S_OK; - return REGDB_E_CLASSNOTREG; + return hr; }
BOOL WINAPI DllMain( HINSTANCE instance, DWORD reason, void *reserved ) diff --git a/dlls/windows.gaming.input/manager.c b/dlls/windows.gaming.input/manager.c index 15388f7df5d..33f2a3c3df9 100644 --- a/dlls/windows.gaming.input/manager.c +++ b/dlls/windows.gaming.input/manager.c @@ -370,8 +370,29 @@ statics2_TryGetFactoryControllerFromGameController( IGameControllerFactoryManage ICustomGameControllerFactory *factory, IGameController *controller, IGameController **value ) { - FIXME( "iface %p, factory %p, controller %p, value %p stub!\n", iface, factory, controller, value ); - return E_NOTIMPL; + struct controller *entry, *other; + BOOL found = FALSE; + + TRACE( "iface %p, factory %p, controller %p, value %p.\n", iface, factory, controller, value ); + + EnterCriticalSection( &manager_cs ); + + LIST_FOR_EACH_ENTRY( entry, &controller_list, struct controller, entry ) + if ((found = &entry->IGameController_iface == controller)) break; + + if (!found) WARN( "Failed to find controller %p\n", controller ); + else + { + LIST_FOR_EACH_ENTRY( other, &controller_list, struct controller, entry ) + if ((found = entry->provider == other->provider && other->factory == factory)) break; + if (!found) WARN( "Failed to find controller %p, factory %p\n", controller, factory ); + else IGameController_AddRef( (*value = &other->IGameController_iface) ); + } + + LeaveCriticalSection( &manager_cs ); + + if (!found) return E_FAIL; + return S_OK; }
static const struct IGameControllerFactoryManagerStatics2Vtbl statics2_vtbl = @@ -395,7 +416,7 @@ static struct manager_statics manager_statics = 1, };
-IActivationFactory *manager_factory = &manager_statics.IActivationFactory_iface; +IGameControllerFactoryManagerStatics2 *manager_factory = &manager_statics.IGameControllerFactoryManagerStatics2_iface;
static HRESULT controller_create( ICustomGameControllerFactory *factory, IGameControllerProvider *provider, struct controller **out ) diff --git a/dlls/windows.gaming.input/private.h b/dlls/windows.gaming.input/private.h index 27dbdb8416c..56d03abad44 100644 --- a/dlls/windows.gaming.input/private.h +++ b/dlls/windows.gaming.input/private.h @@ -39,7 +39,7 @@ extern HINSTANCE windows_gaming_input; extern ICustomGameControllerFactory *controller_factory; extern ICustomGameControllerFactory *gamepad_factory; -extern IActivationFactory *manager_factory; +extern IGameControllerFactoryManagerStatics2 *manager_factory;
extern HRESULT vector_create( REFIID iid, REFIID view_iid, void **out );
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/windows.gaming.input/manager.c | 24 ++++++++++++++++++++++++ dlls/windows.gaming.input/provider.c | 21 +++++++++++++++++++++ dlls/windows.gaming.input/provider.idl | 8 ++++++++ 3 files changed, 53 insertions(+)
diff --git a/dlls/windows.gaming.input/manager.c b/dlls/windows.gaming.input/manager.c index 33f2a3c3df9..f5b5654a4c6 100644 --- a/dlls/windows.gaming.input/manager.c +++ b/dlls/windows.gaming.input/manager.c @@ -437,12 +437,27 @@ static HRESULT controller_create( ICustomGameControllerFactory *factory, IGameCo
void manager_on_provider_created( IGameControllerProvider *provider ) { + IWineGameControllerProvider *wine_provider; struct list *entry, *next, *list; struct controller *controller; + WineGameControllerType type; HRESULT hr;
TRACE( "provider %p\n", provider );
+ if (FAILED(IGameControllerProvider_QueryInterface( provider, &IID_IWineGameControllerProvider, + (void **)&wine_provider ))) + { + FIXME( "IWineGameControllerProvider isn't implemented by provider %p\n", provider ); + return; + } + if (FAILED(hr = IWineGameControllerProvider_get_Type( wine_provider, &type ))) + { + WARN( "Failed to get controller type, hr %#lx\n", hr ); + type = WineGameControllerType_Joystick; + } + IWineGameControllerProvider_Release( wine_provider ); + EnterCriticalSection( &manager_cs );
if (list_empty( &controller_list )) list = &controller_list; @@ -451,6 +466,15 @@ void manager_on_provider_created( IGameControllerProvider *provider ) if (SUCCEEDED(controller_create( controller_factory, provider, &controller ))) list_add_tail( &controller_list, &controller->entry );
+ switch (type) + { + case WineGameControllerType_Joystick: break; + case WineGameControllerType_Gamepad: + if (SUCCEEDED(controller_create( gamepad_factory, provider, &controller ))) + list_add_tail( &controller_list, &controller->entry ); + break; + } + LIST_FOR_EACH_SAFE( entry, next, list ) { controller = LIST_ENTRY( entry, struct controller, entry ); diff --git a/dlls/windows.gaming.input/provider.c b/dlls/windows.gaming.input/provider.c index 9ab9682f221..b4817b42c46 100644 --- a/dlls/windows.gaming.input/provider.c +++ b/dlls/windows.gaming.input/provider.c @@ -125,6 +125,25 @@ static HRESULT WINAPI wine_provider_GetTrustLevel( IWineGameControllerProvider * return E_NOTIMPL; }
+static HRESULT WINAPI wine_provider_get_Type( IWineGameControllerProvider *iface, WineGameControllerType *value ) +{ + struct provider *impl = impl_from_IWineGameControllerProvider( iface ); + DIDEVICEINSTANCEW instance = {.dwSize = sizeof(DIDEVICEINSTANCEW)}; + HRESULT hr; + + TRACE( "iface %p, value %p.\n", iface, value ); + + if (FAILED(hr = IDirectInputDevice8_GetDeviceInfo( impl->dinput_device, &instance ))) return hr; + + switch (GET_DIDEVICE_TYPE( instance.dwDevType )) + { + case DI8DEVTYPE_GAMEPAD: *value = WineGameControllerType_Gamepad; break; + default: *value = WineGameControllerType_Joystick; break; + } + + return S_OK; +} + static const struct IWineGameControllerProviderVtbl wine_provider_vtbl = { wine_provider_QueryInterface, @@ -134,6 +153,8 @@ static const struct IWineGameControllerProviderVtbl wine_provider_vtbl = wine_provider_GetIids, wine_provider_GetRuntimeClassName, wine_provider_GetTrustLevel, + /* IWineGameControllerProvider methods */ + wine_provider_get_Type, };
DEFINE_IINSPECTABLE( game_provider, IGameControllerProvider, struct provider, IWineGameControllerProvider_iface ) diff --git a/dlls/windows.gaming.input/provider.idl b/dlls/windows.gaming.input/provider.idl index d6c4f1d16ec..6af700bb12d 100644 --- a/dlls/windows.gaming.input/provider.idl +++ b/dlls/windows.gaming.input/provider.idl @@ -31,9 +31,16 @@ import "windows.gaming.input.idl"; import "windows.gaming.input.custom.idl";
namespace Windows.Gaming.Input.Custom { + typedef enum WineGameControllerType WineGameControllerType; interface IWineGameControllerProvider; runtimeclass WineGameControllerProvider;
+ enum WineGameControllerType + { + Joystick = 0, + Gamepad = 1, + }; + [ uuid(06e58977-7684-4dc5-bad1-cda52a4aa06d) ] @@ -51,6 +58,7 @@ namespace Windows.Gaming.Input.Custom { interface IWineGameControllerProvider : IInspectable requires Windows.Gaming.Input.Custom.IGameControllerProvider { + [propget] HRESULT Type([out, retval] WineGameControllerType *value); }
[
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- include/windows.gaming.input.idl | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/include/windows.gaming.input.idl b/include/windows.gaming.input.idl index 6a5fc8af1ee..5bf94f78820 100644 --- a/include/windows.gaming.input.idl +++ b/include/windows.gaming.input.idl @@ -293,6 +293,18 @@ namespace Windows.Gaming.Input { [propget] HRESULT Gamepads([out, retval] Windows.Foundation.Collections.IVectorView<Gamepad *> **value); }
+ [ + contract(Windows.Foundation.UniversalApiContract, 4.0), + exclusiveto(Windows.Gaming.Input.Gamepad), + uuid(42676dc5-0856-47c4-9213-b395504c3a3c) + ] + interface IGamepadStatics2 : IInspectable + requires Windows.Gaming.Input.IGamepadStatics + { + HRESULT FromGameController([in] Windows.Gaming.Input.IGameController *controller, + [out, retval] Windows.Gaming.Input.Gamepad **value); + } + [ contract(Windows.Foundation.UniversalApiContract, 1.0), exclusiveto(Windows.Gaming.Input.Headset),
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/windows.gaming.input/gamepad.c | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
diff --git a/dlls/windows.gaming.input/gamepad.c b/dlls/windows.gaming.input/gamepad.c index 3793021d22c..50008541281 100644 --- a/dlls/windows.gaming.input/gamepad.c +++ b/dlls/windows.gaming.input/gamepad.c @@ -27,6 +27,7 @@ struct gamepad_statics { IActivationFactory IActivationFactory_iface; IGamepadStatics IGamepadStatics_iface; + IGamepadStatics2 IGamepadStatics2_iface; ICustomGameControllerFactory ICustomGameControllerFactory_iface; LONG ref; }; @@ -57,6 +58,12 @@ static HRESULT WINAPI factory_QueryInterface( IActivationFactory *iface, REFIID return S_OK; }
+ if (IsEqualGUID( iid, &IID_IGamepadStatics2 )) + { + IInspectable_AddRef( (*out = &impl->IGamepadStatics2_iface) ); + return S_OK; + } + if (IsEqualGUID( iid, &IID_ICustomGameControllerFactory )) { IInspectable_AddRef( (*out = &impl->ICustomGameControllerFactory_iface) ); @@ -188,6 +195,38 @@ static const struct IGamepadStaticsVtbl statics_vtbl = statics_get_Gamepads, };
+DEFINE_IINSPECTABLE( statics2, IGamepadStatics2, struct gamepad_statics, IActivationFactory_iface ) + +static HRESULT WINAPI statics2_FromGameController( IGamepadStatics2 *iface, IGameController *game_controller, IGamepad **value ) +{ + struct gamepad_statics *impl = impl_from_IGamepadStatics2( iface ); + IGameController *controller; + HRESULT hr; + + TRACE( "iface %p, game_controller %p, value %p.\n", iface, game_controller, value ); + + hr = IGameControllerFactoryManagerStatics2_TryGetFactoryControllerFromGameController( manager_factory, &impl->ICustomGameControllerFactory_iface, + game_controller, &controller ); + if (FAILED(hr)) return hr; + + hr = IGameController_QueryInterface( controller, &IID_IGamepad, (void **)value ); + IGameController_Release( controller ); + return hr; +} + +static const struct IGamepadStatics2Vtbl statics2_vtbl = +{ + statics2_QueryInterface, + statics2_AddRef, + statics2_Release, + /* IInspectable methods */ + statics2_GetIids, + statics2_GetRuntimeClassName, + statics2_GetTrustLevel, + /* IGamepadStatics2 methods */ + statics2_FromGameController, +}; + DEFINE_IINSPECTABLE( controller_factory, ICustomGameControllerFactory, struct gamepad_statics, IActivationFactory_iface )
static HRESULT WINAPI controller_factory_CreateGameController( ICustomGameControllerFactory *iface, IGameControllerProvider *provider, @@ -228,6 +267,7 @@ static struct gamepad_statics gamepad_statics = { {&factory_vtbl}, {&statics_vtbl}, + {&statics2_vtbl}, {&controller_factory_vtbl}, 1, };