Kanitatlan
Kanitatlan

Reputation: 395

How to check if a method is available in an OCX interface

Currently I have an OCX embedded in our product using standard boilerplate Delphi importing of the OCX. The vendor has issued a new version of the OCX that uses the exact same GUIDs for everything (object and interfaces) but there are changes to the API. These changes are quite limited but I'm having some difficulty coming up with a reliable way to identify if the installed OCX is using the old or new version. The obvious way is to drill into the interface and check if a specific method is available from the object once it has been instantiated. I would like to do this by actually asking the object what the dispatch ID is for a particular method to see if it is present.

I don't want to use the approach of calling a new method and getting an exception as the object won't work until it has been initialised and the initialisation API is one of the things that has changed. This means that any call of a new method before initialisation will fail anyway.

Does anyone know what would be the proper way to poke through the Delphi wrapper and find out if a particular method can be resolved?

Upvotes: 0

Views: 203

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 596497

The answer is actually in your question:

I would like to do this by actually asking the object what the dispatch ID is for a particular method to see if it is present.

An OCX object implements the IDispatch interface, and IDispatch has a GetIDsOfNames() method for the very purpose of returning the dispatch ID of the object's methods and properties (for use with IDispatch.Invoke()). If a requested name is not known to the object, GetIDsOfNames() returns DISP_E_UNKNOWNNAME.

Upvotes: 3

Related Questions