External Functions
External Functions
Hi,
I am trying to build a dll using the venext.c
however when I run the dll in vensim it does not pass double values.
I write the value passed in a text file.
every time a double is passed it write the value passed as 0.0000
but when I pass a literal/string it is passed properly.
e.g if i pass cosine(.5) the value of x in the dll is 0.00
I have attached the venext.c file.
I have not made any changes to the venext.c file provided by vensim package.
I compile the venext.c in visual studio 6. I also tried using the VENEXT6.dsw and compiled the project yet the values passes are 0.
the only code i have added is
FILE* f;
double y=0;
f=fopen("B:\\test.txt","w");
y=x;
fprintf (f, "y = %f",y);
fclose(f);
Am I supposed to add any library files for double precision while compiling the project ?
I tried adding VENSIMDP.lib in the project.
[Edited on 8-2-2008 by aksdax]
I am trying to build a dll using the venext.c
however when I run the dll in vensim it does not pass double values.
I write the value passed in a text file.
every time a double is passed it write the value passed as 0.0000
but when I pass a literal/string it is passed properly.
e.g if i pass cosine(.5) the value of x in the dll is 0.00
I have attached the venext.c file.
I have not made any changes to the venext.c file provided by vensim package.
I compile the venext.c in visual studio 6. I also tried using the VENEXT6.dsw and compiled the project yet the values passes are 0.
the only code i have added is
FILE* f;
double y=0;
f=fopen("B:\\test.txt","w");
y=x;
fprintf (f, "y = %f",y);
fclose(f);
Am I supposed to add any library files for double precision while compiling the project ?
I tried adding VENSIMDP.lib in the project.
[Edited on 8-2-2008 by aksdax]
- Attachments
-
[The extension t.c has been deactivated and can no longer be displayed.]
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
Actually I just tried your code and it leaves after a the simulation the line y = 100.000000 in the text file as would be expected using the sample model. If I use a model with just 1 variable
blah=cosine(0.5)
then the file contains
y = 0.500000
Of course all calls to cosine at all times will overwrite the file so make sure there is only 1 variable in the model when testing. You might try opening the DLL you create in a debugger to better figure out what is going on.
blah=cosine(0.5)
then the file contains
y = 0.500000
Of course all calls to cosine at all times will overwrite the file so make sure there is only 1 variable in the model when testing. You might try opening the DLL you create in a debugger to better figure out what is going on.
Hi,
I have tried to install vensim on another PC and I re-complied the dll and I ran the debugger I am posting the screenshot of the debugger. you can see that the values passed by vensim is 0.00000 for both the functions cosine() and inrange()
The code and the visual project is the one which is provided by you guys I have not modified any code.
[Edited on 8-6-2008 by aksdax]
[Edited on 8-6-2008 by aksdax]
[Edited on 8-6-2008 by aksdax]
[Edited on 8-6-2008 by aksdax]
I have tried to install vensim on another PC and I re-complied the dll and I ran the debugger I am posting the screenshot of the debugger. you can see that the values passed by vensim is 0.00000 for both the functions cosine() and inrange()
The code and the visual project is the one which is provided by you guys I have not modified any code.
[Edited on 8-6-2008 by aksdax]
[Edited on 8-6-2008 by aksdax]
[Edited on 8-6-2008 by aksdax]
[Edited on 8-6-2008 by aksdax]
- Attachments
-
- untitledw.JPG (179.88 KiB) Viewed 4352 times
other file
- Attachments
-
- untitled(2).JPG (181.17 KiB) Viewed 4352 times
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
Hi,
Still the result is the same. I generally create just one variable and try and test my function. Could it be that the copy that i have is corrupt ?
everything else works just fine....
I could understand if only my code did not work or the dll i create does not work but in this case the code and dll created from your project also does not work
Still the result is the same. I generally create just one variable and try and test my function. Could it be that the copy that i have is corrupt ?
everything else works just fine....
I could understand if only my code did not work or the dll i create does not work but in this case the code and dll created from your project also does not work
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
Using the DLL you created from the sample open the extern.mdl model in the same directory and simulate it. Assuming this works look at the variable called "cos time" and see what it does. It should be a wave between -1 and 1 with period 2 pi. If you get this behavior then x is being passed correctly.
Note to make a graph of "cos time" you will need to select it into the workbench using the Variable tab of the control panel as it does not appear on the sketch view.
Note to make a graph of "cos time" you will need to select it into the workbench using the Variable tab of the control panel as it does not appear on the sketch view.