Example .DLF External Function in C++
The following source code creates a .DLF external function that returns the sum of two numbers. The function is accessed from EES with a statement of the following format; This function does not provide input or output units so there will be no unit checking when this function is called.
s=SUM_C(x,y)
_________________________________________________________
#include <windows.h>
// 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) double SUM_C(char s[256], int& mode, struct EesParamRec *input_rec)
{
double In1, In2, sum_res;
int NInputs;
if (mode==-1) {
strcpy(s,"a = SUM_C(b,c)"); // return example call string
return 0;
}
// Check the number of inputs
NInputs=0;
EesParamRec * aninput_rec=input_rec;
while (aninput_rec!= 0)
{
aninput_rec= aninput_rec->next;
NInputs++;
};
if (NInputs!=2) {
strcpy(s,"SUM_C expects two inputs");
return 0;
}
In1= input_rec->value;
input_rec=input_rec->next;
In2=input_rec->value;
sum_res = In1+In2;
return sum_res;
}
};
This procedure was compiled into file SUM_C.DLF using the Microsoft Visual Studio.