Out of process COM object dynamic versioning

94 views Asked by At

I am using out-of-process COM object that is hosted by myexe.exe. There are multiple versions of those exes which host the COM object. Each version can have slightly changed interfaces and methods. Each of myexe.exe files are located in versioned folders(e.g. C:\v2\myexe.exe, c:\v3\myexe.exe)

There is no way to know ahead of time which of the versions will be running. My client application attaches to the running exes using ROT. I need to be able to use that COM object version dynamically, discovering interfaces through IUnknown.QueryInterface.

Unfortunately I am getting crash when using newer methods if older version of COM is registered in Windows Registry. Once I register newer version of out-of-proces COM in windows registry using "myexe.exe -regserver" the crash goes away. So i cannot dynamically use older or newer version of meexe.exe at runtime as each time i need to re-register my com version.

Any ideas on why i get the crash or how to solve the problem?

2

There are 2 answers

4
Michael Chourdakis On

COM interfaces are never versioned. Each COM interface is as different as any other. You use IIDs to differentiate and go from one to another using QueryInterface().

See QueryInterface guidelines and the Guide.

0
Remy Lebeau On

COM interfaces are immutable. Once you have defined an interface and start using it in your apps, you CAN'T change it anymore. Its IID and VTABLE are locked in. If you need to make changes to existing methods, or add new methods, you MUST create a new interface with a new IID for that purpose (the new interface can derive from the previous interface, though that is not required). The server must then implement the new interface, and clients can QueryInterface() the server for the new interface when needed. There is no getting around this, it is a fundamental rule of COM, so as not to break existing clients when creating new server versions.