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 inefficient as EES must be repeatedly loaded into memory.  An alternative approach is to use dynamic data exchange (DDE) messages.  Many popular programs can use the DDE message exchange format including MATLAB and EXCEL.   However, MATLAB is no longer actively supporting DDE, according to its website. Note that any of the macro commands.  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);

  var cfile,command:atom;

       lParam:longint;

       CSTR:charString;

begin

  StrCopy(CStr,'c:\ees32\myMacro.emf');

  cfile:=GlobalAddAtom(CStr);

  Command:=GlobalAddAtom('PLAY');

  lParam:=MakeLong(cfile,Command);

  PostMessage(EESWindowHandle,wm_DDE_REQUEST,Handle,lParam); 

end;

 

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);

  var cfile,command:atom;

       lParam:longint;

       CSTR:charString;

begin

  StrCopy(CStr,'c:\ees32\myFile.EES');

  cfile:=GlobalAddAtom(CStr);

  Command:=GlobalAddAtom('RUN');

  lParam:=MakeLong(cfile,Command);

  PostMessage(EESWindowHandle,wm_DDE_REQUEST,Handle,lParam); 

end;

 

The QUIT command which terminates EES.  Here's how it can be sent.

 

procedure TForm1.QuitClick(Sender: TObject);

  var cformat,command:atom;

      lParam:longint;

begin

  cformat:=GlobalAddAtom('');

  Command:=GlobalAddAtom('QUIT');

  lParam:=MakeLong(cformat,Command);

  PostMessage(EESWindowHandle,wm_DDE_REQUEST,Handle,lParam); 

end;

 

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);

  var cformat,command:atom;

      lParam:longint;

      CString:array[0..256] of char;

begin

  StrPCopy(CString,'[Open C:\EES32\Examples\Regen.EES]');

  cformat:=GlobalAddAtom(' ');

  Command:=GlobalAddAtom(CString);

  lParam:=MakeLong(cformat,Command);

  PostMessage(EESWindowHandle,wm_DDE_REQUEST,Handle,lParam); end;

 

 

See also: EXCEL and MATLAB DDE examples

              EXCEL Macro commands

              MATLAB Macro commands