| MATLAB® | ![]() |
| On this page… |
|---|
Deploying ActiveX® Controls Requiring Run-Time Licenses Using Microsoft® Forms 2.0 Controls |
When you deploy a Microsoft® ActiveX® control that requires a run-time license, you must include a license key, which the control reads at run-time. If the key matches the control's own version of the license key, an instance of the control is created. Use the following procedure to deploy a run-time-licensed control with a MATLAB® application.
First, create an M-file to build the control. This M-file must contain two elements:
The pragma %#function actxlicense. This pragma causes the MATLAB® Compiler™ to embed a function named actxlicense into the stand alone executable file you build.
A call to actxcontrol to create the control.
Place this M-file in a directory outside of the MATLAB code tree.
Here is an example M-file.
function buildcontrol
%#function actxlicense
h=actxcontrol('MFCCONTROL2.MFCControl2Ctrl.1',[10 10 200 200]);Change to the directory where you placed the M-file you created to build the control. Call the function you defined in the M-file. When it executes this function, MATLAB determines whether the control requires a run-time license. If it does, MATLAB creates another M-file, named actxlicense.m, in the current working directory. The actxlicense function defined in this file provides the license key to MATLAB at run-time.
Next, call MATLAB Compiler to create the stand alone executable from the file you created to build the control. The executable contains both the function that builds the control and the actxlicense function.
mcc -m buildcontrol
Finally, distribute buildcontrol.exe, buildcontrol.ctf, and the control (.ocx or .dll).
You may encounter problems when creating or using Microsoft® Forms 2.0 controls in MATLAB. Forms 2.0 controls are designed for use with applications enabled by Microsoft® Visual Basic® for Applications (VBA). An example is Microsoft Office software.
To work around these problems, use the following replacement controls, or consult article 236458 in the Microsoft Knowledge Base for further information:
http://support.microsoft.com/default.aspx?kbid=236458
You may see this behavior with any of the following Forms 2.0 controls:
Forms.TextBox.1
Forms.CheckBox.1
Forms.CommandButton.1
Forms.Image.1
Forms.OptionButton.1
Forms.ScrollBar.1
Forms.SpinButton.1
Forms.TabStrip.1
Forms.ToggleButton.1
Microsoft recommends the following replacements:
| Old | New |
|---|---|
Forms.TextBox.1 | RICHTEXT.RichtextCtrl.1 |
Forms.CheckBox.1 | vidtc3.Checkbox |
Forms.CommandButton.1 | MSComCtl2.FlatScrollBar.2 |
Forms.TabStrip.1 | COMCTL.TabStrip.1 |
COM collections are a way to support groups of related COM objects that can be iterated over. A collection is itself a special interface with a Count property (read only), which contains the number of items in the collection, and an Item method, which allows you to retrieve a single item from the collection.
The Item method is indexed, which means that it requires an argument that specifies which item in the collection is being requested. The data type of the index can be any data type that is appropriate for the particular collection and is specific to the control or server that supports the collection. Although integer indices are common, the index could just as easily be a string value. Often, the return value from the Item method is itself an interface. Like all interfaces, you should release this interface when you are finished with it.
This example iterates through the members of a collection. Each member of the collection is itself an interface (called Plot and represented by a MATLAB COM object called hPlot.) In particular, this example iterates through a collection of Plot interfaces, invokes the Redraw method for each interface, and then releases each interface:
hCollection = hControl.Plots;
for i = 1:hCollection.Count
hPlot = hCollection.invoke('Item', i);
hPlot.Redraw;
hPlot.release;
end;
hCollection.release;Distributed Component Object Model (DCOM) is a protocol that allows clients to use remote COM objects over a network. Additionally, MATLAB can be used as a DCOM client with remote Automation servers if the operating system on which MATLAB is running is DCOM enabled.
Note If you use MATLAB as a remote DCOM server, all MATLAB windows appears on the remote machine. |
Limitations of MATLAB COM support are:
MATLAB only supports indexed collections.
COM controls are not printed with figure windows.
![]() | Examples of MATLAB® Software as an Automation Client | MATLAB® COM Automation Server Support | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |