Documentation Center

  • Trial Software
  • Product Updates

Contents

我们为许可用户提供了部分翻译好的中文文档。您只需登录便可查阅这些文档

actxserver

Create COM server

Syntax

h = actxserver('progid')
h = actxserver('progid','machine','machineName')
h = actxserver('progid','interface','interfaceName')
h = actxserver('progid','machine','machineName','interface','interfaceName')
h = actxserver('progid',machine)

Description

h = actxserver('progid') creates a local OLE Automation server, where progid is the programmatic identifier of an OLE-compliant COM server, and h is the handle of the server's default interface.

Get progid from the control or server vendor's documentation. To see the progid values for MATLAB® software, refer to Programmatic Identifiers.

h = actxserver('progid','machine','machineName') creates an OLE Automation server on a remote machine, where machineName is a string specifying the name of the machine on which to start the server.

h = actxserver('progid','interface','interfaceName') creates a Custom interface server, where interfaceName is a string specifying the interface name of the COM object. Values for interfaceName are

  • IUnknown — Use the IUnknown interface.

  • The Custom interface name

You must know the name of the interface and have the server vendor's documentation in order to use the interfaceName value. For information about custom COM servers and interfaces, see COM Server Types.

    Note:   The MATLAB COM Interface does not support invoking functions with optional parameters.

h = actxserver('progid','machine','machineName','interface','interfaceName') creates a Custom interface server on a remote machine.

The following syntaxes are deprecated and will not become obsolete. They are included for reference, but the syntaxes described earlier are preferred:

h = actxserver('progid',machine) creates a COM server running on the remote system named by the machine argument. This can be an IP address or a DNS name. Use this syntax only in environments that support Distributed Component Object Model (for more information, see Using MATLAB Application as DCOM Server).

Examples

Microsoft Excel Workbook Example

This example creates an OLE Automation server, Excel® version 9.0, and manipulates a workbook in the application.

Create a COM server running Microsoft® Excel.

e = actxserver ('Excel.Application')
e =     
    COM.Excel.application

Make the Excel frame window visible.

e.Visible = 1;

Use the get method on the Excel object e to list all properties of the application.

e.get
        Application: [1x1
Interface.Microsoft_Excel_9.0_Object_Library._Application]
            Creator: 'xlCreatorCode'
                   .
                   .
                   .
          Workbooks: [1x1 
Interface.Microsoft_Excel_9.0_Object_Library.Workbooks]
                   .
                   .
                   .
            Caption: 'Microsoft Excel - Book1'
    CellDragAndDrop: 0
   ClipboardFormats: {3x1 cell}
                   .
                   .
                   .
             Cursor: 'xlNorthwestArrow'
                   .
                   .
                   .

Create an interface eWorkBooks.

eWorkbooks = e.Workbooks
eWorkbooks =
   Interface.Microsoft_Excel_9.0_Object_Library.Workbooks

List all methods for that interface.

eWorkbooks.invoke
       Add: 'handle Add(handle, [Optional]Variant)'
     Close: 'void Close(handle)'
      Item: 'handle Item(handle, Variant)'
      Open: 'handle Open(handle, string, [Optional]Variant)'
  OpenText: 'void OpenText(handle, string, [Optional]Variant)'
          .
          .
          .

Add a new workbook w, also creating a new interface.

w = eWorkbooks.Add
w =
   Interface.Microsoft_Excel_9.0_Object_Library._Workbook

Close Excel and delete the object.

e.Quit;
e.delete;

More About

expand all

Tips

For components implemented in a dynamic link library (DLL), actxserver creates an in-process server. For components implemented as an executable (EXE), actxserver creates an out-of-process server. Out-of-process servers can be created either on the client system or on any other system on a network that supports DCOM.

If the control implements any Custom interfaces, use the interfaces function to list them, and the invoke function to get a handle to a selected interface.

You can register events for COM servers.

COM functions are available on Microsoft Windows® systems only.

See Also

| | | | | | |

Related Examples

Was this topic helpful?