- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'veended up with a set of formulas originally coded in Visual Basic, that I now need to call from Fortran.
Anyone tried that?
Thanks in advance for any help...
Best regards,
8-) Egil
Egil Giertsen
Senior Research Scientist
Phone : +47 7359 2081
Telefax: +47 7359 2660
Mobile : +47 9305 8672
_____________________________
MARINTEK SINTEF GROUP
Department of Structural Engineering
Otto Nielsens vei 10
P O Box 4125, Valentinlyst
N-7450 Trondheim
NORWAY
_____________________________
http://www.marintek.sintef.no
Link Copied
- « Previous
-
- 1
- 2
- Next »
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We dynamically load DLLs (havent tried VB) and call into them this way and it works fine.
Just make sure you declare your Fortran prototype to be compatible but judging on the mangled name I doubt you have complex arguments. Also, you may have to try a few different calling conventions to get the right one.
Alternatively (and maybe cleaner) create a simple little COM wrapper around the DLL (you can quickly create a COM wrapper using the activescript wizard etc.). Then create an instance of the COM object and call into that. If you have trouble doing that from Fortran code, you can link in a little C code to do and easily call the C code from Fortran.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sadly, none of this will work with a VB DLL which is a COM thingy or ActiveX DLL as opposed to a classic DLL with exports that can be gotten at via GetProcAddress. So you have to use COM protocol with the assistance of the Module Wizard or figure out how to change an ActiveX DLL into a classic DLL as discussed earlier in this thread.
Gerry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
steve, if you decide to do this example, I now have working code that calls (hardcoded) VB2008 scripts from both C++ and Fortran (both using the COM interface, which for C++ comes naturally but for Fortran has to be extracted using the Wizard).
It took me a while, but its pretty neat! I am quite sure the C# version could be worked out realtively easily by analogy.
I will try to document it better and post it (maybe as some kind of short knowledge-base article? this forum has been very helpful for me and so would be nice to contribute something back if its deemed useful).
The whole experience with writing the VB/C++/Fortran connections was rather instructive! I do wish there was some way of learning this more or less systematically rather than by trial and error. Are these matters subjects of any courses, or books? or is the subject too fast-developing for the written word? I certainly found the VB conventions changed sugnificantly over the last few years so some of the "help files" were more like "confusion files" ..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve,
I sent you a 'message' a couple of days ago - just wondering if it got thru as I had some difficulties making it work... I also tried to attach a very rough draft with a working example. Let me know if its of worth continuing..
thanks,
d
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve,
see attached. Its rather rough but the example works - I thought I'd let you see it before trying to do much more.
cheers,dmitri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve,
see attached. Its rather rough but the example works - I thought I'd let you see it before trying to do much more.
cheers,dmitri
cant seem the get the attachment working here either ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve,
just wondering if you had a chance to have a look at the files and have any feedback?
cheers,
d
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
While Steve will give you an expert's feedback, this has been quite helpful to me. I encapsulated it in a module and can call any COM object I created using VB.
Currently I am struggling with passing arrays "from" Fortran "to" VB and on keeping the VB form "alive" even after the Fortran program quits. I need to figure out my way through the safe-array business for the former while the latter has stumped me quite a bit.
Abhi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you want to call a routine in a DLL without an export library, you need to use LoadLibrary and GetProcAddress as demonstrated in the sample DLL\DynamicLoad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
DUMPBIN on the .LIB shows symbols with leading underscores.
Correcting the ALIAS to show this allows me to compile and link.
Registered the DLL and added it to C:\WIndows\system32\ so that it could be found.
Program runs but crashes with access error on the call to PrintTiltlesName
Can you show your Visual Basic function prototype declarations?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, I guess I should have seen that but couldn't.
I think the crash is related to passing a string into the DLL. Do I need to do this as a safearray? Or a BSTR pointer?
Private Declare Function ApplyNNet Lib "NNetApply.dll" (MyNNetType As String, MyAddress As String, MyInput() As Double) As Variant
Private Declare Sub PrintTitlesName Lib "NNetApply.dll" (MyAddress As String)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Going the other way is a real pain. Strings are horrible compard to integers, reals etc.
You want to 'send' a string from Fortran to VB. This means that the memory location (buffer) for the string is allocated on the Fortran side so you need to send the address of the start of that buffer to VB. If VB needs/assumes/stores strings a BITSTRINGS, then you would be wise to cast your character string on the Fortran side as a BITSTRING. There are functions available that do this which will give you a pointer (address) to the BITSTRING. Then all you need to do is pass this pointer to VB.
I find that dealing with adresses makes it easier to see what's happening in memory.
I would try making MyAdress ByRef for a start (and make the argument the pointer with a VALUE attribute on the Fortran side), then post a new DLL. Can you supply a Debug version for test purposes?
P.S. What does PrintTitlesName do?
Can you arrange for the function to display a message box showing what turns up as the argument?

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- « Previous
-
- 1
- 2
- Next »