'Typecasting' COM-objects in matlab?

3 views (last 30 days)
Joris Janssenswillen
Joris Janssenswillen on 9 Oct 2015
Is it possible to typecast COM objects in matlab, as would be done in C# for instance?
I am using a COM dll (actxserver).
The code in C# of what I want to do is:
var m = tracker.Measurement.MeasureStationary() as StationaryMeasurement3D;
The object returned by 'tracker.Measurement.MeasureStationary()' is not of type 'StationaryMeasurement3D', but can be cast to it.
I've tried using the cast() function in matlab, but returns with the error 'Unsupported data type for conversion'.

Answers (1)

Guillaume
Guillaume on 9 Oct 2015
Use invoke to get access to a different interface implemented by the com object. The list of interfaces implemented by that object can be obtained with interfaces.
  3 Comments
Guillaume
Guillaume on 12 Oct 2015
Edited: Guillaume on 12 Oct 2015
It may well be a limitation of matlab in which case I'm not sure there's any workaround (short of rewriting the com object).
Note that the documentation states that "custom interfaces are not supported on a 64-bit version of MATLAB". I've not got a 32-bit version installed anymore so can't really do any testing. It's also been a while since I've dealt with COM since I never bothered upgrading my COM components to 64-bit.
Is there a way to access the com interface you want through an IDISPATCH interface (obtained via a property of the object)?
Joris Janssenswillen
Joris Janssenswillen on 13 Oct 2015
I have seen that note in the documentation indeed. Rewriting the COM dll is not a possibility.
I have noted that the returned type of the measurement is an interface:
Interface.LMF_Tracker_Connection.IMeasurementCOM
On which the 'interfaces' command does not work. When I create an emtpy COM-object of that same type, however:
measurement0=COM.LMF.Tracker.MeasurementResults.Measurement
The returned object is the corresponding COM-object:
COM.LMF.Tracker.MeasurementResults.Measurement
On this object I can indeed probe the supported interfaces:
interfaces(measurement0)
Is there anyway to convert the returned interface-object into its COM-object? Would that enable the possibility to invoke another interface of that COM-object?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!