Main Content

Create COM Objects

Use theactxserver强啡肽的功能来创建一个进程内服务器mic 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 theactxserverfunction. MATLAB®creates an instance of the component in the same process that contains the client application.

The syntax foractxserver, when used with a DLL component, isactxserver(ProgID), whereProgIDis the programmatic identifier for the component.

actxserverreturns 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, seeCOM Object Interfaces.

Unlike通过显微镜osoft®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, seeWhy am I not able to use 32-bit DLL COM Objects in 64-bit MATLAB?.

Instantiate EXE Component

You can use theactxserverfunction 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 foractxserverto create an executable isactxserver (ProgID sysname).ProgIDis the programmatic identifier for the component, andsysnameis an optional argument used in configuring a distributed COM (DCOM) system.

actxserverreturns 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, seeCOM Object Interfaces.

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

This example creates a COM server application running the通过显微镜osoft Excel®spreadsheet program. The handle is assigned toh.

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 theactxGetRunningServerfunction.

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

h = actxGetRunningServer('Excel.Application')

MATLAB displays:

h = COM.excel.application

See Also

|