- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have downloaded the trial version of Intel's Visual Fortran Compiler and I am investigating the possibility of creating a DLL with Fortran and using the DLL in Visual Basic. I am using Visual Studio 2005.
I began by opening a FortranDynamic Link Library typeprojecttemplate in Visual Studio. I have modified the Subroutine toproduce atrivial Fuction that returns a value.The Fortran code is:
Function FortranDLL
! Expose subroutine FortranDLL to users of this DLL
!DEC$ ATTRIBUTES DLLEXPORT::FortranDLL
FortranDLL = 3.141
Return
end
I then added a standard Windows Application to the project. I added the following Visual Basic Declare statement to declare my test DLL and call the DLL from the Form's Click Event.
Public
Class Form1Declare Auto Function TestDLL Lib "C:VB .NET ProjectsFotran DLLFortran DLLDebugfortran dll.dll" Alias "FortranDLL" () As Single
Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
Dim Test As Object
Test = TestDLL
End Sub
End Class
When I run the VB code above I receive the following error message stating that the program is unable to find the EntryPoint for the DLL.
System.EntryPointNotFoundException was unhandled
Message="Unable to find an entry point named 'FortranDLL' in DLL 'C:VB .NET ProjectsFotran DLLFortran DLLDebugfortran dll.dll'."
Source="Fortran DLL"
Can you point me to information that will help me create a simple Function in the form of a DLLwith Intel's Fortran Compiler and call that Function from Visual Basic using Visual Studio 2005? If it is relatively easy to do I will purchase the Compilier for use in my programs.
Thank You.
Jim Denny
Link Copied
- « Previous
-
- 1
- 2
- Next »
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Many thanks, Steve Lionel. I am a Java programmer faced with the need to call FORTRAN dlls from VB .NET in Visual Studio 2008. I spent many hoursobtaining a lot of bad advice before I found this excellent, concise advice.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Function DLL2(x)
!DEC$ ATTRIBUTES DLLEXPORT,STDCALL,REFERENCE,ALIAS:"DLL2" :: DLL2
real x
DLL2 = x
Return
end
and the visual basic code is
Public Class Form1
Declare Auto Function DLL2 Lib "D:\Abhinav\Visual Basic Codes\Dll2\Dll2\Debug\DLL2.dll" Alias "DLL2" (ByRef x) As Single
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Test As Single
Dim a As Single = 4.2
Test = DLL2(a)
MsgBox(Test)
End Sub
End Class
The program runs butprints 5.605194E-45. I cant figure out is that i am doing wrong. Kindly advise
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Real*4 Function DLL2(x)
!DEC$ ATTRIBUTES DLLEXPORT,REFERENCE,ALIAS:"DLL2" :: DLL2
real*4 x
DLL2 = x
Return
end
Then I inserted some Visual Basic code into an Excel worksheet and tried it out:
Public Declare Function DLL2 Lib "P:\whateverpath\dll2_test\debug\dll2_test.dll" (A1 As Single) As Single
Public Function GetDLL2(a As Single) As Single
GetDLL2 = DLL2(a)
MsgBox (Str(a))
End Function
and I invoked GetDLL2 in a formula in a cell (e.g. '=GetDLL2(B39)' taking a value in cell B39) and it worked OK. The message box showed the value and the value turned up in the Excel cell containing the formula.
Note that I use MsgBox(Str(a)) in order to get the correct value displayed.
It even works with
!DEC$ ATTRIBUTES DLLEXPORT,STDCALL,REFERENCE,ALIAS:"DLL2" :: DLL2
as the export directive.
- 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
- « Previous
-
- 1
- 2
- Next »