Contents - Index


Example .DLP 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++.  The source code follows. 

 

______________________________________________________

 

#include <windows.h>

#include <stdlib.h>

#include <string.h>

 

BOOL APIENTRY DllMain( HANDLE hModule, 

                       DWORD  ul_reason_for_call, 

                       LPVOID lpReserved

          )

{

    return TRUE;

}

 

// Structure for handling ees calling syntax

struct EesParamRec {

  double value;

  struct EesParamRec *next;

};

 

// Tell C++ to use the "C" style calling conventions rather than the C++ mangled names

extern "C"

  

__declspec (dllexport) void MDAS_C(char s[256], int &mode, struct EesParamRec *input_rec, struct EesParamRec *output_rec) {

   double v, v1, v2;

   int NInputs, NOutputs;

   EesParamRec *outputs, *inputs;

 

   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;

   }

   inputs=inputs_rec;

   NInputs=0;

   while (inputs!=NULL) {

      NInputs++

      inputs=inputs->next;

   }

   if (NInputs!=2) {

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

     mode=1;

     return;

   };

   outputs=output_rec;

   NOutputs=0;

   while (outputs!=NULL) {

       NOutputs++;

       outputs=outputs->next;

   }

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

   inputs=input_rec;

   v1=inputs->value;

   inputs=inputs->next;

   v2=inputs->value;

 

   v=v1*v2;

   outputs=output_rec;

   outputs->value=v;

   outputs=outputs->next;

   if (v2==0) {

     strcpy(s,"attempt to divide by zero in MDAS_C");

  mode=3;

  return;

   }

   v=v1/v2;

   outputs->value=v;

   outputs=outputs->next;

   outputs->value=v1+v2;

   outputs=outputs->next;

   outputs->value=v1-v2;

   mode=0;

};

 

______________________________________________

 

This procedure was compiled into file MDAS_C.DLP using the Microsoft Visual Studio C++ compiler.