Contents - Index


Example .FDL External Procedure in C++

 

MDAS is an acronym for 'multiply-divide-add-subtract'.  MDAS takes two input values and returns four outputs which are the product, the ratio, the sum, and the difference of the two numbers.  Although the MDAS procedure itself is no use, it is shown here to  illustrate how to write external procedures for EES in C++.  Note that EES will provide unit checking for external procedures if the external procedure provides a string for its inputs when Mode=-2 and a string for its outputs when Mode=-3.  That capability is illustrated in the following source code.

______________________________________________________

 

#include <windows.h>

#include <stdlib.h>

#include <string.h>

 

// Use extern "C" to prevent C++ name mangling

extern "C"

 

void FAR  _stdcall _export MDAS_C(char s[256], int& clen, int& mode,

   int& NInputs, double inputs[25], int& NOutputs, double outputs[25])

{

   if (mode==-1) {

     strcpy(s,"CALL MDAS_C(X,Y : M, D, A, S)");

     return;

   }

   if (mode==-2) {

     strcpy(s,"m,m");

     return;

   }

   if (mode==-3) {

     strcpy(s,"m^2, ,m,m");

     return;

   }   if (NInputs!=2) {

     strcpy(s,"MDAS_C expects two inputs");

     mode=1;

     return;

   };

   if (NOutputs!=4) {

     strcpy(s,"MDAS_C requires 4 outputs which are the product, difference, sum and difference of the two inputs.");

     mode=2;

     return;

   }

   strcpy(s,"");

 outputs[0]=inputs[0]*inputs[1];

   outputs[1]=inputs[0]/inputs[1];

   outputs[2]=inputs[0]+inputs[1];

   outputs[3]=inputs[0]-inputs[1];

   mode=0;

}

___________________________________________________________

 

This procedure was compiled into file MDAS_C.FDL using the Microsoft Visual Studio.