[PATCH v3 1/7] windows.gaming.input: Introduce helpers to define IInspectable interface boilerplate.

Rémi Bernon rbernon at codeweavers.com
Wed Mar 2 07:03:01 CST 2022


Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---

v3: Fix test failure in PATCH 7, IGameControllerImpl really needs to be
    the inner IInspectable iface instead of an additional iface, as the
    runtime queries it then calls Initialize to provide the outer iface.

 dlls/windows.gaming.input/controller.c | 41 +-------------------------
 dlls/windows.gaming.input/gamepad.c    | 41 +-------------------------
 dlls/windows.gaming.input/private.h    | 36 ++++++++++++++++++++++
 3 files changed, 38 insertions(+), 80 deletions(-)

diff --git a/dlls/windows.gaming.input/controller.c b/dlls/windows.gaming.input/controller.c
index 00ab9c5d91c..654d0795eac 100644
--- a/dlls/windows.gaming.input/controller.c
+++ b/dlls/windows.gaming.input/controller.c
@@ -35,11 +35,6 @@ static inline struct controller_statics *impl_from_IActivationFactory( IActivati
     return CONTAINING_RECORD( iface, struct controller_statics, IActivationFactory_iface );
 }
 
-static inline struct controller_statics *impl_from_IRawGameControllerStatics( IRawGameControllerStatics *iface )
-{
-    return CONTAINING_RECORD( iface, struct controller_statics, IRawGameControllerStatics_iface );
-}
-
 static HRESULT WINAPI factory_QueryInterface( IActivationFactory *iface, REFIID iid, void **out )
 {
     struct controller_statics *impl = impl_from_IActivationFactory( iface );
@@ -121,41 +116,7 @@ static const struct IActivationFactoryVtbl factory_vtbl =
     factory_ActivateInstance,
 };
 
-static HRESULT WINAPI statics_QueryInterface( IRawGameControllerStatics *iface, REFIID iid, void **out )
-{
-    struct controller_statics *impl = impl_from_IRawGameControllerStatics( iface );
-    return IActivationFactory_QueryInterface( &impl->IActivationFactory_iface, iid, out );
-}
-
-static ULONG WINAPI statics_AddRef( IRawGameControllerStatics *iface )
-{
-    struct controller_statics *impl = impl_from_IRawGameControllerStatics( iface );
-    return IActivationFactory_AddRef( &impl->IActivationFactory_iface );
-}
-
-static ULONG WINAPI statics_Release( IRawGameControllerStatics *iface )
-{
-    struct controller_statics *impl = impl_from_IRawGameControllerStatics( iface );
-    return IActivationFactory_Release( &impl->IActivationFactory_iface );
-}
-
-static HRESULT WINAPI statics_GetIids( IRawGameControllerStatics *iface, ULONG *iid_count, IID **iids )
-{
-    struct controller_statics *impl = impl_from_IRawGameControllerStatics( iface );
-    return IActivationFactory_Release( &impl->IActivationFactory_iface );
-}
-
-static HRESULT WINAPI statics_GetRuntimeClassName( IRawGameControllerStatics *iface, HSTRING *class_name )
-{
-    struct controller_statics *impl = impl_from_IRawGameControllerStatics( iface );
-    return IActivationFactory_Release( &impl->IActivationFactory_iface );
-}
-
-static HRESULT WINAPI statics_GetTrustLevel( IRawGameControllerStatics *iface, TrustLevel *trust_level )
-{
-    struct controller_statics *impl = impl_from_IRawGameControllerStatics( iface );
-    return IActivationFactory_Release( &impl->IActivationFactory_iface );
-}
+DEFINE_IINSPECTABLE( statics, IRawGameControllerStatics, struct controller_statics, IActivationFactory_iface )
 
 static HRESULT WINAPI statics_add_RawGameControllerAdded( IRawGameControllerStatics *iface, IEventHandler_RawGameController *value,
                                                           EventRegistrationToken *token )
diff --git a/dlls/windows.gaming.input/gamepad.c b/dlls/windows.gaming.input/gamepad.c
index e69568e2fb1..231e923b5e8 100644
--- a/dlls/windows.gaming.input/gamepad.c
+++ b/dlls/windows.gaming.input/gamepad.c
@@ -35,11 +35,6 @@ static inline struct gamepad_statics *impl_from_IActivationFactory( IActivationF
     return CONTAINING_RECORD( iface, struct gamepad_statics, IActivationFactory_iface );
 }
 
-static inline struct gamepad_statics *impl_from_IGamepadStatics( IGamepadStatics *iface )
-{
-    return CONTAINING_RECORD( iface, struct gamepad_statics, IGamepadStatics_iface );
-}
-
 static HRESULT WINAPI factory_QueryInterface( IActivationFactory *iface, REFIID iid, void **out )
 {
     struct gamepad_statics *impl = impl_from_IActivationFactory( iface );
@@ -121,41 +116,7 @@ static const struct IActivationFactoryVtbl factory_vtbl =
     factory_ActivateInstance,
 };
 
