Documentation Center

  • Trial Software
  • Product Updates


Getting Interfaces to COM Object

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');

MATLAB displays information like:

    Application: [1x1 Interface.Microsoft_Excel_9.0_
        Creator: 'xlCreatorCode'
         Parent: [1x1 Interface.Microsoft_Excel_9.0_
     ActiveCell: []
    ActiveChart: [1x50 char]

To see if Workbooks is an interface, type:

w = h.Workbooks

MATLAB displays:

w =

The information displayed depends on the version of the Excel software you have on your system.

For examples using Excel in MATLAB, see:

Custom Interfaces

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.

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 =

To get the handle to a particular interface, use the invoke function:

c1 = h.invoke('ICalc1')
c1 =

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:

     background: 'Blue'
         height: 10
          width: 0

To list the methods, use:

   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 =

prod = c1.Multiply(4, 7)
prod =
Was this topic helpful?