Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Late Binding COM objects with C++Builder

We're interfacing to some 3rd party COM objects from a C++Builder 2010 application.

Currently we import the type library and generate component wrappers, and then are able to make method calls and access properties in a fairly natural way.

object->myProperty = 42;
object->doSomething(666);

However, we've been bitten by changes to the COM object's interface (which is still being extended and developed) causing our own app to fail because some method GUIDs seem to get invalidated - even if the only change to the interface has been the addition of a new method).

Late Binding has been suggested as a way of addressing this. I think this requires our code to be changed rather like this:

object.OlePropertySet("myProperty", 42);
object.OlePrcedure("doSomething", 666);

Obviously this is painful to read and write, so we'd have to write wrapper classes instead.

Is there any way of getting late binding wrappers generated automatically when we import the type library? And, if so, are they smart enough to only do the textual binding once when the object is created, rather than on every single method call?

like image 707
Roddy Avatar asked Oct 22 '22 15:10

Roddy


1 Answers

When you import a TypeLibrary for a COM object that supports late-binding (when it implements the IDispatch interface), the importer can generate separate wrapper classes (not components) for both static-binding and late-binding.

Adding a new method to an existing interface should not invalidate your code. Methods do not have GUIDs. However, for an IDispatch-based interface, its methods do have DISPID values associated with them, and those DISPID values can be changed from one release to another. Though any respectable COM developer should never do that once an interface definition has been locked in.

like image 76
Remy Lebeau Avatar answered Nov 02 '22 10:11

Remy Lebeau