- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am calling Fortran subroutines and functions in a DLL from a VB.Net application; some but not all of my simple functions work. I'm still at the "let's see how this works" stage. Eventually I will probably need a full range of types that can pass back and forth. I need help understanding the correct syntax. Using XD12.0.1.127 [IA-32] on the Fortran side and VB.Net (2.0) in Visual Studio 2010 (10.0.40129.1 SP1Rel). In the example, the Fortran DLL is called 'fvsf.dll'
These two example VB signatures work fine:
CallingConvention:=CallingConvention.Cdecl)> _
Public Sub SET_CB_VAL(ByRef n As Integer)
End Sub
CallingConvention:=CallingConvention.Cdecl)> _
Public Function GET_CB_VAL() As Integer
End Function
and with them I can write code that will call this sub and function; step into them and return values correctly:
SUBROUTINE SET_CB_VAL (N)
!DEC$ ATTRIBUTES DLLEXPORT :: SET_CB_VAL
INTEGER A
COMMON A
A = N
END SUBROUTINE
INTEGER FUNCTION GET_CB_VAL()
!DEC$ ATTRIBUTES DLLEXPORT :: GET_CB_VAL
INTEGER A
COMMON A
GET_CB_VAL = A
END FUNCTION
The 3rd case isn't working yet, and I would like advice!
Of course ;) it involves strings.
Here is the signature, which declares that I am passing an int, an input- and an output-string:
CharSet:=CharSet.Ansi, _
CallingConvention:=CallingConvention.Cdecl)> _
Public Sub FPASSSTRINGSUB(ByRef n As Integer, ByVal S1 As String, _
ByVal S2 As String)
End Sub
Here is the Fortran code it calls:
SUBROUTINE FPASSSTRINGSUB (INT_ARG, STR_IN, STR_OUT)
!DEC$ ATTRIBUTES DLLEXPORT :: FPASSSTRINGSUB
INTEGER, INTENT(IN) :: INT_ARG
CHARACTER*(8), INTENT(IN) :: STR_IN
CHARACTER*(8), INTENT(OUT) :: STR_OUT
STR_OUT = "HELLO "
END SUBROUTINE
Since it seems relevant, here is the VB sub that starts it rolling:
Private Sub ButtonCallFORTRAN_Click(sender As System.Object, e As System.EventArgs) Handles ButtonCallFORTRAN.Click
Dim i As Integer = 3
Dim s1 As String = "input " ' 8 chars
Dim s2 As String = "--------"
FPASSSTRINGSUB(i, s1, s2)
Dim s3 = s2
End Sub
One thing that I have discovered is that it "almost" works (doesn't crash...) if the lengths of the strings are known in advance on both sides. In the example, they are 8 characters long. But I find that upon return, the returned string (variable s2) is unchanged from its original input value, and it should be the 8-char string "HELLO "
Advice and working examples would be very welcome! If I get enough good stuff, I will assemble and post.
These two example VB signatures work fine:
Public Sub SET_CB_VAL(ByRef n As Integer)
End Sub
Public Function GET_CB_VAL() As Integer
End Function
and with them I can write code that will call this sub and function; step into them and return values correctly:
SUBROUTINE SET_CB_VAL (N)
!DEC$ ATTRIBUTES DLLEXPORT :: SET_CB_VAL
INTEGER A
COMMON A
A = N
END SUBROUTINE
INTEGER FUNCTION GET_CB_VAL()
!DEC$ ATTRIBUTES DLLEXPORT :: GET_CB_VAL
INTEGER A
COMMON A
GET_CB_VAL = A
END FUNCTION
The 3rd case isn't working yet, and I would like advice!
Of course ;) it involves strings.
Here is the signature, which declares that I am passing an int, an input- and an output-string:
CallingConvention:=CallingConvention.Cdecl)> _
Public Sub FPASSSTRINGSUB(ByRef n As Integer, ByVal S1 As String, _
ByVal S2 As String)
End Sub
Here is the Fortran code it calls:
SUBROUTINE FPASSSTRINGSUB (INT_ARG, STR_IN, STR_OUT)
!DEC$ ATTRIBUTES DLLEXPORT :: FPASSSTRINGSUB
INTEGER, INTENT(IN) :: INT_ARG
CHARACTER*(8), INTENT(IN) :: STR_IN
CHARACTER*(8), INTENT(OUT) :: STR_OUT
STR_OUT = "HELLO "
END SUBROUTINE
Since it seems relevant, here is the VB sub that starts it rolling:
Private Sub ButtonCallFORTRAN_Click(sender As System.Object, e As System.EventArgs) Handles ButtonCallFORTRAN.Click
Dim i As Integer = 3
Dim s1 As String = "input " ' 8 chars
Dim s2 As String = "--------"
FPASSSTRINGSUB(i, s1, s2)
Dim s3 = s2
End Sub
One thing that I have discovered is that it "almost" works (doesn't crash...) if the lengths of the strings are known in advance on both sides. In the example, they are 8 characters long. But I find that upon return, the returned string (variable s2) is unchanged from its original input value, and it should be the 8-char string "HELLO "
Advice and working examples would be very welcome! If I get enough good stuff, I will assemble and post.
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There are two VB.NET samples provided by Intel Visual Fortran in the "MixedLanguage" ZIP file. Have you studied those? Perhaps you can start with one and gradually adapt it toward what you want.
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There are two VB.NET samples provided by Intel Visual Fortran in the "MixedLanguage" ZIP file. Have you studied those? Perhaps you can start with one and gradually adapt it toward what you want.

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