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'.

답변 (1개)

Guillaume
Guillaume 2015년 10월 9일

0 개 추천

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

I have tried finding the correct interface, but the interfaces() function does not work on the returned object. Applying interfaces() on the returned object returns the following error:
Undefined function 'interfaces' for input arguments of type
'Interface.LMF_Tracker_Connection.IMeasurementCOM'.
I have tried the following as well:
measurement2= COM.LMF.Tracker.MeasurementResults.StationaryMeasurement3D(measurement)
But this returns the following error:
Invalid number of parameters. COM object creation failed
Guillaume
Guillaume 2015년 10월 12일
편집: Guillaume 2015년 10월 12일
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)?
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?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Use COM Objects in MATLAB에 대해 자세히 알아보기

질문:

2015년 10월 9일

댓글:

2015년 10월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by