llsvvv 发表于 2016-1-9 08:48:39

vb如何向fortran传递参数(参数是函数)?

fortran生成dll
例如dll里有求积分的函数:function jf=f(x)*dx
      jf返回 f(x)从a到b的积分
f(x)在vb里编写例如:
function f(x)
f=sin(x)+x
end function
如何把vb里的函数传递到dll?



li913 发表于 2016-1-10 18:55:19

本帖最后由 li913 于 2016-1-10 18:57 编辑

给你个例子作为参考。Public Class Form1
    Private Declare Sub exdll Lib " d1.dll" (ByVal a As Integer, ByVal b As Integer, ByVal c As pro1)
    Delegate Sub pro1(ByRef a As Integer, ByRef b As Integer)
    Private Sub pro(ByRef a As Integer, ByRef b As Integer)
      Dim c As Integer
      c = a * b
      Debug.Print(c)
      MsgBox(c.ToString)
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
      Dim x, y As Integer
      x = 2
      y = 5
      Call exdll(x, y, AddressOf pro)
    End Sub

End Class
!Fortran代码:

subroutine exdll(x,y,bkpro)

      !DEC$ ATTRIBUTES stdcall,DLLEXPORT :: exdll
      !DEC$ ATTRIBUTES alias : "exdll" :: exdll
      !DEC$ ATTRIBUTES value :: x,y
      !DEC$ ATTRIBUTES reference :: bkpro

      integer(4) x,y,a,b
      interface
                subroutine bkpro(a,b)
                  integer(4) a,b
                end subroutine
      end interface

      a=x+1
      b=y+1
      call bkpro(a,b)
end subroutine exdll

llsvvv 发表于 2016-1-11 02:29:12

li913 发表于 2016-1-10 18:55
给你个例子作为参考。Public Class Form1
    Private Declare Sub exdll Lib " d1.d ...

谢谢!雪中送炭
页: [1]
查看完整版本: vb如何向fortran传递参数(参数是函数)?