Fortran dll call from VB.Net



下面的代码包含来自vb.net的fortran77dll调用,该调用具有二维数组和结构。输入参数为flg&a_in(,),它计算一些值,然后在a_pn(,)a_vOUT(,)中填充输出数组。fortran dll中使用了一个addressof回调函数。我无法获取输出值以继续操作。

---VB.Net代码与Fortran dll调用--

Dim flg As Int32
Dim a_in(,) As Double --- Input array with values
Dim a_PN(,) as Double ----Output array return from Fortran77 DLL (Value calculated from a_in(,) array and returns)
Dim a_vOUT(,) as Double ----Output array return from Fortran77 DLL 
Dim a_Flgs(,) as Int32
Dim a_b() as byte
Dim a_string1 As New VB6.FixedLengthString(255)
Public Structure Case_Info
    Dim nx() As Double
    Dim ny() As Double
    Dim tc() As Double
    Dim ip(,) As Double
End Structure
 W_Ftrn(Flg, a_in(1, 1), a_PN(1, 1),a_vOUT(1, 1), a_Flgs(1, 1), .TC(1), .ip(1, 1),.nx(1), .ny(1), AddressOf CallBack0, AddressOf CallBack1, a_b(1), a_string1.Value, 255)

---vb.net--中的Fortran声明

 Public Declare Sub W_Ftrn _
       Lib "D:Proj2Fortran.DLL" Alias "W_Ftrn" _
      (ByRef flg As integer,ByRef a_in As Double, ByRef a_PN As Double, ByRef a_vOUT As Double, ByRef a_Flgs As Int32, _
       ByRef constray As Double, ByRef ipn As Double, _
       ByRef aGX%, ByRef aGY#, _
       ByVal cbaddr0 As long,ByVal cbaddr1 As long,ByRef bPlain As Byte, _
       ByVal s1 As String, ByRef L1 As Int32)

我的猜测是,在F77调用前后,您将不得不自己手动复制要写入的数组单元格。类似这样的东西:

Dim a_in1 As Double 
Dim a_PN1 as Double 
Dim a_vOUT1 as Double 
Dim a_Flgs1 as Int32
Dim a_b1 as byte
Dim nx As Double
Dim ny As Double
Dim tc As Double
Dim ip1 As Double
' copy-in, manually '
a_in1 = a_in(1, 1)
a_PN1 = a_PN(1, 1)
a_vOUT1 = a_vOUT(1, 1)
a_Flgs1 = a_Flgs(1, 1)
tc = .TC(1)
ip1 = .ip(1, 1)
nx = .nx(1)
ny = .ny(1)
a_b1 = a_b(1)
W_Ftrn(Flg, a_in1, a_PN1,a_vOUT1, a_Flgs1, TC, ip1, nx, ny, AddressOf CallBack0, AddressOf CallBack1, a_b1, a_string1.Value, 255)
' copy-out, manually '
a_in(1, 1) = a_in1
a_PN(1, 1) = a_PN1
a_vOUT(1, 1) = a_vOUT1 
a_Flgs(1, 1) = a_Flgs1
.TC(1) = tc 
.ip(1, 1) = ip1
.nx(1) = nx
.ny(1) = ny
a_b(1) = a_b1 

最新更新