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.

 

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.

 

C:\EES32\EES.EXE /HIDE

 

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 5 that sends the WM_DDE_INITIATE message to EES.

 

procedure TForm1.doInitiate(Sender: TObject);

  var theApp, theTopic:Atom;

       lParam:longInt;

begin

  theApp:=GlobalAddAtom('EES');

  theTopic:=GlobalAddAtom('');

  lParam:=MakeLong(theApp,theTopic);

  SendMessage(HWND(-1),wm_DDE_Initiate,Handle,lParam);

  GlobalDeleteAtom(theApp);

  GlobalDeleteAtom(theTopic);

end;

 

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

  var AppName,TopicName:charString;

      S:shortString;

begin

    EESWindowHandle:=theMessage.wParam;

end;

 

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

  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 the EXCEL and MATLAB examples for additional information.