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

VB.Net and Fortran DLL syntax

Robinson__Donald
Beginner
726 Views
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.

0 Kudos
1 Solution
Steven_L_Intel1
Employee
726 Views
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.

View solution in original post

0 Kudos
1 Reply
Steven_L_Intel1
Employee
727 Views
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.
0 Kudos
Reply