COM Object Interfaces

IUnknown and IDispatch Interfaces

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:

  1. First get a handle to the IUnknown interface from the component. All COM components are required to implement this interface.

  2. Attempt to get the IDispatch interface. If IDispatch is implemented, return a handle to this interface. If IDispatch is not implemented, return the handle to IUnknown.

Additional Interfaces

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');
get(h)

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

MATLAB displays:

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:

Related Topics