|On this page…|
When you invoke the actxserver or actxcontrol functions, the MATLAB® software creates the server and returns a handle to the server interface as a means of accessing its properties and methods. The software uses the following process to determine which handle to return:
Components often provide additional interfaces, based on IDispatch, that are implemented as properties. Like any other property, you obtain these interfaces using the MATLAB get function.
For example, a Microsoft® Excel® component contains numerous interfaces. To list these interfaces, along with Excel properties, type:
h = actxserver('Excel.Application'); h.get
MATLAB displays information like:
Application: [1x1 Interface.Microsoft_Excel_9.0_ Object_Library._Application] Creator: 'xlCreatorCode' Parent: [1x1 Interface.Microsoft_Excel_9.0_ Object_Library._Application] ActiveCell:  ActiveChart: [1x50 char] . .
To see if Workbooks is an interface, type:
w = h.Workbooks
w = Interface.Microsoft_Excel_9.0_Object_Library.Workbooks
The information displayed depends on the version of the Excel software you have on your system.
For examples using Excel in MATLAB, see:
The MATLAB COM Interface supports custom interfaces for the following client/server configurations:
Limitations to custom interface support are:
Custom interfaces are not supported on a 64-bit version of MATLAB.
You cannot invoke functions with optional parameters.
Once you have created a server, you can query the server component to see if any custom interfaces are implemented using the interfaces function. interfaces returns the names in a cell array of strings.
For example, if you have a component with the ProgID mytestenv.calculator, you can see its custom interfaces using the commands:
h = actxserver('mytestenv.calculator'); customlist = h.interfaces
MATLAB displays the interfaces, which might be:
customlist = ICalc1 ICalc2 ICalc3
To get the handle to a particular interface, use the invoke function
c1 = h.invoke('ICalc1') c1 = Interface.Calc_1.0_Type_Library.ICalc_Interface
Use this handle c1 to access the properties and methods of the object through this custom interface ICalc1.
For example, to list the properties, use:
c1.get background: 'Blue' height: 10 width: 0
To list the methods, use:
c1.invoke Add = double Add(handle, double, double) Divide = double Divide(handle, double, double) Multiply = double Multiply(handle, double, double) Subtract = double Subtract(handle, double, double)
To add and multiply numbers using the Add and Multiply methods of the object, use:
sum = c1.Add(4, 7) sum = 11 prod = c1.Multiply(4, 7) prod = 28