A MATLAB® class cannot be directly compiled into a COM object.
You can, however, use a user-generated class inside a MATLAB file
and build a COM object from that file. You can use the MATLAB command-line
interface instead of the Library Compiler app to create COM objects.
Do this by issuing the mcc
command with options.
If you use mcc
, you do not create a project.
The following table provides an overview of some mcc
options
related to components, along with syntax and examples of their usage.
Using the Command Line to Create COM Components
Action to Perform | mcc Option to Use | Description |
---|---|---|
Create component that has one class. | -W com | The |
Syntax
An unspecified | ||
Example
The example creates a COM component called
| ||
Add additional classes to a COM component. | Not needed | A separate COM named Following
the |
Syntax
| ||
Example
The example creates a COM component named
| ||
Simplify the command-line input for components. | -B ccom: | Uses the bundle. |
Syntax
| ||
Example
| ||
Control how each COM class uses the MATLAB Runtime. | -S |
By default, a new MATLAB Runtime instance is created for each instance of each COM
class in the component. Use This option tells the compiler to create a single MATLAB Runtime at the time when the first COM class is instantiated. This MATLAB Runtime is reused and shared among all subsequent class instances, resulting in more efficient memory usage and eliminating the MATLAB Runtime startup cost in each subsequent class instantiation. When using NoteThe default behavior dictates that a new MATLAB Runtime be created for each instance of a class, so when
the class is destroyed, the MATLAB Runtime is destroyed as well. If you want to retain the
state of global variables (such as those allocated for drawing
figures, for instance), use the |
Example
The example creates a COM component called
When multiple instances of this class are instantiated in an application, only one MATLAB Runtime is initialized, and it is shared by each instance. | ||
Create subfolders needed for deployment and copy associated files to them. | -d | The \src and \distrib subfolders
are needed to package components. |
Syntax
|