Calling a Fortran routine from VB.NET

In 2009, I wrote a little application that involved calling a Fortran DLL (contents unavailable) into a VB.NET application. It worked. However, I now need to revisit the code and have found the the VB.NET application won't run from the original source code if it is compiled in Visual Studio Community 2017.

The arguments of the Fortran dll are a combination of arrays of integers, reals and chars:

SV is a string (array of Fortran characters?)
IV is an array of Fortran integers
RV is an array of Fortran reals

Within the VB code, I have used:

Dim IV(1279) As Integer
Dim RV(15999) As Single
Dim IERR As Integer
Dim SV As New String(" ", 5120)
Dim FileDir As New String(" ", 64)

Call FORT_SUB(SV, 5120, IV(1), RV(1), IERR)

The resulting EXE crashes at the Call line. I can only think the syntax requirements must have changed slightly and that I now need to make the Fortran call slightly differently...

2 Answers

  1. Lance- Reply


    My target platform was wrong. The old DLL was x86 architecture but my VB2017 compiler defaulted to x64. I changed that and my old code now compiles and runs. Happy days.

  2. Larry- Reply


    The .Net version in your new VS2017 is probably newer than your original code. I would change the .Net version to what CLR version you were using then; probably .Net 3.5. Then you need to import your DLL. Ensure that when you add your reference to your DLL you can inspect in your object browser. Now I am also assuming that your DLL is not managed code meaning code not written in .Net. I would check these things first and then move forward from there.

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>