-static HRESULT WINAPI statics_QueryInterface( IGamepadStatics *iface, REFIID iid, void **out )
-{
-    struct gamepad_statics *impl = impl_from_IGamepadStatics( iface );
-    return IActivationFactory_QueryInterface( &impl->IActivationFactory_iface, iid, out );
-}
-
-static ULONG WINAPI statics_AddRef( IGamepadStatics *iface )
-{
-    struct gamepad_statics *impl = impl_from_IGamepadStatics( iface );
-    return IActivationFactory_AddRef( &impl->IActivationFactory_iface );
-}
-
-static ULONG WINAPI statics_Release( IGamepadStatics *iface )
-{
-    struct gamepad_statics *impl = impl_from_IGamepadStatics( iface );
-    return IActivationFactory_Release( &impl->IActivationFactory_iface );
-}
-
-static HRESULT WINAPI statics_GetIids( IGamepadStatics *iface, ULONG *iid_count, IID **iids )
-{
-    struct gamepad_statics *impl = impl_from_IGamepadStatics( iface );
-    return IActivationFactory_Release( &impl->IActivationFactory_iface );
-}
-
-static HRESULT WINAPI statics_GetRuntimeClassName( IGamepadStatics *iface, HSTRING *class_name )
-{
-    struct gamepad_statics *impl = impl_from_IGamepadStatics( iface );
-    return IActivationFactory_Release( &impl->IActivationFactory_iface );
-}
-
-static HRESULT WINAPI statics_GetTrustLevel( IGamepadStatics *iface, TrustLevel *trust_level )
-{
-    struct gamepad_statics *impl = impl_from_IGamepadStatics( iface );
-    return IActivationFactory_Release( &impl->IActivationFactory_iface );
-}
+DEFINE_IINSPECTABLE( statics, IGamepadStatics, struct gamepad_statics, IActivationFactory_iface )
 
 static HRESULT WINAPI statics_add_GamepadAdded( IGamepadStatics *iface, IEventHandler_Gamepad *value,
                                                 EventRegistrationToken *token )
diff --git a/dlls/windows.gaming.input/private.h b/dlls/windows.gaming.input/private.h
index 612d11135f4..d36f88d58e4 100644
--- a/dlls/windows.gaming.input/private.h
+++ b/dlls/windows.gaming.input/private.h
@@ -38,3 +38,39 @@ extern IActivationFactory *controller_factory;
 extern IActivationFactory *gamepad_factory;
 
 extern HRESULT vector_create( REFIID iid, REFIID view_iid, void **out );
+
+#define DEFINE_IINSPECTABLE( pfx, iface_type, impl_type, base_iface )                              \
+    static inline impl_type *impl_from_##iface_type( iface_type *iface )                           \
+    {                                                                                              \
+        return CONTAINING_RECORD( iface, impl_type, iface_type##_iface );                          \
+    }                                                                                              \
+    static HRESULT WINAPI pfx##_QueryInterface( iface_type *iface, REFIID iid, void **out )        \
+    {                                                                                              \
+        impl_type *impl = impl_from_##iface_type( iface );                                         \
+        return IInspectable_QueryInterface( (IInspectable *)&impl->base_iface, iid, out );         \
+    }                                                                                              \
+    static ULONG WINAPI pfx##_AddRef( iface_type *iface )                                          \
+    {                                                                                              \
+        impl_type *impl = impl_from_##iface_type( iface );                                         \
+        return IInspectable_AddRef( (IInspectable *)&impl->base_iface );                           \
+    }                                                                                              \
+    static ULONG WINAPI pfx##_Release( iface_type *iface )                                         \
+    {                                                                                              \
+        impl_type *impl = impl_from_##iface_type( iface );                                         \
+        return IInspectable_Release( (IInspectable *)&impl->base_iface );                          \
+    }                                                                                              \
+    static HRESULT WINAPI pfx##_GetIids( iface_type *iface, ULONG *iid_count, IID **iids )         \
+    {                                                                                              \
+        impl_type *impl = impl_from_##iface_type( iface );                                         \
+        return IInspectable_GetIids( (IInspectable *)&impl->base_iface, iid_count, iids );         \
+    }                                                                                              \
+    static HRESULT WINAPI pfx##_GetRuntimeClassName( iface_type *iface, HSTRING *class_name )      \
+    {                                                                                              \
+        impl_type *impl = impl_from_##iface_type( iface );                                         \
+        return IInspectable_GetRuntimeClassName( (IInspectable *)&impl->base_iface, class_name );  \
+    }                                                                                              \
+    static HRESULT WINAPI pfx##_GetTrustLevel( iface_type *iface, TrustLevel *trust_level )        \
+    {                                                                                              \
+        impl_type *impl = impl_from_##iface_type( iface );                                         \
+        return IInspectable_GetTrustLevel( (IInspectable *)&impl->base_iface, trust_level );       \
+    }
-- 
2.34.1




More information about the wine-devel mailing list