Skip to content

ComWrapper RCW Design question #35929

@weltkante

Description

@weltkante

I've been told by @AaronRobinsonMSFT that the ComWrapper API will be the future of COM interop development. I'm interested in this development as we make heavy use of COM interop in our products, both for win32 interop and for communication between our own components, including across languages and across processes.

ComWrapper is brand new and I'm having a bit trouble following up, CCW generation seems to have some good examples but RCW less so. From the test code and what I can gather from the issues I have doubts whether the RCW API Design of ComWrapper will hold up for general purpose use.

From what I've been linked to it looks like you are supposed to override CreateObject and construct a managed wrapper around the vtable.

As far as I'm reading out of various issue discussions (e.g. here) the design has been validated for WinUI/WinRT usage who have IInspectable to allow determining what the vtable represents. I'm worried this design of just passing a vtbl pointer along will not work for classic COM or other COM-like APIs which don't make use of IInspectable and have an unknown set of interfaces.

I've read the suggestion to "just query for all IIDs you know" to figure out what the object supports - this is a no-go for me as the approach doesn't scale (some of our libraries can support on the magnitude of hundreds of COM interfaces imported from TLBs, I cannot imagine that querying for all of them on each RCW would scale)

In old CLR COM I understand the RCW is an object that I can cast to an interface and it will on-demand map that vtable to an implementation of that interface. What I would have expected to see for an API to replace RCW is that I can build up one interface at a time lazily as C# performs the casts.

Am I missing something here? If the lazy cast pattern cannot be built into ComWrapper directly I can also imagine implementing a magic interface like ICustomQueryInterface on the RCW, just for managed casts. The current RCWs have to be solving it somehow so it can't be technically impossible to generalize the concept if it wasn't part of the current design.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Interop-coreclrquestionAnswer questions and provide assistance, not an issue with source code or documentation.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions