windows-rs icon indicating copy to clipboard operation
windows-rs copied to clipboard

Consider implementing limited support for COM aggregation

Open kennykerr opened this issue 5 months ago • 1 comments

I removed this support as it was only needed for Xaml and overly complicated for the vast majority of other cases but perhaps there is a simple way to support it in a limited fashion, most likely with a dedicated macro.

@kennykerr I appreciate your help with #3242 very much. I've mentioned the need for composable inheritance previously, or at least a way to hook into QI so that it was possible to implement it by hand without unrolling the implement macro. .NET has ICustomQueryInterface, something like this would've definitely been helpful even without proper composable support.

You can see the main perpetrator here:

  • https://github.com/Alovchin91/winui3-rs/blob/25bb415df3676a834c5ce54a4fe46c14c5e7f14a/winui3/src/xaml_app.rs

If I want to use any XAML at all, even if it's in an "island", -- I must inherit from (I)Application because its factory turns it into a singleton reused later on. I don't like it either, but there's no way around it. I've tried implementing it with the "stock" implement macro, but it works until it doesn't, see this commit: https://github.com/Alovchin91/winui3-rs/commit/83cb3eb67e34f2984c4c3c9b0a0e808d593aa774

FYI, I have no plans to publish it, at least as a "winui3" crate, because I don't plan to support the entirety of the API surface (and WebView2 is not a part of my plans, at least currently). I'm only looking at a very constrained set of use cases, like a Window with a SwapChainPanel (because Window itself is not a UIElement, unfortunately).

Originally posted by @Alovchin91 in #3762

kennykerr avatar Sep 22 '25 14:09 kennykerr

I have a solution that's a little hacky and doesn't introduce new macros.

https://github.com/compio-rs/winui3-rs/blob/winui3-lite/winui3/src/compose.rs

The hacky part is the trait ChildClass.

  • It needs the Factory object to create a compose object.
  • It replaces the vtable to extend the QueryInterface method.

Then it works. The object is created with Compose::compose and the inner base interface should be accessed with Compose::base. It would be better if the *Overrides interfaces also exposes methods wrappers, in order to make the users calling base methods easier.

Berrysoft avatar Oct 24 '25 18:10 Berrysoft