Question

we're considering exposing some C# types to C++ clients via COM. What problems can we expect to hit over the life of the project? E.g. how will versioning be managed?

On versioning, it would seem from reading this that we should decorate our types to be exposed with [ClassInterface(ClassInterfaceType.None)] and use an explicit interface. That way I assume we fully control the interface that will be exposed to COM clients.

Thanks in advance.

Was it helpful?

Solution

Since you are using a C++ client you should definitely use explicit interfaces for early binding. Dispatch interfaces are useful when using scripting clients such as VBS but they are rarely useful for C++ clients.

The only way to version an interface is to create a new interface (possibly inheriting from the original interface). When using explicit interfaces you have full control over this process.

This means you should create an interface for every class that you intend to expose via COM. Don't forget to mark every interface and class with the ComVisible and Guid attributes. Also all your classes must have a default constructor.

OTHER TIPS

You'll have to read about the GUID attribute (including this) to maintain binary compatibility and only rebuild the clients when necessary.

Also you might be interested in the ComVisible attribute that helps reduce registry pollution.

To get full control over COM interfaces, define them in MIDL. Build a type library with those interfaces in a C++ project, then import type library to C# and implement interfaces.

This approach is useful with complex interfaces where marshaling is not trivial.

Versions should be done COM-style, changing GUIDs and adding new or inheriting interfaces.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top