- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There are two additional things you have to do, both of which can be addressed by adding the following line to the Fortran code:
!DEC$ ATTRIBUTES STDCALL,REFERENCE,ALIAS:"FortranDLL" :: FortranDLL
First, Intel Visual Fortran converts all routine names to uppercase and (on IA-32), prefixes the routine name with an underscore. So what is created is the symbol _FORTRANDLL which does not match what Visual Basic is looking for.
The second problem is that there are two different conventions for calling routines on 32-bit Windows, STDCALL and C. VB uses STD CALL and Intel Visual Fortran uses C. The line I suggested above selects STDCALL. I added REFERENCE also in case you change the code to pass arguments, as STDCALL implies pass by value.
You can get more information in the mixed-language programming chapter of the on-disk documentation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve.
That was a big help.Works like a charm.Thatgot me pointed in the right direction. I know the Fortran compiler will help significantly speed upintensive numerical analysis. It appears that developing DLL's with Fortran for use in VB is fairly straight forward and might be a viable option for me. I think I can figure out the rest from here. As they say, "I know just enough to be dangerous".
Thanks,
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve,
I have also been trying to do about the same with Fortran dll's called from VB in Visual Studio 2005.
What would be the Fortran Code to call a Fortran dll from a Fortran console application in Visual Studio 2005.
Thanks again,
Norm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tanks Steve,
I am trying to find and run a test program in the latest version of Intel's FORTRAN for Windows that I downloaded and installed on a test machine.
I am working within Visual Studio 5. All I want to do is show myself that I can write a FORTRAN dll and then call it from a FORTRAN console application.
In addition I want the projects to be seperate projects within the visual studiosolution.
I will also need to call fortran dlls from vb and call vb COM dll's created in managed code from fortran.
Thanks again,
Norm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Norm,
I replied in the other thread you started.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I solwe the same problem using fortran 9.1 and visual basic 2005. Your explaining is not understandable for me. I wrote this fortran and basic code in my visual studo 2005, but a got the same error mesage
Message="Unable to find an entry point named 'FortranDLL' in DLL 'C:VB .NET ProjectsFotran DLLFortran DLLDebugfortran dll.dll'."
Source="Fortran DLL"
hear is you repaired codes
Function FortranDLL
!DEC$ ATTRIBUTES STDCALL,REFERENCE,ALIAS:"FortranDLL" :: FortranDLL
FortranDLL = 3.141
Return
end
and VB code
Public Class Form1
Declare 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
Can you help me with this code?
I have fortran subroutines and functions and I need to make a visual environment in visual basic. I need to call a subroutin or function from basic with input arguments. An after calculation the fortran must return resuts to basic.
Your tablet code is it what I need. But this code is with error. could you write a corect code for fortran and basic.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are missing the DLLEXPORT attribute in your Fortran code. Use this:
!DEC$ ATTRIBUTES DLLEXPORT,STDCALL,REFERENCE,ALIAS:"FortranDLL" :: FortranDLL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I use this attribute
!DEC$ ATTRIBUTES DLLEXPORT,STDCALL,REFERENCE,ALIAS:"FortranDLL" :: FortranDLL
where is the problem?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When I build your test program with the correct attributes, I get a DLL which contains a "FortranDLL" routine. So the problem is somewhere else - perhaps your VB code is referring to a different DLL. I cannot tell what is wrong from the information you have given us.
One thing you can do is to download the free tool Dependency Walker and use it to look at your DLL. Make sure that it shows that FortranDLL is an exported function and that it does not show any errors.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks for your help STEVE,
this code is operating.
But now I'm solving problem usin more input and output arguments in functions and subroutines. And these atrubutes is un know for me :(
Function FortranDLL(x,y)
!DEC$ ATTRIBUTES DLLEXPORT,STDCALL,REFERENCE,ALIAS:"FortranDLL" :: FortranDLL
real x
real y
FortranDLL = 3.141*x*y
Return
end
and basic code>
Public Class Form1
Declare Auto Function FortranDLL Lib "D:_dokumentsVisual Studio 2005ProjectsWindowsApplication2Dll1Debugdll1.dll" Alias "FortranDLL" (ByVal x, ByVal y) As Single
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Test As Single
Dim b As Single = 4.2
Dim c As Single = 5
Test = FortranDLL(b, c)
MsgBox(Test)
End Sub
End Class
error mesage>Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve,
I've been following this thread, but no one seems
to be having the same trouble that I am. I'm
attempting a very simple procedure (shown here):
Here's the Fortran Function:
FUNCTION
FORTRANCALL(R1,NUM)!DEC$ATTRIBUTES DLLEXPORT:: FORTRANCALL!DEC$ATTRIBUTES ALIAS: 'FORTRANCALL'::FORTRANCALL!DEC$ATTRIBUTES STDCALL,REFERENCE:: FORTRANCALLNUM = R1 - 25
End FUNCTION
Here's the VB Module Code:
Module
Module1Declare Sub FORTRANCALL Lib "C:FORTRANFCALLFCALL......ReleaseFCALL.dll" (ByRef R1 As Integer, ByRef NUM As Integer)
End
Module
Here's the corresponding VB Sub:
PrivateSub Button1_Click(ByVal sender As System.Object,...
...ByVal e As System.EventArgs) Handles Button1.Click
Dim R1 As Integer
Dim NUM As IntegerR1 = 75
NUM = 20
TextBox2.Text = Str$(R1)
TextBox3.Text = Str$(NUM)
Call FORTRANCALL(R1, NUM)TextBox1.Text = Str(NUM)
TextBox4.Text = Str$(R1)
TextBox5.Text = Str$(NUM)
End SubThe Fortran function is compiled as a DLL and referenced
by the VB program.
The program runs to completion, only the value for
NUM is shown as -25, instead of 50 (R1 - 25 = 50).
I'd appreciate it if you could spot any code blunders
for me, as I can't seem to figure it out.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You definitely should make the Fortran code a subroutine as you're going to corrupt the floating point stack if you don't.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There are two additional things you have to do, both of which can be addressed by adding the following line to the Fortran code:
!DEC$ ATTRIBUTES STDCALL,REFERENCE,ALIAS:"FortranDLL" :: FortranDLL
First, Intel Visual Fortran converts all routine names to uppercase and (on IA-32), prefixes the routine name with an underscore. So what is created is the symbol _FORTRANDLL which does not match what Visual Basic is looking for.
The second problem is that there are two different conventions for calling routines on 32-bit Windows, STDCALL and C. VB uses STD CALL and Intel Visual Fortran uses C. The line I suggested above selects STDCALL. I added REFERENCE also in case you change the code to pass arguments, as STDCALL implies pass by value.
You can get more information in the mixed-language programming chapter of the on-disk documentation.
hi everybody:
ive got a questin related to this topyc. if the created fortran dll uses a numerical library (i have in the code: use numerical_libraries), when i call the created dll from visual basic, it cant find it in a pc where fortran is not installed. that may be because it cant find the numerical libraries. where and which files do i have to add to this pc so that it can work properly.
ive found numerical_libraries.mod and i add it but it doesnt work
any idea?
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As with any DLL library you link against, you need to have a copy of that DLL on the end-user system in a place Windows knows where to find it. If you have specified that you are building against the DLL version of IMSL, you will need the appropriate IMSL DLL (which is NOT named "numerical_libraries"). I suggest that you use Dependency Walker to determine what the name of the DLL is, as VB won't tell you. Please note that your application must use IMSL and not just provide IMSL functionality to some other program,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I use the sample program as list above:
Public Class Form1
Declare Auto Function TestDLL Lib "C:_JIANGCodeT1Console1Console1F.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
! Expose subroutine FortranDLL to users of this DLL
!DEC$ ATTRIBUTES DLLEXPORT,STDCALL,REFERENCE,ALIAS:"FortranDLL" :: FortranDLL
FortranDLL = 3.141
Return
end
In running, at first microsoft Visual Studio says the project is old, and new compile, then
"BadImaheFormatException" will not deal, and
"An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)"
what is the wrong?
regards,
- 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 FortranDLLI 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 Form1
Declare 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
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.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page