| MATLAB® | ![]() |
| 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:
First get a handle to the IUnknown interface from the component. All COM components are required to implement this interface.
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.
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.getMATLAB displays information similar to:
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.
The following client/server configurations support interface:
Note The MATLAB COM Interface does not support invoking functions with optional parameters. |
Once you have created the 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.interfacesMATLAB 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_InterfaceUse 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: 0To 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
![]() | Using Events | Saving Your Work | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |