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

Visual Basic .NET Fortran DLL Basics

blackre3
Beginner
1,741 Views
I am trying to call a FORTRAN DLL from Visual Basic.

I am using a Microsoft Visual Studio 2008 with multi-language solution.

Visual Basic is the calling language

I added a project named dll1 to the solution (Intel Visual Fortran -> Library -> Dynamic Linked Library)

This is what the FORTRAN (source1.for) looks like:

subroutine DLL1()

!DEC$ ATTRIBUTES DLLEXPORT::DLL1
Print *, 'Hello World'
Return
End


This is what the Visual Basic .NET code looks like:

Option Strict On
Option Explicit On
Imports System.Runtime.InteropServices


Public Class Form1
Public Declare Sub DLL1 Lib "dll1.dll" ()

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dll1()
End Sub
End Class

When I run it, VB does not seem to be able to load the DLL as it says "Unable to load DLL 'dll1.dll': The specified module could not be found (Exception from HRESULT:0x8007007E)"

I would have thought that if I am building this as a mixed language solution that I would not have to explicitly tell VB where the DLL is located (ie, with the exact path). Eventually this will be distributed to other and I will not know the exact path.

Any help on this would be appreciated.
Thanks
Rob
0 Kudos
1 Solution
DavidWhite
Valued Contributor II
1,741 Views
The DLL must be accessible on the PATH otherwise it cannot be found.

I suggest that you change the DLLEXPORT as follows:
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, ALIAS:'DLL1' :: DLL1

Note that VB is case-sensitive, but Fortran is not, hence the use of the Alias item to make sure the exported name has the correct case.

The VB declaration then needs tobe
Declare SubDLL1 Lib "dll1.dll"

I don't think the case of the dll filename is an issue - I have always used the same case as the Fortran project, so havenot noticed.

Regards,

David

View solution in original post

0 Kudos
2 Replies
DavidWhite
Valued Contributor II
1,742 Views
The DLL must be accessible on the PATH otherwise it cannot be found.

I suggest that you change the DLLEXPORT as follows:
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, ALIAS:'DLL1' :: DLL1

Note that VB is case-sensitive, but Fortran is not, hence the use of the Alias item to make sure the exported name has the correct case.

The VB declaration then needs tobe
Declare SubDLL1 Lib "dll1.dll"

I don't think the case of the dll filename is an issue - I have always used the same case as the Fortran project, so havenot noticed.

Regards,

David
0 Kudos
blackre3
Beginner
1,741 Views
Thanks, that worked!
Rob
0 Kudos
Reply