- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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,
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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,
(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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page