I am trying to link a Fortran dynamic-link-library (DLL) with a VB.NET application. The subroutine contained in the DLL is supposed to modify a value c
provided in the VB side, but it is not doing it: it keeps c
as it is.
Here is the Fortran code:
SUBROUTINE prueba_int(m,n,p)
!DEC$ ATTRIBUTES DLLEXPORT, DECORATE, ALIAS : "prueba_int" :: prueba_int
!DEC$ ATTRIBUTES REFERENCE :: m,n
IMPLICIT NONE
INTEGER, INTENT(IN) :: m,n
INTEGER,INTENT(OUT) :: p
p=m*n
END SUBROUTINE
And here is the VB.NET section:
Public Class Form1
Public Declare Sub prueba_int Lib "Dll2.dll path" (ByRef m As Integer, ByRef n As Integer, ByRef p As Integer)
Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
ofd.Filter = "(*txt)|*.txt"
If (ofd.ShowDialog() = DialogResult.OK) Then
txtArray.Text = ofd.FileName
End If
End Sub
Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
Dim a, b, c As Integer
a = CInt(txt1.Text)
b = CInt(txt2.Text)
c = 1
Call prueba_int(a, b, c)
MsgBox(c) 'Only to check c's value
End Sub
End Class
I have already tried using LONG
instead of INTEGER
, but the problem remained. Can anybody give me a clue about this issue?
EDIT: Both the VB.NET and the FORTRAN codes were programmed using Visual Studio 2015 with the Intel Fortran Compiler (Parallel XE 2017). The DLL was built using the STDCALL(/iface:stdcall)
calling convention.
ByVal
withm
andn
, but if I do so, the exceptionSystem.AccessViolationException
arises, accompanied with a warning about trying to overwrite protected memory. UsingByRef
on them was the only way to avoid it. - MSalmerp
as INTENT(INOUT) if you want to change the value of c. - M. ChinouneINOUT
, but it is still failing. - MSalmer