--ActiveX Control for MathLink--

This is just a draft, yet to be much edited.

What is ActiveMathLink?

ActiveMathLink is an ActiveX control for MathLink, which can connect to a Mathematica kernel, make the kernel evaluate a string, obtain its result from the kernel, and disconnect the link to the kernel. If a graphic command is invoked, its result can be displayed on the control.

Since it uses ActiveX technology, ActiveMathLink cannot be used in any platforms but in Windows OS.

Properties and Methods

The properties and methods of ActiveMathLink are listed below:

Property List




Background color


If true, the control is connected to the kernel.


Text color on the control if DisplayTextQ is true


If true, the evaluation result is also displayed on the control; if false, it is not.


Height of the control


Initial string to be evaluated when a Mathematica kernel is loaded and connected
Default string is as follows:
$Display := OpenTemporary[];
$DisplayFunction = (Module[{tmpstream = $Display, tmpfile}, tmpfile = tmpstream[[1]]; Close[tmpstream]; Display[tmpfile, #1, "Metafile"]; LinkWrite[$ParentLink, DisplayEndPacket[tmpfile]]]; #1)&;
SetOptions[ "stdout", PageWidth->65];
Format[LineBreak[_]]:= "";
Format[Continuation[_]]:= " ";SetAttributes[MessagePacket, HoldFirst];$CharacterEncoding ="Unicode";


Left position of the control


Input string to be evaluated by the kernel


Message string from the kernel


Output string or evaluation result


Path to the kernel
Default string is as follows:
-linklaunch -linkname '\Program Files\Wolfram Research\Mathematica\3.0\MathKernel'


If true, an image is stretched to the size of the control; if false, it is not.


Top position of the control


Width of the control

Method List




Connect to the kernel


Disconnect the link


Evaluate an input string in MathIn and get a result in MathOut


Stop an evaluation process

ActiveMathLink was tested with Mathematica under Windows 98 Japanese version, and has been working all right with Visual Basic 6.0 and Internet Explorer.

How to get ActiveMathLink

ActiveMathLink is FREE! Your comments are always welcome.

Getting ActiveMathLink is quite easy if you know how to decompress LHA files:

  1. Download the compressed file;

  2. Decompress it;

  3. Invoke SETUP.EXE;

  4. Follow the messages on the screen.

Sample: Using ActiveMathLink with Internet Explorer

Here a sample is presented to demonstrate how to use ActiveMathLink with Internet Explorer 4.0. 

First, type the following HTML source code.

Note: For your convenience, this source code is included in the downloadable compressed file above. It is possible that the code does not work with Internet Explorer 3.0.  If so, uncomment the section in black, use buttons instead and change the textarea name from INPUT to, say, INPUTSTR.


<TR ALIGN="center">
<TD VALIGN="center" BGCOLOR=#4040C0><FONT SIZE=7 COLOR=#FFFF00><I>ActiveMathLink</I></FONT>
<TD BGCOLOR=#FF4000><FONT SIZE=4 COLOR=#FFFFFF><A NAME="ConnectBtn"><B>&nbsp;Connect&nbsp;</B></A></TD>
<TD BGCOLOR=#FF4000><FONT SIZE=4 COLOR=#FFFFFF><A NAME="EvaluateBtn"><B>&nbsp;Evaluate&nbsp;</B></A></TD>
<TD BGCOLOR=#FF4000><FONT SIZE=4 COLOR=#FFFFFF><A NAME="DisconnectBtn"><B>&nbsp;Disconnect&nbsp;</B></A></TD>

<!--If button controls are used instead of strings,
<BR><CENTER><INPUT TYPE="button" NAME="ConnectBtn" VALUE="Connect">
<INPUT TYPE="button" NAME="EvaluateBtn" VALUE="Evaluate">
<INPUT TYPE="button" NAME="DisconnectBtn" VALUE="Disconnect">

Sub Window_OnLoad() 'When the page is loaded
ActiveML.BGColor=&HF0F0F0 'Set the background color of the ActiveX control
ActiveML.DisplayTextQ=1 'Display the result on the control
End Sub

Sub ConnectBtn_OnClick() 'Connect to the Mathematica kernel
End Sub

Sub DisconnectBtn_OnClick() 'Disconnect the link to the Mathematica kernel
End Sub

Sub EvaluateBtn_OnClick() 'Evalution
If ActiveML.Connected Then 'If the control is connected to the kernel
ActiveML.MathIn=Input.Value 'Input is the input string. Copy it to MathIn.
ActiveML.Evaluate 'Invoke the evaluation command
Out.Value=ActiveML.MathOut 'Get the result in MathOut and copy it to Out.
Else 'If the control is not yet connected to the kernel
MsgBox "Not connected to Kernel yet.",0,"Connection error"
'Display the error message
End If
End Sub

<FONT SIZE=5 COLOR=#995599>Input:</FONT><BR>
<TEXTAREA NAME="Input" Rows=3 Cols=70></TEXTAREA><BR>

<FONT SIZE=5 COLOR=#995599>Output:</FONT><BR>
<TEXTAREA NAME="Out" Rows=5 Cols=70></TEXTAREA>

<OBJECT ID="ActiveML" WIDTH=500 HEIGHT=300 CLASSID="CLSID:C06D7B50-B613-11D2-81BB-00400535F9E7">


Execute the code or read it from Internet Explorer, and you get:


Press [Connect] and the control will be connected to the kernel. Type your command in the [Input] box. Press [Evaluate], and you get its result in the [Output] box.


Images can be displayed on the control. If you invoke a Plot command, you get a graph on the control.


If the DisplayTextQ property is true, evaluation results are displayed also on the control.

By pressing [Disconnect], the link to the kernel is disconnected.

Known bug

The control cannot handle special characters and characters other than ASCII.


Visual Basic sample program gMini FrontEndh included in MathLink Developerfs Kits.