- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, that worked!
Rob
Rob

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