Page 1 of 3

vensim link matlab

Posted: Thu Aug 19, 2010 3:38 pm
by ahmadi2010
hi,My vensim is DSS & Ihave win 7 (64bit),How Can I link vensim to matlab?

Posted: Fri Aug 20, 2010 2:51 pm
by Administrator
There is already a thread on this subject, have a look at

http://www.ventanasystems.co.uk/forum/v ... php?t=4181

Posted: Fri Aug 20, 2010 7:45 pm
by ahmadi2010
Thanks for your help

my matlab pro. is 32bit,win 7(64bit),& when I search in my computer I can't find Vensim DLL as a separate pro.Can this different bit work properly together or not?

I saw that link.Do you mean I should write a program in DLL. I'm confused.How can I open it.

Posted: Fri Aug 20, 2010 9:22 pm
by tomfid
You don't open the .dll as a program; you load it via code in matlab - see http://www.mathworks.com/access/helpdes ... 43202.html for details. Your matlab code will be fairly close to the code in the .dll examples that install with Vensim (look in the dll folder in your Vensim program directory).

A good first step would be to see if you can load the library and view the functions, as in
http://www.mathworks.com/access/helpdes ... tml#f42310

if not(libisloaded('libmx'))
hfile = [matlabroot '\extern\include\matrix.h'];
loadlibrary('libmx', hfile);
end
libfunctionsview libmx

Replace libmx above with ven32dll (which should be in your windows directory, e.g. c:\windows\system32 on XP) and hfile with C:\Program Files\Vensim\dll\vendll.h (or the path to your dll folder in the Vensim program directory).

Hopefully this will work; unfortunately I don't have a copy of Matlab to test with.

Tom

Posted: Sat Aug 21, 2010 7:00 pm
by ahmadi2010
Thank you Tom for your help

I run these two (as you said):
if not(libisloaded('libmx'))
hfile = [matlabroot '\extern\include\matrix.h'];
loadlibrary('libmx', hfile);
end
libfunctionsview libmx

&

if not(libisloaded('ven32dll'))
hfile = [matlabroot '\extern\include\matrix.h'];
loadlibrary('ven32dll', hfile);
end
libfunctionsview ven32dll

but for both of them, matlab gives me this error:

??? Error using ==> loadlibrary at 263
microsoft visual C++ 2005 is required to use this feature.


I checked my computer & I have microsoft visual C++ 2005.
even I installed it again after this error but it gives me that error again!!!!!!!!

Posted: Mon Aug 23, 2010 10:29 am
by bob@vensim.com
It sounds like you should contact technical support for Matlab.

Posted: Mon Aug 23, 2010 8:15 pm
by ahmadi2010
Thanks

1)My previous verson of Matlab-soft was 2008a,I unistalled it & installed Matlab 2010(R 2009a), then after run this program:

>> if not(libisloaded('libmx'))
hfile = [matlabroot '\extern\include\matrix.h'];
loadlibrary('libmx', hfile);
end
libfunctionsview libmx

it gives me :

Warning: Warnings messages were produced while parsing. Check the functions you
intend to use for correctness. Warning text can be viewed using:
[notfound,warnings]=loadlibrary(...)
> In loadlibrary at 399

And it opens a table (it’s title Function Is Library libmx)
…………………………………
And when run:

if not(libisloaded('ven32dll'))
hfile = [matlabroot '\extern\include\matrix.h'];
loadlibrary('ven32dll', hfile);
end
libfunctionsview ven32dll
…………………..
It gives me :

Warning: Warnings messages were produced while parsing. Check the functions you
intend to use for correctness. Warning text can be viewed using:
[notfound,warnings]=loadlibrary(...)
> In loadlibrary at 399
??? Error using ==> loadlibrary at 480
There was an error loading the library "ven32dll"
The specified module could not be found.

Caused by:
Error using ==> loaddefinedlibrary
The specified module could not be found.
.....................................................................................

2) I couldn’t open these files: http://www.mathworks.com/access/helpdes ... 43202.html
http://www.mathworks.com/access/helpdes ... tml#f42310

Can any one help me please ?

