External Interfaces |
Getting Interfaces to the Object
The COM component you are working with can provide different types of interfaces for accessing the object's public properties and methods:
When you invoke the actxserver
or actxcontrol
function, MATLAB creates the server and returns a handle to the server interface as a means of accessing its properties and methods. MATLAB uses the following process to determine which handle to return:
Additional Interfaces. Components often provide additional interfaces, based on IDispatch, that are implemented as properties. Like any other property, you can obtain any of these interfaces using the MATLAB get
function.
For example, a Microsoft Excel component contains numerous interfaces. You can list these interfaces, along with other Excel properties, using the MATLAB get
function without any arguments:
h = actxserver('excel.application'); h.get 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 get a handle to a specific interface, specify an object or interface handle, h
in the example below, and the name of the target interface, Workbooks
:
The following two client/server configurations also support any custom interfaces that may be implemented in the component:
Once you have created the server, you can query the server component to see if any custom interfaces are implemented. Use the interfaces
function to return a list of all available custom interfaces. This list is returned in a cell array of strings:
h = actxserver('mytestenv.calculator') h = COM.mytestenv.calculator customlist = h.interfaces customlist = ICalc1 ICalc2 ICalc3
To get a handle to the custom interface you want, use the invoke
function, specifying the handle returned by actxcontrol
or actxserver
, and also the name of the custom interface:
You can now use this handle with most of the COM client functions to access the properties and methods of the object through the selected custom interface.
For example, to list the properties available through the ICalc1
interface, 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)
Add and multiply numbers using the Add
and Multiply
methods of the custom object c1
:
Instantiating an EXE Component | Invoking Commands on a COM Object |
© 1994-2005 The MathWorks, Inc.