Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

Call Fortran DLL from .NET

John_N
Beginner
291 Views

Hello,

I just installed Parallel Studio XE for Windows. I have tried to reference multiple Fortran DLLs from .NET.  The call doesn't toss any errors but the Fortran DLL doesn't run.  This morning, I took a copy of a test project and had a colleague run the same project and it worked successfully for him but it does nothing for me.  With one sample program I get an unable to load dll error. I'm linking the dll as an existing item (add by link).  Most just act like they will work and do nothing.

I'm able to run the same code by running it as a fortran exe instead on my machine.  We are both running VS 2015 enterprise and have the latest versions of  Parallel Studio for Windows.  The only difference is I'm running Windows 10 and he is running Windows 7.  What could I be missing from a configuration standpoint to cause this issue.  Or is it a setup issue?  Or just Windows 10?

Thanks in advance for the help,

John

0 Kudos
7 Replies
IanH
Black Belt
291 Views

Are the Fortran and C runtime DLL's on your system path?

John_N
Beginner
291 Views

Yes, I verified them by comparing them to the working install.

John_N
Beginner
291 Views

Yes, I verified them by comparing them to the working install.

Greg_T_
Valued Contributor I
291 Views

Your approach with .NET calling Fortran DLLs may be similar to mine.  Are you using C# or maybe VB?  I have a C# front end exe that calls Fortran DLLs.  I've had success by copying the Fortran DLLs into the C# projects /bin/x64/Debug folder, then running the C# exe from Visual Studio or directly at the exe.  

In the C# class that calls the Fortran routines I have added syntax to identify the DLL name and subroutine name, and add the "InteropServices" class:

using System.Runtime.InteropServices;

And in the C# method I also define each Fortran routine as a static external method with the DllImport attribute to name the DLL to help the exe locate it.  I have found that I can omit the ".dll" extension for the project name in DllImport, such as myFortProj.dll identified as "myFortProj" with subroutine "myFortSub":

[DllImport("myFortProj")]
static extern void myFortSub(ref int value1, double[] array2);

And then later in the C# method the "myFortSub" is called.  Is this anything like what you are trying to do?

Regards,

Greg T.

John_N
Beginner
291 Views

I'm using the VB.NET equivalent, but yes, I have tried both the DllImport method and the Declare method.  Both dll call types work, just not on my machine.

John_N
Beginner
291 Views

I'm using the VB.NET equivalent, but yes, I have tried both the DllImport method and the Declare method.  Both dll call types work, just not on my machine.

FortranFan
Honored Contributor II
291 Views

John N wrote:

.. Both dll call types work, just not on my machine.

@John N,

Have you checked the dependencies of the DLL(s) in question using a tool such as Dependency Walker and confirmed the files are all present on your system?

Reply