Documentation

Call COM Objects

Access COM components and ActiveX®controls from MATLAB®

The Microsoft®Component Object Model(COM) provides a framework for integrating reusable, binary software components into an application. Because components are implemented with compiled code, the source code can be written in programming languages that support COM. Upgrades to applications are simplified, as components can simply be swapped without the need to recompile the entire application. In addition, a component's location is transparent to the application, so components can be relocated to a separate process or even a remote system without having to modify the application.

Alternatively, consider using the Microsoft .NET Framework.

MATLAB supports COM and the .NET Framework integration on the Microsoft Windows®platform only.

Functions

actxserver Create COM server
actxcontrol Create Microsoft ActiveX control in figure window
actxcontrollist List currently installed Microsoft ActiveX controls
actxcontrolselect Create Microsoft ActiveX control from UI
actxGetRunningServer Handle to running instance of Automation server
iscom Determine whether input is COM or ActiveX object
isprop Determine whether input is COM object property
get Get property value from interface, or display properties
set Set object or interface property to specified value
addproperty Add custom property to COM object
deleteproperty Remove custom property from COM object
inspect Open Property Inspector
propedit Open built-in property page for control
fieldnames Field names of structure, or public fields of COM or Java object
ismethod Determine whether input is COM object method
methods Class method names
methodsview View class methods
invoke Invoke method on COM object or interface, or display methods
isevent Determine whether input is COM object event
events List of events COM object can trigger
eventlisteners List event handler functions associated with COM object events
registerevent 在俄罗斯为COM对象事件关联事件处理程序n time
unregisterallevents Unregister all event handlers associated with COM object events at run time
unregisterevent Unregister event handler associated with COM object event at run time
isinterface Determine whether input is COM interface
interfaces List custom interfaces exposed by COM server object
release Release COM interface
delete Remove COM control or server
move Move or resize control in parent window
load Initialize control object from file
save Serialize control object to file

Examples and How To

Microsoft Office Examples

Write Data to Excel Spreadsheet Using ActiveX

This example shows how to write a MATLAB matrix to an Excel®spreadsheet.

Read Spreadsheet Data Using Excel as Automation Server

For alternatives to importing Excel spreadsheet data into MATLAB, see the functions and examples inSpreadsheets.

Change Cursor in Spreadsheet

This example shows how to change the cursor icon in an Excel spreadsheet.

Change Row Height in Range of Spreadsheet Cells

This example shows how to change the height of a row, defined by aRangeobject, in a spreadsheet.

Insert Spreadsheet After First Sheet

This example shows how to skip an optional input argument in the ExcelAddmethod, used to insert a sheet into a workbook.

Connect to Existing Excel Application

This example shows how to read data from an open file,weekly_log.xlsx, in MATLAB.

Display Message for Workbook OnClose Event

This example shows how to handle a COM interface event, how to set up an event in aMicrosoft Excelworkbookobject, and how to handle itsBeforeCloseevent.

Explore COM Objects

Learn about a COM object using MATLAB commands

ActiveX Control Examples

MATLAB Sample ActiveX Control mwsamp

MATLAB includes an example COM control that draws a circle on the screen, displays some text, and fires events when the user single- or double-clicks the control.

Redraw Circle in mwsamp Control

This example shows how to call a method of themwsampcontrol to redraw a circle.

Display Event Messages from mwsamp Control

This example shows how to handle events fired by the MATLAB ActiveX control,mwsamp2.

Add Position Property to mwsamp Control

This example shows how to add a custom property,Positionto themwsampcontrol.

Combine Event Handlers as MATLAB Local Functions

This example shows how to consolidate event handlers into a single file using local functions.

Save mwsamp2 COM Control

This example shows how to restore originalmwsamp2control settings.

Deploy ActiveX Controls Requiring Run-Time Licenses

When you deploy aMicrosoft ActiveXcontrol that requires a run-time license, include a license key, which the control reads at run time.

Internet Explorer Examples

Use Internet Explorer in MATLAB Figure

This example uses the ActiveX controlShell.Explorer, which is exposed by the Microsoft Internet Explorer®application, to include an HTML viewer in a MATLAB figure.

Concepts

MATLAB COM Integration

COM concepts and an overview of COM support in MATLAB software

Getting Started with COM

Examples that show how to use COM interface with MATLAB software

Registering Controls and Servers

Before using COM objects, you must register their controls and servers.

Create COM Objects

How to createMicrosoft ActiveXcontrols and COM server objects

Handle COM Data in MATLAB

Pass data to and handle data from a COM object

COM Object Properties

List property names and set values, work with multiple objects and properties, use the Property Inspector, use enumerated values and custom properties

COM Methods

You execute, orinvoke, COM functions or methods belonging to COM objects.

COM电动车ents

Respond to events, write event handlers

COM电动车ent Handlers

For controls, register handler functions either at the time you create an instance of the control (usingactxcontrol), or any time afterward (usingregisterevent).

Save and Delete COM Objects

Use these MATLAB functions to save and restore the state of a COM control object.

COM Object Interfaces

Use IUnknown, IDispatch, and custom interfaces

COM Collections

COMcollectionsare a way to support groups of related COM objects that can be iterated over.

Supported Client/Server Configurations

COM client-server configurations in MATLAB software

Microsoft Forms 2.0 Controls

Microsoft Forms 2.0 controls are designed for use with applications enabled byMicrosoft Visual Basic®for Applications (VBA).

MATLAB Application as DCOM Client

Distributed Component Object Model (DCOM) is a protocol that allows clients to use remote COM objects over a network.

Troubleshooting

MATLAB COM Support Limitations

Microsoft does not support loading 32-bit DLLs or in-process COM servers into a 64-bit application, or conversely.

Interpreting Argument Callouts in COM Error Messages

When a MATLAB client sends a command with an invalid argument to a COM server application, the server sends back an error message in the following format.

Was this topic helpful?