Contents - Index
Dynamic Data Exchange (DDE)
The easiest way to run an EES macro file from another application is to simply start EES and provide the macro file name (with an .EMF filename extension) as a parameter on the command line. However, this disadvantage of this method is that EES quits when the macro file commands have been executed. If it is necessary to call EES repeatedly, this method becomes very inefficient as EES must be repeatedly loaded into memory. An alternative approach is to use dynamic data exchange (DDE) messages. Many popular programs support the DDE message exchange format including MATLAB and EXCEL
Note that any of the macro commands can be sent directly from an external program to EES with the application's DDEExecute command. For example, the following command issued from EXCEL Visual Basic will cause EES to execute its SOLVETABLE command for Table 1. Note that when macro commands must be enclosed in square brackets.
Application.DDEExecute ChannelNumber, "[SOLVETABLE 'TABLE 1', Rows=1..10]"
The Professional version of EES must be running to receive a DDE message. This is not really a problem as EES can be started from a remote application using the Windows CreateProcess command. However, when EES starts, it normally displays its splash screen and waits for the user to click the OK button. To avoid having EES display the splash screen and wait for user input, supply /HIDE as a parameter on the command line, i.e., start EES with the following command.
After receiving this command EES will start in a minimized mode. Its icon will be visible in the Windows task bar, but the program will otherwise not be visible on the screen.
The calling program must next send EES a series of messages according to the DDE message protocol. The first message that must be sent is the WM_DDE_INITIATE message. This message is normally sent using the Windows SendMessage command. The SendMessage command requires four parameters. The first should be a broadcast message to all running applications. The second must be WM_DDE_INITIATE . The third is the handle of the calling application. EES will use this handle to send message back to the calling application. The final parameter is a global atom referring to 'EES', so that EES knows to act on this initiate message. Shown below is a code fragment in Delphi that sends the WM_DDE_INITIATE message to EES.
procedure TForm1.doInitiate(Sender: TObject);
var theApp, theTopic:Atom;
EES will respond to the WM_DDE_INITIATE message by sending the application a WM_DDE_ACK message. Included in this message is the handle to the EES application, here called EESWindowHandle, that the calling program must provide in following messages. A code segment that receives the WM_DDE_ACK message may appear as shown below.
procedure TForm1.GetACK(var theMessage:TMessage);
After the WM_DDE_INITIATE message has been received by EES, the calling application can next send a WM_DDE_REQUEST message to play a macro. The information sent to EES includes a global atom referring to the string 'PLAY' and a character string containing the DOS filename of the macro file. The complete file name should be sent, including the directory information and the .EMF filename extension. The code fragment below shows how this is done.
procedure TForm1.PlayMacro(Sender: TObject);
After receiving this message, EES will open the macro file and execute the instructions therein. It will then send a WM_DDE_ACK message to inform the calling program that the calculations are completed. When EES executes a macro file, it writes results to a specified text file. The calling application can open this text file to retrieve the results.
EES will also recognize other commands. The RUN filename request can be sent to EES using code shown below. When EES receives this request, it will open the specified file, solve the equations using the Solve command and write the Solution window to a file having the same name as the EES file with a .TXT filename extension.
procedure TForm1.RunFileMacro(Sender: TObject);
The QUIT command which terminates EES. Here's how it can be sent.
procedure TForm1.QuitClick(Sender: TObject);
EES will also execute any macro command sent by DDE that is implemented in the its Macro Command list. These commands must be enclosed with in square brackets, as shown.
procedure TForm1.ExecuteBtnClick(Sender: TObject);
CString:array[0..256] of char;
See the EXCEL and MATLAB examples for additional information.