Posted: Mon Aug 23, 2010 8:27 pm
by tomfid
Sounds like you need to check your system directories to see if the dll is installed. Or, just reinstall Vensim, and be sure that the .dll option is checked.

Tom

Posted: Tue Aug 24, 2010 10:22 am
by bob@vensim.com
The libraries name is vendll32 not ven32dll - that may be the problem.

Posted: Tue Aug 24, 2010 12:24 pm
by ahmadi2010
now I try this :

>> if not(libisloaded('vendll32'))
hfile = [matlabroot '\extern\include\matrix.h'];
loadlibrary('vendll32', hfile);
end
libfunctionsview vendll32
...........................................
it gives me :

Warning: Warnings messages were produced while parsing. Check the functions you
intend to use for correctness. Warning text can be viewed using:
[notfound,warnings]=loadlibrary(...)
> In loadlibrary at 399
??? Error using ==> loadlibrary at 480
There was an error loading the library "vendll32"
The specified module could not be found.

Posted: Tue Aug 24, 2010 7:57 pm
by tomfid
Sorry about the name mistake. Did you look in your system folders to see if the .dll is installed?

Tom

Posted: Wed Aug 25, 2010 8:03 am
by ahmadi2010
you are wellcome

Thank you very much for your helo;

as I seid before, I have win7, matlab 64(bit),and in subfolder of windows\system64, I checked & saw this file vendll32.
Is it enough to know if dll is installed?

Posted: Wed Aug 25, 2010 9:06 am
by arraywanted
I think your header file (matrix.h) is the wrong one. You got that one from the example with the libmx library on the mathworks page, didn't you? That won't work for vensim.

The correct header file is vendll.h, it can be found in the same folder as vendll32.lib.
Now, if you navigate to that folder after opening matlab, you can simply type

loadlibrary('vendll32','vendll').

Posted: Wed Aug 25, 2010 1:57 pm
by ahmadi2010
Thank you

Yes,I see the both of them in DLL subdirectory: VenDLL32.lib & Vendll.h
Now I try that with full address of Vendll.h:
if not(libisloaded('vendll32'))
hfile = ['C:\Program Files (x86)\Vensim\dll\vendll.h'];
loadlibrary('vendll32',hfile);
end
libfunctionsview vendll32
……………………..
It’s response is :
Warning: Warnings messages were produced while parsing. Check the functions you
intend to use for correctness. Warning text can be viewed using:
[notfound,warnings]=loadlibrary(...)
> In loadlibrary at 399
Error loading library intermediate output follows.
The actual error is at the end of this output.
*********

Type 'HWND' was not found. Defaulting to type error.

Found on line 111 of input from line 110 of file C:\\Program Files (x86)\\Vensim\\dll\\vendll.h

Type 'HWND' was not found. Defaulting to type error.

Found on line 117 of input from line 116 of file C:\\Program Files (x86)\\Vensim\\dll\\vendll.h

Type 'HWND' was not found. Defaulting to type error.

Found on line 128 of input from line 127 of file C:\\Program Files (x86)\\Vensim\\dll\\vendll.h

Type 'HWND' was not found. Defaulting to type error.

Found on line 136 of input from line 135 of file C:\\Program Files (x86)\\Vensim\\dll\\vendll.h

Type 'HWND' was not found. Defaulting to type error.

Found on line 142 of input from line 141 of file C:\\Program Files (x86)\\Vensim\\dll\\vendll.h

Type 'HWND' was not found. Defaulting to type error.

