- Contrassegnare come Nuovo
- Preferito
- Iscriversi
- Disattiva notifiche
- Iscriversi a feed RSS
- Evidenziare
- Stampare
- Segnalare contenuto inappropriato
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 copiato
- « Precedente
-
- 1
- 2
- Successivo »
- Contrassegnare come Nuovo
- Preferito
- Iscriversi
- Disattiva notifiche
- Iscriversi a feed RSS
- Evidenziare
- Stampare
- Segnalare contenuto inappropriato
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.
- Contrassegnare come Nuovo
- Preferito
- Iscriversi
- Disattiva notifiche
- Iscriversi a feed RSS
- Evidenziare
- Stampare
- Segnalare contenuto inappropriato
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
- Contrassegnare come Nuovo
- Preferito
- Iscriversi
- Disattiva notifiche
- Iscriversi a feed RSS
- Evidenziare
- Stampare
- Segnalare contenuto inappropriato
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" ..
- Contrassegnare come Nuovo
- Preferito
- Iscriversi
- Disattiva notifiche
- Iscriversi a feed RSS
- Evidenziare
- Stampare
- Segnalare contenuto inappropriato
- Contrassegnare come Nuovo
- Preferito
- Iscriversi
- Disattiva notifiche
- Iscriversi a feed RSS
- Evidenziare
- Stampare
- Segnalare contenuto inappropriato
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
- Contrassegnare come Nuovo
- Preferito
- Iscriversi
- Disattiva notifiche
- Iscriversi a feed RSS
- Evidenziare
- Stampare
- Segnalare contenuto inappropriato
- Contrassegnare come Nuovo
- Preferito
- Iscriversi
- Disattiva notifiche
- Iscriversi a feed RSS
- Evidenziare
- Stampare
- Segnalare contenuto inappropriato
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
- Contrassegnare come Nuovo
- Preferito
- Iscriversi
- Disattiva notifiche
- Iscriversi a feed RSS
- Evidenziare
- Stampare
- Segnalare contenuto inappropriato
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 ...
- Contrassegnare come Nuovo
- Preferito
- Iscriversi
- Disattiva notifiche
- Iscriversi a feed RSS
- Evidenziare
- Stampare
- Segnalare contenuto inappropriato
- Contrassegnare come Nuovo
- Preferito
- Iscriversi
- Disattiva notifiche
- Iscriversi a feed RSS
- Evidenziare
- Stampare
- Segnalare contenuto inappropriato
Hi Steve,
just wondering if you had a chance to have a look at the files and have any feedback?
cheers,
d
- Contrassegnare come Nuovo
- Preferito
- Iscriversi
- Disattiva notifiche
- Iscriversi a feed RSS
- Evidenziare
- Stampare
- Segnalare contenuto inappropriato
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
- Contrassegnare come Nuovo
- Preferito
- Iscriversi
- Disattiva notifiche
- Iscriversi a feed RSS
- Evidenziare
- Stampare
- Segnalare contenuto inappropriato
- Contrassegnare come Nuovo
- Preferito
- Iscriversi
- Disattiva notifiche
- Iscriversi a feed RSS
- Evidenziare
- Stampare
- Segnalare contenuto inappropriato
Thanks!
- Contrassegnare come Nuovo
- Preferito
- Iscriversi
- Disattiva notifiche
- Iscriversi a feed RSS
- Evidenziare
- Stampare
- Segnalare contenuto inappropriato
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
- Contrassegnare come Nuovo
- Preferito
- Iscriversi
- Disattiva notifiche
- Iscriversi a feed RSS
- Evidenziare
- Stampare
- Segnalare contenuto inappropriato
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?
- Contrassegnare come Nuovo
- Preferito
- Iscriversi
- Disattiva notifiche
- Iscriversi a feed RSS
- Evidenziare
- Stampare
- Segnalare contenuto inappropriato
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)
- Contrassegnare come Nuovo
- Preferito
- Iscriversi
- Disattiva notifiche
- Iscriversi a feed RSS
- Evidenziare
- Stampare
- Segnalare contenuto inappropriato
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?

- Iscriversi a feed RSS
- Contrassegnare la discussione come nuova
- Contrassegnare la discussione come letta
- Sposta questo Discussione per l'utente corrente
- Preferito
- Iscriversi
- Pagina in versione di stampa
- « Precedente
-
- 1
- 2
- Successivo »