External Interfaces Previous page   Next Page

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:

IUnknown and IDispatch

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:

  1. MATLAB first gets a handle to the IUnknown interface from the component. All COM components are required to implement at least this one interface.
  2. MATLAB then attempts to get the IDispatch interface from the component. If IDispatch is implemented in the component, MATLAB returns a handle to the IDispatch interface. If IDispatch is not implemented, MATLAB returns the handle to IUnknown.

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:

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:

Custom Interfaces

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:

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

To list the methods, use

Add and multiply numbers using the Add and Multiply methods of the custom object c1:


Previous page  Instantiating an EXE Component Invoking Commands on a COM Object Next page

© 1994-2005 The MathWorks, Inc.