Using the vendll32.dll

Use this forum to post Vensim related questions.
Post Reply
mruud
Member
Posts: 23
Joined: Fri Mar 28, 2003 7:19 am

Using the vendll32.dll

Post by mruud »

Hi,
I have from time to time done some simple GUI programming for Vensim models using Visual Basic and VENDLL32.DLL. In other contexts I have been using a tool called PowerBuilder (from Sybase) for database application development. Today I did a simple experiment to see if it was possible to use PowerBuilder together with Vensim. I did a quick and dirty copy and paste of external function declarations (with some minor changes). Most of the functions I tested (like: vensim_continue_simulation, vensim_start_simulation, vensim_finish_simulation) seemed to work, giving meaningful return values. One quite essential function, vensim_command, did anyhow only give me a return value of 0.
Is it in any way possible to make this work, or should I just give up trying?
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

What commands were you passing to the DLL?

If it works fine with vensim_start stop etc, it should be fine with vensim_command (as long as you pass the correct type of parameter).

Tony.
mruud
Member
Posts: 23
Joined: Fri Mar 28, 2003 7:19 am

Post by mruud »

Hi
FUNCTION int vensim_command(string kom) LIBRARY "VENDLL32.DLL"
FUNCTION int vensim_be_quiet(long quietflag) LIBRARY "VENDLL32.DLL"
FUNCTION int vensim_get_info(int infowanted, string beskr, int lengde) LIBRARY "VENDLL32.DLL"
FUNCTION int vensim_start_simulation(int loadfirst, int game, int overwrite) LIBRARY "VENDLL32.DLL"
FUNCTION int vensim_get_val(string varname, double varval) LIBRARY "VENDLL32.DLL"
FUNCTION int vensim_continue_simulation(int stepp) LIBRARY "VENDLL32.DLL"
FUNCTION int vensim_finish_simulation() LIBRARY "VENDLL32.DLL"
and then:
result= vensim_command("SPECIAL>LOADMODEL|test3.vmf")
returning 0

result= vensim_start_simulation(1,0,1)
returning 1
result= vensim_continue_simulation(10)
returning 1 ten times then 0
result= vensim_finish_simulation()
returning 1 and a new vdf-file was created in the default directory.

It looks like I have run vensim without a model(!?) because the vdf-file do not have any refrences to a model...
Morten
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

>> result= vensim_command("SPECIAL>LOADMODEL|test3.vmf")

I don't know the correct syntax, but can you create a string variable first and pass that to vensim_command?

PowerBuilder may well be passing the wrong kind of string to Vensim. Just a guess, but worth a try.

Tony.
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

You could also try declaring the function differently.

FUNCTION int vensim_command(REF string kom) LIBRARY "VENDLL32.DLL"

That should pass the string by reference. Again, something to try. I am sure it will work, it is just getting the correct syntax.

Tony.
mruud
Member
Posts: 23
Joined: Fri Mar 28, 2003 7:19 am

Post by mruud »

Hi
Tryed both without any luck :What can be the difference between VB sending this string and PB doing the same?
Morten

FUNCTION int vensim_command(REF string kommentar) LIBRARY "VENDLL32.DLL"

kom="SPECIAL>LOADMODEL|test3.vmf"
result= vensim_command(kom)
Messagebox(kom,result)
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

When having a search yesterday, there was a lot mentioned about unicode in relation to PowerBuilder. Maybe that could be the cause of the problem.

I'll search some more when I get a chance.

Tony.
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

The Vensim DLL is expecting the be passed the address (32 bit) of a null terminated UTF-8 string. I don't know powerbuilder but it probably requires a special cast or conversion to make that happen.
mruud
Member
Posts: 23
Joined: Fri Mar 28, 2003 7:19 am

Post by mruud »

Hi,
The last information did put me on track :).
There are probably better ways to do this but this PowerBuilder code did function:

B=Blob("SPECIAL>LOADMODEL|C:\Data\MindLabAS\Prosjekter\AST\08Test\test3.vpm ",EncodingUTF8!)

kom=string(B)

result= vensim_command(kom)

As you can see I also had to save the model as a package..
Thanks a lot!

Morten
Post Reply