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

Problem Referencing Fortran DLL in VB .NET Project

bevo3
Beginner
1,129 Views
Hello,

I am having trouble referencing a Fortran DLL file that I am building with Intel Visual Fortran v11.1. When I build the DLL, I use the following compiler directives with my exporting subroutines:

!DEC$ ATTRIBUTES DLLEXPORT, STDCALL :: Analysis_Circ
!DEC$ ATTRIBUTES DECORATE, ALIAS:'Analysis_Circ' :: Analysis_Circ

I build the DLL using the following command line statement:

ifort /dll filename.f90

When I try to reference the DLL file in my .NET project (VS2008 VB application) I get the following error message:

"A reference to ...could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component."

I am positive that the file is accessible, thus it appears as though I am building an invalid assembly. The only thing I can think of is that I am missing a compiler directive that specifies a Win32 DLL as opposed to a 64-bit DLL. If you have an idea why I am building an invalid DLL file, please share your thoughts.

Best Regards,
0 Kudos
5 Replies
bevo3
Beginner
1,129 Views

Hello,

I've been browsing around the internet this evening trying to figure out how to solve my problem, and it looks like I may just be building a DLL that isn't compatible with the .NET framework. Are there specific compiler directives that I should be using to ensure the built DLL will be compatible with VB.NET?

Thank you,

0 Kudos
DavidWhite
Valued Contributor II
1,129 Views
Suggest you get dependency walker from dependencywalker.com and use this to check the entry points on your DLL to confirm that they have been exported properly.

Especially check that the case of the names matches the declaration in VB. I call DLLs from VBA (Excel) regularly. Normally, I export the Alias name all in upper case for simplicity.

Try an example with no arguments to ensure that you can actually access the DLL.

Regards,

David
0 Kudos
anthonyrichards
New Contributor III
1,129 Views
Please post your VB .NET declarations of the DLL functions you wish to import.
Also, please show the error messages IN FULL.
Also, use DUMPBIN on your DLL to list the exported symbols and post the list.
e.g. DUMPBIN /exports your.dll

Here is an example of what I got to work:

FORTRAN:

subroutine PassStringsToFortran(nelements, ptr_Array)
! Expose subroutine PASSSTRINGSTOFORTRAN (n.b. exported symbol defaults to Uppercase in Fortran)
! to users of this DLL and specify that nelements is passed by reference but ptr_Array is passed by value
!
!DEC$ ATTRIBUTES DLLEXPORT::PassStringsToFortran
!DEC$ ATTRIBUTES VALUE::ptr_Array
!DEC$ ATTRIBUTES REFERENCE::nelements
! ptr_array is a pointer to a SafeArray of bit-strings
! nelements is the number of strings in the array
integer ptr_array, nelements

(excerpt ends)
-------------------------------------------
VISUAL BASIC 2008 EXPRESS:

Public Class Form1
' Note UPPERCASE symbols are exported as default in the Fortran DLL
Private Declare Sub PASSSTRINGSTOFORTRAN Lib "c:\f90\test_VBstrings\debug\test_VBstrings.dll" _
(ByRef nelements As Long, ByVal str() As String)

(excerpt ends)
-------------------------------------------
DUMPBIN OUTPUT EXTRACT (Note the UPPERCASE symbol names)

C:\F90\test_vbstrings\Debug>dumpbin /exports test_vbstrings.dll
Microsoft COFF Binary File Dumper Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

Dump of file test_vbstrings.dll

File Type: DLL

Section contains the following exports for test_vbstrings.dll

0 characteristics
4E01F22E time date stamp Wed Jun 22 14:46:22 2011
0.00 version
1 ordinal base
10 number of functions
10 number of names

ordinal hint RVA name

1 0 000016A1 PASSINTEGERSTOFORTRAN
3 1 00001000 PASSSTRINGSTOFORTRAN
(excerpt ends)
-------------------------------------------
Note uppercase symbol names
0 Kudos
bevo3
Beginner
1,129 Views
Thank you both for your replies. Unfortunately, I am still not able to figure this problem out. I decided to break this problem down as much as possible, thus I wrote a very simple Fortran subroutine as follows:

SUBROUTINE ERIC(x)

!DEC$ ATTRIBUTES DLLEXPORT::ERIC

!DEC$ ATTRIBUTES STDCALL::ERIC

!DEC$ ATTRIBUTES REFERENCE::x

IMPLICIT NONE

REAL::x

x=x+6

END SUBROUTINE ERIC

I build my DLL file using Intel Visual Fortran v11.1 and use the following command:

ifort /dll Eric.f90

I then open up a new VB.NET project...blank with no code. I right click in the solution explorer and select "add reference." I browse on my desktop and select Eric.dll. When I click ok, I get the following error message:

"A reference to 'C:\Users\els977\Desktop\Eric.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component."

This is the same error message that I get when I try building my more complex DLL and adding it to my real VB.NET project as a reference. I should note that I've built this DLL using Silverfrost's trial version compiler, and I've been able to successfully add that DLL as a reference to my VB.NET project and call it as needed. I don't like the ugly splash screen that pops up saying that I'm using a trial version of Silverfrost and I have access to Intel Visual Fortran...this is why I am trying to use Intel Visual Fortran. This is very frustrating considering the fact that I have absolutely no problems building a useable DLL file with Silverfrost. I don't understand what I'm doing wrong with the Intel compiler.

0 Kudos
Steven_L_Intel1
Employee
1,129 Views
Don't add the reference. You don't need to do that for Fortran DLLs. You do need the proper declaration in the VB "module". There are two VB samples provided with Intel Visual Fortran - I suggest you examine them.
0 Kudos
Reply