Main Content

Create COM Objects

Use the actxserver function to create an in-process server for a dynamic link library (DLL) component or an out-of-process server for an executable (EXE) component.

Instantiate DLL Component

To create a server for a component implemented as a dynamic link library (DLL), use the actxserver function. MATLAB® creates an instance of the component in the same process that contains the client application.

The syntax for actxserver, when used with a DLL component, is actxserver(ProgID), where ProgID is the programmatic identifier for the component.

actxserver returns a handle to the primary interface to the object. Use this handle to reference the object in other COM function calls. You can also use the handle to obtain more interfaces to the object. For more information on using interfaces, see COM Object Interfaces.

Unlike Microsoft® ActiveX® controls, any user interface displayed by the server appears in a separate window.

You cannot use a 32-bit in-process DLL COM object in a 64-bit MATLAB application. For information about this restriction, see Why am I not able to use 32-bit DLL COM Objects in 64-bit MATLAB?.

Instantiate EXE Component

You can use the actxserver function to create a server for a component implemented as an executable (EXE). In this case, MATLAB instantiates the component in an out-of-process server.

The syntax for actxserver to create an executable is actxserver(ProgID, sysname). ProgID is the programmatic identifier for the component, and sysname is an optional argument used in configuring a distributed COM (DCOM) system.

actxserver returns a handle to the primary interface to the COM object. Use this handle to reference the object in other COM function calls. You can also use the handle to obtain more interfaces to the object. For more information on using interfaces, see COM Object Interfaces.

Any user interface displayed by the server appears in a separate window.

This example creates a COM server application running the Microsoft Excel® spreadsheet program. The handle is assigned to h.

h = actxserver('Excel.Application')

MATLAB displays:

h =
    COM.excel.application

MATLAB can programmatically connect to an instance of a COM Automation server application that is already running on your computer. To get a reference to such an application, use the actxGetRunningServer function.

This example gets a reference to the Excel program, which must already be running on your system. The returned handle is assigned to h.

h = actxGetRunningServer('Excel.Application')

MATLAB displays:

h =
    COM.excel.application

See Also

|