0

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?

Yuri Vovchenko
  • 363
  • 1
  • 5
  • 14
  • Do you mean you're using the same interface id (IID) with different interface definitions / layout? – Simon Mourier Jun 24 '19 at 15:57
  • yes. I dont want to rely on windows registry definition of the interface. I want to call it dynamically like in this article: http://forums.codeguru.com/showthread.php?198816-Calling-IDispatch-Invoke-and-passing-arguments – Yuri Vovchenko Jun 24 '19 at 16:03
  • Not sure what you're doing/looking for exactly. You talk about IDispatch in others' comments. You should explain better. One thing for sure, you **cannot** change an IUnknown-derived interface ("early binding") without changing its IID. It's a binary contract carved in stone. – Simon Mourier Jun 24 '19 at 17:16

2 Answers2

0

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.

Michael Chourdakis
  • 10,345
  • 3
  • 42
  • 78
  • yes, but different versions of the software have more methods added to same interface. Sorry it is not my fault. It was done by developers of that software. I know that proper guideline is never version them and instead introduce new interfaces like Interface2,or Interface3 etc. I just need to solve the problem cause I am developing a client to the original flawed COM server. – Yuri Vovchenko Jun 24 '19 at 16:06
  • You can't do anything. It will be a different virtual table of the interface. COM interfaces are virtual, if the vtbl changes and you don't have the newer declaration you will get a crash. – Michael Chourdakis Jun 24 '19 at 16:07
  • There should be a way I hope. Correction: since it is out-of-process com i use dynamic IDispatch calls after using IUnknown->QueryInterface. – Yuri Vovchenko Jun 24 '19 at 16:10
  • If i'ts IDispatch, then you will still have a problem if relying on a typelibrary for automated Invoke calls. Otherwise you must call Invoke() manually. – Michael Chourdakis Jun 24 '19 at 16:11
0

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.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770