[PATCH 1/5] include: Add some helpers to define IInspectable forwarded methods.

Rémi Bernon rbernon at codeweavers.com
Tue Mar 1 02:17:05 CST 2022


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

This should greatly reduce the burden of implementing WinRT classes.

None of the WinRT interfaces are using inheritance, and classes very
often implement several interfaces, all deriving from IInspectable, and
even if a v2 interface only adds a single method, it doesn't derive from
the v1, and instead requires to reimplement the IInspectable methods and
forward them to the default interface.

In addition, it looks like they also used COM aggregation extensively,
and in these cases the forward has to be done to an outer IInspectable
pointer.

 include/inspectable.idl | 44 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/include/inspectable.idl b/include/inspectable.idl
index 847d21da608..8b233e3da94 100644
--- a/include/inspectable.idl
+++ b/include/inspectable.idl
@@ -39,3 +39,47 @@ interface IInspectable : IUnknown
 }
 
 typedef [unique] IInspectable *LPINSPECTABLE;
+
+cpp_quote("#ifdef __WINESRC__")
+cpp_quote("#define DEFINE_IINSPECTABLE_EXPR( pfx, iface_type, impl_type, impl_from, iface_mem, expr ) \\")
+cpp_quote("    static inline impl_type *impl_from( iface_type *iface ) \\")
+cpp_quote("    { \\")
+cpp_quote("        return CONTAINING_RECORD( iface, impl_type, iface_mem ); \\")
+cpp_quote("    } \\")
+cpp_quote("    static HRESULT WINAPI pfx##_QueryInterface( iface_type *iface, REFIID iid, void **out ) \\")
+cpp_quote("    { \\")
+cpp_quote("        return IInspectable_QueryInterface( (IInspectable *)(expr), iid, out ); \\")
+cpp_quote("    } \\")
+cpp_quote("    static ULONG WINAPI pfx##_AddRef( iface_type *iface ) \\")
+cpp_quote("    { \\")
+cpp_quote("        return IInspectable_AddRef( (IInspectable *)(expr) ); \\")
+cpp_quote("    } \\")
+cpp_quote("    static ULONG WINAPI pfx##_Release( iface_type *iface ) \\")
+cpp_quote("    { \\")
+cpp_quote("        return IInspectable_Release( (IInspectable *)(expr) ); \\")
+cpp_quote("    } \\")
+cpp_quote("    static HRESULT WINAPI pfx##_GetIids( iface_type *iface, ULONG *iid_count, IID **iids ) \\")
+cpp_quote("    { \\")
+cpp_quote("        return IInspectable_GetIids( (IInspectable *)(expr), iid_count, iids ); \\")
+cpp_quote("    } \\")
+cpp_quote("    static HRESULT WINAPI pfx##_GetRuntimeClassName( iface_type *iface, HSTRING *class_name ) \\")
+cpp_quote("    { \\")
+cpp_quote("        return IInspectable_GetRuntimeClassName( (IInspectable *)(expr), class_name ); \\")
+cpp_quote("    } \\")
+cpp_quote("    static HRESULT WINAPI pfx##_GetTrustLevel( iface_type *iface, TrustLevel *trust_level ) \\")
+cpp_quote("    { \\")
+cpp_quote("        return IInspectable_GetTrustLevel( (IInspectable *)(expr), trust_level ); \\")
+cpp_quote("    }")
+cpp_quote("#define DEFINE_IINSPECTABLE_OUTER_PFX( pfx, impl_pfx, iface_type, impl_type, outer ) \\")
+cpp_quote("    DEFINE_IINSPECTABLE_EXPR( pfx, iface_type, impl_type, impl_pfx##_from_##iface_type, \\")
+cpp_quote("                              iface_type##_iface, impl_pfx##_from_##iface_type( iface )->outer )")
+cpp_quote("#define DEFINE_IINSPECTABLE_OUTER( pfx, iface_type, impl_type, outer ) \\")
+cpp_quote("    DEFINE_IINSPECTABLE_EXPR( pfx, iface_type, impl_type, impl_from_##iface_type, \\")
+cpp_quote("                              iface_type##_iface, impl_from_##iface_type( iface )->outer )")
+cpp_quote("#define DEFINE_IINSPECTABLE_PFX( pfx, impl_pfx, iface_type, impl_type, member ) \\")
+cpp_quote("    DEFINE_IINSPECTABLE_EXPR( pfx, iface_type, impl_type, impl_pfx##_from_##iface_type, \\")
+cpp_quote("                              iface_type##_iface, &impl_pfx##_from_##iface_type( iface )->member )")
+cpp_quote("#define DEFINE_IINSPECTABLE( pfx, iface_type, impl_type, member ) \\")
+cpp_quote("    DEFINE_IINSPECTABLE_EXPR( pfx, iface_type, impl_type, impl_from_##iface_type, \\")
+cpp_quote("                              iface_type##_iface, &impl_from_##iface_type( iface )->member )")
+cpp_quote("#endif")
-- 
2.34.1




More information about the wine-devel mailing list