Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28441 Discussions

FORTRAN DLL won't load in VS2019

GedLee
Beginner
3,241 Views

I have used IVF and VS to make VB code that calls a FORTRAN DLL, for decades, all the way up to Win8.1.  I just got a new computer (with Win10) and installed IVF and VS2019 and now none of my solutions work anymore.  The VS2019 install is new as I used VS 2017 previously.  I assume that IVF hasn't changed much since then.  I load the solutions (VB and FORTRAN) clean, rebuild, and run.

In each and every case I get error "An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)"

I have changed nothing (to my knowledge) and I have tried so many things that I can't enumerate them all.

A web app (no FORTRAN) done on my old computer works fine, loads and runs and publishes just fine.  So it is clearly something to do with the FORTRAN DLLs.

Does anyone have some suggestions on how to resolve this?

0 Kudos
1 Solution
Steve_Lionel
Honored Contributor III
2,913 Views

Going back to what I wrote earlier, you probably have a 32-bit VB calling a 64-bit DLL (or vice-versa.) I suggest, in the VB project, setting the CPU type to either 32 or 64 bit, matching that of the DLL.

The typical way of dealing with the path issue is to copy the DLL into the same folder as the VB executable.

View solution in original post

35 Replies
GedLee
Beginner
1,157 Views

Thanks Steve

Attached is the project file.  Some things in the project are hard coded to certain directories so you may have to change locations to get it to work.

I'd appreciate it if anyone knows why just copying the project files and creating and loading the fiels into a new project does not link the "Main" form to its designer - i.e. form has no controls and lost of errors for missing controls.

0 Kudos
Steve_Lionel
Honored Contributor III
1,154 Views

First, the DLL project DOES specify /dll and does create one. Why do you think it didn't?

Second, I notice that the filespec for the DLL in the VB code has no path, just the DLL name. It probably looks for it in the VB project folder then, and I didn't spot a post-build command to copy it there. I replaced this with the path to my built DLL. But when I run the program it asks for an input file that wasn't provided, so I can't test more

You have to copy the entire VB project folder, not create a new project and copy in some source files. There's some relationship info in other parts of the project.

0 Kudos
GedLee
Beginner
1,149 Views

Thanks Steve,

Yes, I (dumbly!) always copied the necessary files to the My Project folder by hand.  So I can see why it didn't work for you.

But the issue, to me, is that this is the Link command line that I see in the DLL project

"/OUT:"x64\Debug\MeasCalcs.dll" /NOLOGO /MANIFEST /MANIFESTFILE:"x64\Debug\MeasCalcs.dll.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"D:\Documents\Visual Studio 2019\Projects\Measure\MeasCalcs\x64\Debug\MeasCalcs.pdb" /SUBSYSTEM:WINDOWS /IMPLIB:"D:\Documents\Visual Studio 2019\Projects\Measure\MeasCalcs\x64\Debug\MeasCalcs.lib"

and I don't see a /DLL.  Do you have it in your Link command line?

0 Kudos
GedLee
Beginner
1,147 Views

Also attached is a file that you need to find and open that contains the data.

0 Kudos
Steve_Lionel
Honored Contributor III
1,139 Views

I see - that is odd. The Win32 configuration has /dll in the command line for the linker, the x64 configuration does not. But I also see that the x64 configuration is set to use the beta ifx compiler, not the "classic" ifort. I did some experiments to see if changing this setting caused the /dll option to disappear, but I couldn't make it do that. I do see that the option is missing from your .vfproj file.

I tried rebuilding as x64 and running the program, but there are some paths to folders on your local system in the VB project that I can't figure out where they are set. I think starting with a new Fortran project is best.

0 Kudos
Steve_Lionel
Honored Contributor III
1,138 Views

Try using the MeasCalcs.vfproj in the attached zip.

0 Kudos
MWind2
New Contributor III
1,120 Views

I had to change  real(8) to complex(8) dym,dyt in rk4.F90 to use CalcDerivs.F90 as is. Something wrong with original project file but not apparent to me in gui, but default project with files worked to compile.

Paths in vb code hard code location of dll. Not checked if it works properly, but compiles.

0 Kudos
GedLee
Beginner
1,109 Views

HI Steve

Happy New Year.

I worked out the VB problem of no controls.  You have to "add" the form but NOT the designer.  If you "add" the designer with the form then it fails.  Just "add" the form and not the designer, but the designer must be in the same directory.

So I have the VB project all set as a new solution.  I next needed to add the FORTRAN project as a DLL.  It took me quite awhile to find the FORTRAN DLL template as it does not come up unless you search for "FORTRAN DLL" and then it is well down the list. 

Others may want to know these two "gotchas."  In the new VS2019.

The link line now states "/DLL" so that should correct most of my issues.  I haven't looked at this code in a while and there is a call parameter mismatch that I have to resolve - I am not sure what happened.  I do think that all my issues have been resolved and once I find my coding error I should be OK.

 I'll update when all is well, but will be gone for a week, so it may be awhile.

Thanks again. 

0 Kudos
GedLee
Beginner
1,098 Views

I got the VB project working and the FORTRAN code now creates a DLL, all this starting from scratch.  And I have now come back to the original problem, error: "System.BadImageFormatException: 'An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)'" I get this error no matter what configuration I set.

One other question that I have is about declaring the FORTRAN subs in VB with the Declare statement.  This statement only allows for string constants, so it seems to me that the DLL locations have to be hard coded.  Is there a way around this?

0 Kudos
Steve_Lionel
Honored Contributor III
2,914 Views

Going back to what I wrote earlier, you probably have a 32-bit VB calling a 64-bit DLL (or vice-versa.) I suggest, in the VB project, setting the CPU type to either 32 or 64 bit, matching that of the DLL.

The typical way of dealing with the path issue is to copy the DLL into the same folder as the VB executable.

GedLee
Beginner
1,088 Views

As I said, I tried all configurations.  The one that I posted was for an all X64 build, the exe and dll which are both in the same project.

I tried the copy command in the "post build" and it failed, but yet the exact same "copy" command line worked fine in PowerShell. So I don't quite understand the problem.

0 Kudos
GedLee
Beginner
1,078 Views

My mistake, I wasn't putting the DLL where it should be and it was using an older DLL.  Corrected that and the DLL loads.

 

Thanks all for your help, especially Steve.  His commitment to help FORTRAN coders (a rare breed) is to be commended.

 

0 Kudos
MWind2
New Contributor III
1,259 Views

What type of VB project template would you say would be similar to yours so I can run a simple test.

0 Kudos
Steve_Lionel
Honored Contributor III
1,225 Views

The test solution was set for x64, and it worked for me.

0 Kudos
JohnNichols
Valued Contributor III
1,214 Views

Steve: if you work 24/7 on this site why did you retire?

0 Kudos
Reply