Page 1 of 1

vensim & DLL

Posted: Sat Jul 14, 2007 2:52 pm
by gk720421
I use c++ to make a DLL(Fej1023). I want use the DLL in vensim,but the result isn't the same.

I declare several variables in C code to replace variables in vensim , for example: 'double groundW' is computed, and I write functions to show it and the count result in the same interface in vensim , but the 'groundW' and 'gaW' are just out of my expect , become very huge , at first I think it's the problem of over flow , but I find the difference is the same , for each time I enter the same input .
for example , if enter 180 in 'need' of the vensim interface and u enter 180 again , u'll find that the difference of groundW of two times is 8000 , but the number of groundW should be the same if u key in the same 'need' .


thank you for help !(append file is the C code and vensim file)
:D



[Edited on 7-15-2007 by gk720421]

[Edited on 7-15-2007 by gk720421]

[Edited on 7-15-2007 by gk720421]

Posted: Sat Jul 14, 2007 5:43 pm
by Administrator
I cannot work out what you are trying to do here. All I can really suggest is stepping through the C code using the debugger and see what values Vensim is passing to the DLL. Make sure it is calculating what you expect it to.

All the best,

Tony.

Posted: Sun Jul 15, 2007 3:50 am
by gk720421
I send the DLL . you can include it in my vensim.

Please help me,thanks.



[Edited on 7-15-2007 by gk720421]

Posted: Sun Jul 15, 2007 2:15 pm
by Administrator
I was able to build the DLL fine and step through the code using the debugger, I just cannot figure out what you are trying to do.

All the best,

Tony.

Posted: Sun Jul 15, 2007 3:00 pm
by gk720421
ok! thank you~

I meen I use the "fej1023. dll" in "example1" VS. I don't use it in "oriange"

I find the final answers(supply2) are different , I don't know what is wrong.

[Edited on 7-15-2007 by gk720421]

[Edited on 7-15-2007 by gk720421]

Posted: Sun Jul 15, 2007 7:58 pm
by Administrator
There must be an error in your C code if it is not giving the same answer as you expect. Have you stepped through the code in the debugger to check it is doing what you want?

Tony.

Posted: Mon Jul 16, 2007 8:56 am
by gk720421
1. I find that at first when I use "Run a Simulation" in example01(with fej1023.dll) VS. oriange
,and the final supply2's answers are correct.

2. If I input other number in "need" in example01 . I must close it, open the example01 again
the supply2' answer VS. oriange is the same.
3. But I find if I can't use "Automatically simulate on change" in 'example01' and 'oriange'
because the final supply2's answers are different.

I don't know what' wrong

Posted: Mon Jul 16, 2007 10:42 am
by Administrator
Do you need to reset the internal variables in the DLL?

static long double groundW=50;
static long double inflow2=20;
static long double gaw=0;


Use the function

CFUNCTION int PASCAL simulation_setup(int iniflag)
{
groundW=50;
inflow2=20;
gaw=0;
return(1) ;
}

Does this now give you what you need?

Tony.

Posted: Mon Jul 16, 2007 5:51 pm
by gk720421
thank you for tell me this information , but I am still testing the code ,
after using the code you give me , the variabls is not jumping any more,
but the result is not right still .

Posted: Mon Jul 16, 2007 9:43 pm
by Administrator
>> thank you for tell me this information , but I am still testing
>> the code , after using the code you give me , the variabls
>> is not jumping any more, but the result is not right still .
The problem is in your C code, you need to step through it using the debugger and make sure it is doing what you need it to.

Tony.