Dll execute error

Dll execute error

nguyenthanhnam2310
Contributor Contributor
238 Views
2 Replies
Message 1 of 3

Dll execute error

nguyenthanhnam2310
Contributor
Contributor

Recently I tried with the DLL function in FlexSim. 

I wrote a simple dll like adding two numbers of type double, but when I ran, it didn't return the total but only the first input number. 

I want to know why this happen and how to avoid it when I build the dll. 

Below is my code in dll

// C LIBRARY FOR INPUT/OUTPUT STREAMS
#include <stdio.h>
#include <math.h>
// IN ORDER TO HAVE ACCESS TO FLEXSIM FUNCTIONS, INCLUDE FLEXSIMDEFS.H
#include "FlexsimDefs.h"
 
visible double dllcommand1(FLEXSIMINTERFACE)
{
// test passing parameters in usercommand
string par1=parstr(1);
pt("string parameter ");pt(par1);pr();
 
return 0;
}
 
visible double mydllfunction2(FLEXSIMINTERFACE)
{
pt("This will print to the Output Console");pr();
return 0;
}
 
visible double addfunction(double p1, double p2)
{
double a;
a = p1 + p2;
print(a); pr();
return a;
}

PS: the function mydllfunction2 is working fine, but the "addfunction" have the problem. I also attach my model too

 
0 Likes
Accepted solutions (1)
239 Views
2 Replies
Replies (2)
Message 2 of 3

joerg_vogel_HsH
Mentor
Mentor
Accepted solution

I have never done this before. But “a” is a command itself in FlexSim. So I would try to change the name of the local variable into a string that does not collide with any command featured in FlexSim or any other loaded library of the DLL.

0 Likes
Message 3 of 3

nguyenthanhnam2310
Contributor
Contributor

I try with other way in the C++ source code, and it worked.

And I think it's good to name the function is not collide with other functions as you suggest.

Below is what I changed. 

visible double addfunction(FLEXSIMINTERFACE) 
{
double p1 = parval(1);
double p2 = parval(2);
double Total_2num;
Total_2num = p1 + p2;
print(Total_2num); pr();
return Total_2num;
}
Anyway, thank you for your advice. 
0 Likes