Found on line 153 of input from line 152 of file C:\\Program Files (x86)\\Vensim\\dll\\vendll.h
*********
??? Error using ==> loadlibrary at 428
Building vendll32_thunk_pcwin64 failed. Compiler output is:
vendll32_thunk_pcwin64.c
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(110) : error C2146: syntax error : missing
')' before identifier 'pwindow'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(110) : error C2081: 'HWND' : name in formal
parameter list illegal
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(110) : error C2061: syntax error :
identifier 'pwindow'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(110) : error C2059: syntax error : ';'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(110) : error C2059: syntax error : ','
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(110) : error C2059: syntax error : ')'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(116) : error C2146: syntax error : missing
')' before identifier 'pwindow'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(116) : error C2081: 'HWND' : name in formal
parameter list illegal
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(116) : error C2061: syntax error :
identifier 'pwindow'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(116) : error C2059: syntax error : ';'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(116) : error C2059: syntax error : ')'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(127) : error C2146: syntax error : missing
')' before identifier 'window'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(127) : error C2061: syntax error :
identifier 'window'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(127) : error C2059: syntax error : ';'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(127) : error C2059: syntax error : ','
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(127) : error C2059: syntax error : ')'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(135) : error C2146: syntax error : missing
')' before identifier 'pwindow'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(135) : error C2081: 'HWND' : name in formal
parameter list illegal
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(135) : error C2061: syntax error :
identifier 'pwindow'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(135) : error C2059: syntax error : ';'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(135) : error C2059: syntax error : ','
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(135) : error C2059: syntax error : ')'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(141) : error C2146: syntax error : missing
')' before identifier 'pwindow'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(141) : error C2081: 'HWND' : name in formal
parameter list illegal
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(141) : error C2061: syntax error :
identifier 'pwindow'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(141) : error C2059: syntax error : ';'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(141) : error C2059: syntax error : ')'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(152) : error C2146: syntax error : missing
')' before identifier 'window'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(152) : error C2081: 'HWND' : name in formal
parameter list illegal
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(152) : error C2061: syntax error :
identifier 'window'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(152) : error C2059: syntax error : ';'
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(152) : error C2059: syntax error : ','
C:\Program Files\MATLAB\R2010a\extern\include\vendll.h(152) : error C2059: syntax error : ')'
vendll32_thunk_pcwin64.c(87) : error C2065: 'HWND' : undeclared identifier
vendll32_thunk_pcwin64.c(87) : error C2146: syntax error : missing ';' before identifier 'p1'
vendll32_thunk_pcwin64.c(87) : error C2065: 'p1' : undeclared identifier
vendll32_thunk_pcwin64.c(88) : error C2275: 'int32' : illegal use of this type as an expression
vendll32_thunk_pcwin64.c(44) : see declaration of 'int32'
vendll32_thunk_pcwin64.c(88) : error C2146: syntax error : missing ';' before identifier 'p2'
vendll32_thunk_pcwin64.c(88) : error C2065: 'p2' : undeclared identifier
vendll32_thunk_pcwin64.c(91) : error C2065: 'p1' : undeclared identifier
vendll32_thunk_pcwin64.c(91) : error C2146: syntax error : missing ')' before identifier 'HWND'
vendll32_thunk_pcwin64.c(91) : error C2065: 'HWND' : undeclared identifier
vendll32_thunk_pcwin64.c(91) : error C2100: illegal indirection
vendll32_thunk_pcwin64.c(91) : error C2059: syntax error : ')'
vendll32_thunk_pcwin64.c(91) : error C2297: '*' : illegal, right operand has type 'const char *'
vendll32_thunk_pcwin64.c(92) : error C2065: 'p1' : undeclared identifier
vendll32_thunk_pcwin64.c(92) : error C2065: 'p1' : undeclared identifier
vendll32_thunk_pcwin64.c(92) : error C2065: 'p1' : undeclared identifier
vendll32_thunk_pcwin64.c(93) : error C2065: 'p2' : undeclared identifier
vendll32_thunk_pcwin64.c(94) : error C2065: 'p2' : undeclared identifier
vendll32_thunk_pcwin64.c(94) : error C2065: 'p2' : undeclared identifier
vendll32_thunk_pcwin64.c(94) : error C2065: 'p2' : undeclared identifier
vendll32_thunk_pcwin64.c(95) : error C2059: syntax error : ','
vendll32_thunk_pcwin64.c(95) : error C2146: syntax error : missing ')' before identifier 'HWND'
vendll32_thunk_pcwin64.c(95) : error C2146: syntax error : missing ')' before identifier 'HWND'
vendll32_thunk_pcwin64.c(95) : error C2065: 'HWND' : undeclared identifier
vendll32_thunk_pcwin64.c(95) : error C2059: syntax error : 'type'
vendll32_thunk_pcwin64.c(99) : error C2061: syntax error : identifier 'int32int32int32int32Thunk'
vendll32_thunk_pcwin64.c(99) : error C2059: syntax error : ';'
vendll32_thunk_pcwin64.c(99) : error C2059: syntax error : 'type'
vendll32_thunk_pcwin64.c(146) : error C2065: 'HWND' : undeclared identifier
vendll32_thunk_pcwin64.c(146) : error C2146: syntax error : missing ';' before identifier 'p3'
vendll32_thunk_pcwin64.c(146) : error C2065: 'p3' : undeclared identifier
vendll32_thunk_pcwin64.c(153) : error C2065: 'p3' : undeclared identifier
vendll32_thunk_pcwin64.c(153) : error C2146: syntax error : missing ')' before identifier 'HWND'
vendll32_thunk_pcwin64.c(153) : error C2065: 'HWND' : undeclared identifier
vendll32_thunk_pcwin64.c(153) : error C2100: illegal indirection
vendll32_thunk_pcwin64.c(153) : error C2059: syntax error : ')'
vendll32_thunk_pcwin64.c(153) : error C2297: '*' : illegal, right operand has type 'const char *'
vendll32_thunk_pcwin64.c(154) : error C2065: 'p3' : undeclared identifier
vendll32_thunk_pcwin64.c(154) : error C2065: 'p3' : undeclared identifier
vendll32_thunk_pcwin64.c(154) : error C2065: 'p3' : undeclared identifier
vendll32_thunk_pcwin64.c(155) : error C2059: syntax error : ','
vendll32_thunk_pcwin64.c(155) : error C2146: syntax error : missing ')' before identifier 'HWND'
vendll32_thunk_pcwin64.c(155) : error C2146: syntax error : missing ')' before identifier 'HWND'
vendll32_thunk_pcwin64.c(155) : error C2065: 'HWND' : undeclared identifier
vendll32_thunk_pcwin64.c(155) : error C2059: syntax error : ')'
vendll32_thunk_pcwin64.c(155) : error C2146: syntax error : missing ';' before identifier 'fcn'
vendll32_thunk_pcwin64.c(155) : warning C4047: 'return' : 'int32' differs in levels of indirection
from 'int32 (__cdecl *)(int32,int32,int32,...)'
vendll32_thunk_pcwin64.c(155) : error C2059: syntax error : ')'
vendll32_thunk_pcwin64.c(155) : error C2065: 'p3' : undeclared identifier
vendll32_thunk_pcwin64.c(218) : error C2065: 'HWND' : undeclared identifier
vendll32_thunk_pcwin64.c(218) : error C2146: syntax error : missing ';' before identifier 'p0'
vendll32_thunk_pcwin64.c(218) : error C2065: 'p0' : undeclared identifier
vendll32_thunk_pcwin64.c(219) : error C2143: syntax error : missing ';' before 'type'
vendll32_thunk_pcwin64.c(220) : error C2143: syntax error : missing ';' before 'type'
vendll32_thunk_pcwin64.c(221) : error C2065: 'p0' : undeclared identifier
vendll32_thunk_pcwin64.c(221) : error C2146: syntax error : missing ')' before identifier 'HWND'
vendll32_thunk_pcwin64.c(221) : error C2065: 'H

Posted: Thu Aug 26, 2010 9:42 am
by bob@vensim.com
the messages suggest to me that matlab is only partially parsing the vendll.h file - you might want to delete the definition of HWND in that file and replace its occurrences with void* to see if that works.

Posted: Thu Aug 26, 2010 11:52 am
by ahmadi2010
I delete:( these rows and where I see (HWND pwindow ) I substitute it with void*.
#ifndef HWND
#define HWND void *
#endif
………………………………………
>> if not(libisloaded('vendll32'))
hfile = ['C:\Users\mrj\Desktop\New folder (3)\vendll.h'];
loadlibrary('vendll32', hfile);
end
libfunctionsview vendll32

??? Error using ==> loadlibrary at 474
There was an error loading the library "vendll32"
The specified module could not be found.



Caused by:
Error using ==> loaddefinedlibrary
The specified module could not be found.

even I uninstalled matlab 64(bit) & install 32bit.But it gives me the same error!!!!!!!:(

Posted: Thu Aug 26, 2010 5:01 pm
by ahmadi2010
do you think I should change my windows?

Posted: Thu Aug 26, 2010 9:55 pm
by tomfid
Above, you said:

Yes,I see the both of them in DLL subdirectory: VenDLL32.lib & Vendll.h

It sounds like your modified vendll.h is now OK. What you may still be missing is vendll32.dll (not .lib) in your system path.

Tom

Posted: Fri Aug 27, 2010 1:00 am
by ahmadi2010
vendll32.dll is in (windows\sysWOW64) path too. I don't khow why it doesn't work:(

Posted: Fri Aug 27, 2010 1:18 am
by tomfid
Maybe try giving it the full path then, e.g.

vendll = ['c:\windows\sysWOW64\vendll32.dll']; (or whatever the real path is)
hfile = ['C:\Users\mrj\Desktop\New folder (3)\vendll.h'];
loadlibrary( vendll , hfile);

?

Tom

Posted: Fri Aug 27, 2010 9:28 am
by ahmadi2010
Thank you Tom ,
I tried :
>> vendll=['C:\Windows\SysWOW64\venDLL32.dll']

vendll =

C:\Windows\SysWOW64\venDLL32.dll

>> hfile=['C:\Program Files (x86)\Vensim\dll\vendll.h']

hfile =

C:\Program Files (x86)\Vensim\dll\vendll.h

>> loadlibrary('vendll',hfile)
……………………………………………………………………………………………………….
Warning: Warnings messages were produced while parsing. Check the functions you
intend to use for correctness. Warning text can be viewed using:
[notfound,warnings]=loadlibrary(...)
> In loadlibrary at 394
Error loading library intermediate output follows.
The actual error is at the end of this output.
*********

Type 'HWND' was not found. Defaulting to type error.

Found on line 111 of input from line 110 of file C:\\Program Files (x86)\\Vensim\\dll\\vendll.h

Type 'HWND' was not found. Defaulting to type error.

Found on line 117 of input from line 116 of file C:\\Program Files (x86)\\Vensim\\dll\\vendll.h

Type 'HWND' was not found. Defaulting to type error.

Found on line 128 of input from line 127 of file C:\\Program Files (x86)\\Vensim\\dll\\vendll.h

Type 'HWND' was not found. Defaulting to type error.

Found on line 136 of input from line 135 of file C:\\Program Files (x86)\\Vensim\\dll\\vendll.h

Type 'HWND' was not found. Defaulting to type error.

Found on line 142 of input from line 141 of file C:\\Program Files (x86)\\Vensim\\dll\\vendll.h

Type 'HWND' was not found. Defaulting to type error.

Found on line 153 of input from line 152 of file C:\\Program Files (x86)\\Vensim\\dll\\vendll.h
*********
??? Error using ==> loadlibrary at 422
Building vendll_thunk_pcwin64 failed. Compiler output is:
vendll_thunk_pcwin64.c
.
.
.
.
The same error!

Posted: Fri Aug 27, 2010 9:52 am
by bob@vensim.com
it sounds like you are pointing to the original vendll.h file or perhaps you reinstalled Vensim and overwrote the one you had edited. You should probably edit the file and place it in a directory with other files you are using so that you can be sure you are pointing at your edited file at all times.

Posted: Fri Aug 27, 2010 11:50 am
by ahmadi2010
yes, I pointed to the original vendll.h file .
I installed vensim only once. And when I want to edit it I copy it to the other path.
now I mail a copy of original file for you.Please see it.

Posted: Fri Aug 27, 2010 1:49 pm
by bob@vensim.com
I know what the original file looks like - you need to point to the file you have edited to remove the definition of HWND and replace the use of HWND with void*.

Posted: Fri Aug 27, 2010 4:24 pm
by tomfid
I think what Bob means is that you're back to using the original hfile = C:\Program Files (x86)\Vensim\dll\vendll.h where you should be using your modified hfile = C:\Users\mrj\Desktop\New folder (3)\vendll.h'

Tom