主题:求助 vb fortran 混合编程。
非常简单,使用VB调用fortran的dll。
各种书都说,只要把vb数组的第一个元素地址传给fortran就好了。我使用vb。net测试了下面的程序,它工作的很好。可是用vb
.60时,就有问题了。传入fortran的数组第一个元素是对的,后面的元素都丢了。 因此,fortran再返回来的数都是错的了。
即下面程序中,mya 传入 fortran后 mya(1) (也就是vb中的
mya(0))是正确的,mya(2)就是诸如2.234234e-43这样的怪东西了。奇怪的是,这样的代码在vb.net中正常的很。
有人有办法解决或者遇到类似问题没? 我试过 cvf 和 ivf11 结果都一样。 希望高手解答!
the code as:
in vb:
Private Declare Sub Dll2 Lib "d:\Dll2.dll" (ByRef a As Single, ByRef b As Single, ByRef n As Long)
Private Sub Command1_Click()
Dim mya(1) As Single
Dim myb(1) As Single
Dim n As Long
mya(0) = 1.01
mya(1) = 1.1
myb(0) = 3.1
myb(1) = 4.1
n = 2
Call Dll2(mya(0), myb(0), n)
aa = myb(1)
End Sub
in fortran:
module testdll
IMPLICIT NONE
contains
subroutine Dll2(a,b,n)
! Expose subroutine Dll2 to users of this DLL
!DEC$ ATTRIBUTES :: Dll2
!DEC$ ATTRIBUTES DLLEXPORT,ALIAS: "Dll2":: Dll2
integer n
real a(n)
real b(n)
b(1)=a(1)
b(2)=a(2)
end subroutine Dll2
end module
the code as:
in vb:
Private Declare Sub Dll2 Lib "d:\Dll2.dll" (ByRef a As Single, ByRef b As Single, ByRef n As Long)
Private Sub Command1_Click()
Dim mya(1) As Single
Dim myb(1) As Single
Dim n As Long
mya(0) = 1.01
mya(1) = 1.1
myb(0) = 3.1
myb(1) = 4.1
n = 2
Call Dll2(mya(0), myb(0), n)
aa = myb(1)
End Sub
in fortran:
module testdll
IMPLICIT NONE
contains
subroutine Dll2(a,b,n)
! Expose subroutine Dll2 to users of this DLL
!DEC$ ATTRIBUTES :: Dll2
!DEC$ ATTRIBUTES DLLEXPORT,ALIAS: "Dll2":: Dll2
integer n
real a(n)
real b(n)
b(1)=a(1)
b(2)=a(2)
end subroutine Dll2
end module