invoke - Invoke method on object or interface, or display methods

Syntax

S = h.invoke
S = h.invoke('methodname')
S = h.invoke('methodname', arg1, arg2, ...)
S = h.invoke('custominterfacename')
S = invoke(h, ...)

Description

S = h.invoke returns structure array S containing a list of all methods supported by the object or interface, h, along with the prototypes for these methods.

If S is empty, either there are no properties or methods in the object, or MATLAB® cannot read the object's type library. Refer to the COM vendor's documentation. For Automation objects, if the vendor provides documentation for specific properties or methods, use the S = invoke(h, ...) syntax to call them.

S = h.invoke('methodname') invokes the method specified in the string methodname, and returns an output value, if any, in S. The data type of the return value is dependent upon the specific method being invoked and is determined by the specific control or server.

S = h.invoke('methodname', arg1, arg2, ...) invokes the method specified in the string methodname with input arguments arg1, arg2, etc.

S = h.invoke('custominterfacename') returns an Interface object that serves as a handle to a custom interface implemented by the COM component. The h argument is a handle to the COM object. The custominterfacename argument is a quoted string returned by the interfaces function.

S = invoke(h, ...) is an alternate syntax for the same operation.

Remarks

If the method returns a COM interface, then invoke returns a new MATLAB COM object that represents the interface returned. See Handling COM Data in MATLAB® Software in the External Interfaces documentation for a description of how MATLAB converts COM data types.

Examples

Example 1 — Invoking a Method

Create an mwsamp control and invoke its Redraw method:

f = figure ('position', [100 200 200 200]);
h = actxcontrol ('mwsamp.mwsampctrl.1', [0 0 200 200], f);

h.Radius = 100;
h.invoke('Redraw');

Here is a simpler way to use invoke. Just call the method directly, passing the handle, and any arguments:

h.Redraw;

Call invoke with only the handle argument to display a list of all mwsamp methods:

h.invoke
ans = 
   AboutBox = void AboutBox(handle)
   Beep = void Beep(handle)
   FireClickEvent = void FireClickEvent(handle)
             .
             .
            etc.

Example 2 — Getting a Custom Interface

Once you have created a COM 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:

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:

c1 = h.invoke('ICalc1')
c1 =
   Interface.Calc_1.0_Type_Library.ICalc_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.

See Also

methods, ismethod, interfaces

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS