Attachment uses different colored fonts to make it more readable ....
Using Vensim External Functions via the freely downloadable Visual C++ Toolkit 2003.
Got the following from Vensim e-mail 08/24/04 concerning Vensim Version 5.4a update:
Microsoft Visual C++ Toolkit 2003
---------------------------------
Microsoft has chosen to make its C++ compiler engine available for free.
If you are using Vensim DSS and want to speed up your simulations by
compiling this is a good way to do it. You can go to
http://msdn.microsoft.com/visualc and look for the Visual C++ Toolkit
for more details. Microsoft has not indicated how long they will make
this available for free, it may be only for a limited time. The
supporting files that ship with version 5.4a make it easy to use this
compiler. Creating external functions with this compiler might work,
but would take some work.
The last sentence: “Creating external functions with this compiler might work,
but would take some work.” is what the focus here.
( first off I need to acknowledge that I know nil about compiling, linking and
associated script/batch files that make it all happen ( .mak, .bat , .dsp & .dsw files )
as well as the unique syntax used for passing arguments and dealing with ‘environmental’ or global variables ; it may well be your advise will be for me to learn this stuff )
By reviewing the Vensim DSS Supplement Chapter 8 on using External Functions,
and examining the files in the C:\Program Files\Vensim\comp directory as well as those
in the C:\Program Files\Microsoft Visual C++ Toolkit 2003 directory I’ve made the following observations:
Given that the Microsoft Visual C++ Toolkit 2003 does not contain the MSFT Visual C++ IDE that creates and uses the .dsp and .dsw files it makes no sense to try to use them. Success seems to lie in focusing on using the C:\Program Files\Vensim\comp directory MSCVXT32 batch file recommended for use with MSFT’s C compiler. The issue then becomes how should the MSCVXT32 batch file be modified to do its compile and link operations with the C:\Program Files\Microsoft Visual C++ Toolkit 2003 directory compiler and linker made available in that directory’s bin subdirectory ?
Also there is the issue of setting the required ‘environment’ or ‘global’ variables as
is done in the C:\Program Files\Microsoft Visual C++ Toolkit 2003 directory’s
vcvars32 batch file;
@echo off
Set PATH=C:\Program Files\Microsoft Visual C++ Toolkit 2003\bin;%PATH%
Set INCLUDE=C:\Program Files\Microsoft Visual C++ Toolkit 2003\include;%INCLUDE%
Set LIB=C:\Program Files\Microsoft Visual C++ Toolkit 2003\lib;%LIB%
echo Setting environment for using Microsoft Visual C++ 2003 Toolkit.
echo (If you have another version of Visual Studio or Visual C++ installed and wish
echo to use its tools from the command line, run vcvars32.bat for that version.)
echo.
echo Thank you for choosing the Visual C++ Toolkit 2003! Get started quickly by
echo building the code samples included in the "Samples" directory. Each sample
echo includes a short whitepaper discussing the Visual C++ features, and a batch
echo file for building the code.
echo.
echo Type "cl /?" for brief documentation on compiler options.
echo.
echo Visit http://msdn.microsoft.com/visualc/using ... fault.aspx for
echo complete compiler documentation.
This processing step is also recommended in the C:\Program Files\Vensim\comp directory MDL batch file;
@ECHO OFF
REM
REM The following should work with Microsoft C/C++ Toolkit 2003
REM
REM if "%OS%" == "" set PATH="set PATH=c:\Program Files\Microsoft Visual C++ Toolkit 2003\bin"
REM if "%OS%" == "Windows_NT" set PATH=c:\Program Files\Microsoft Visual C++ Toolkit 2003\bin"
REM set LIB=c:\Program Files\Microsoft Visual C++ Toolkit 2003\lib
REM set INCLUDE=c:\Program Files\Microsoft Visual C++ Toolkit 2003\include
REM
Such that the creation of the venext.dll should follow from something like;
Batch code segment from C:\Program Files\Microsoft Visual C++ Toolkit 2003 directory’s vcvars32 batch file;
Set PATH=C:\Program Files\Microsoft Visual C++ Toolkit 2003\bin;%PATH%
Set INCLUDE=C:\Program Files\Microsoft Visual C++ Toolkit 2003\include;%INCLUDE%
Set LIB=C:\Program Files\Microsoft Visual C++ Toolkit 2003\lib;%LIB%
Followed by the batch code segment from C:\Program Files\Vensim\comp directory batch file MSCVXT32: ( its not clear to me from the code here what the dependencies are
between the PATH, INCLUDE and LIB ‘set’ variables above and the batch code below )
CL /c /DWIN32 %1 venext.c
if errorlevel 1 goto :error1
LINK /DLL /OUT:venext.dll /def:venext.def vensim.lib venext.obj user32.lib gdi32.lib comdlg32.lib shell32.lib
if errorlevel 1 goto :error
del venext.lib
del venext.exp
goto :exit
:error
echo Errors encountered in creating venext.dll
pause
:exit
goto :exit2
:error1
echo Unable to compile venext.c
pause
:exit2
The challenge here is putting together these batch code segments in a way that will work with the C:\Program Files\Microsoft Visual C++ Toolkit 2003 cl ( compiler ) and link ( linker ) commands in the bin directory.
The Vensim documentation in Ch 8 of the DSS Supplement and the Vensim/comp directory code makes adding your own external functions straight forward except for
the changes required to use C++ function calls instead of C-function calls; although
I’d imagine these changes only involve including the required C++ header files and/or
libraries. I understand that C++ is a superset of C so C functions and the venext.c
and venext.def files provided show how C-based external functions can be added easily.
When I copied the existing C:\Program Files\Vensim\comp\mscvxt32 MS-DOS Batch file and venext.c to test on my own; I couldn’t save these files as their exact type using notepad; is this something else that requires the Visual Studio IDE to do correctly/consistently ?
Comments, guidance appreciated.
Mike Reilly
Using Vensim External Functions via the freely downloadable
Using Vensim External Functions via the freely downloadable
- Attachments
-
- vensim.external.func.ForumQuestion.doc
- (37.5 KiB) Downloaded 600 times
-
- Super Administrator
- Posts: 4827
- Joined: Wed Mar 05, 2003 3:10 am
>> When I copied the existing C:\Program Files\Vensim\comp\mscvxt32 MS-DOS Batch file and venext.c to test
>> on my own; I couldn’t save these files as their exact type using notepad; is this something else that requires the Visual
>> Studio IDE to do correctly/consistently ?
I suspect this is a configuration problem on your machine. It sounds like notepad is adding the .txt to the end of the filename. I think (but am not sure) that if you turn on the display of file extensions, you should be ok.
Tony.
>> on my own; I couldn’t save these files as their exact type using notepad; is this something else that requires the Visual
>> Studio IDE to do correctly/consistently ?
I suspect this is a configuration problem on your machine. It sounds like notepad is adding the .txt to the end of the filename. I think (but am not sure) that if you turn on the display of file extensions, you should be ok.
Tony.