Hi !
I want to port my 32bit VB-Fortran code to the 64bit platform, consisting in calling a fortran DLL both from VBA (ie: Excel) and VB.NET. In the attached pieces of code, everything runs fine in 32bit OS. In 64bit OS, VBA (64bit Excel) works fine, but VB.NET (calling the same 64bit DLL) crashes.
All fortran compilations (both 32bit and 64bit) were done as: ifort -dll -static polar.for
Does anybody has an idea what am I doing wrong?
VB.NET code
Private Declare Sub check1 Lib "c:\temp\polar.dll" (ByRef s1 as Single, ByRef i1 As Integer)
Private Declare Sub check0 Lib "c:\temp\polar.dll" (ByRef d1 As Double, ByRef i1 As Integer)
Dim aa As Single, ii As Integer : aa = 0.5 : ii = 6
Call check1(aa, ii) 'works OK
MsgBox("aa="& aa.ToString & " ii="& ii.ToString)
Dim bb(0 To 1000 - 1) As Double, jj(0 To 1000 - 1) As Integer
Call check0(bb(0), jj(0)) 'crashes !!!
MsgBox("bb(0)="& bb(0).ToString & " jj(0)="& jj(0).ToString)
VBA code
Private Declare PtrSafe Sub check1 Lib "c:\temp\polar.dll" (s1 As Single, i1 As Long)
Private Declare PtrSafe Sub check0 Lib "c:\temp\polar.dll" (d1 As Double, i1 As Long)
Dim aa As Single, ii As Long: aa = 0.5: ii = 6
Call check1(aa, ii) 'works OK
MsgBox "aa="& Str$(aa) & " ii="& Str$(ii)
Dim bb(0 To 1000 - 1) As Double, jj(0 To 1000 - 1) As Long
Call check0(bb(0), jj(0)) 'works OK
MsgBox "bb(0)="& Str$(bb(0)) & " jj(0)="& Str$(jj(0))
FORTRAN code
SUBROUTINE check1 (a,n)
!dec$ attributes dllexport,stdcall,reference,alias : "check1" :: check1
REAL*4 a
INTEGER*4 n
a = a + 1.0
n = n - 1
RETURN
END
SUBROUTINE check0 (a,n)
!dec$ attributes dllexport,stdcall,reference,alias : "check0" :: check0
REAL*8 a(0:999)
INTEGER*4 n(0:999)
a = 3.14159
n = -999
RETURN
END