Fortran Coder

标题: vb如何向fortran传递参数(参数是函数)? [打印本页]

作者: llsvvv    时间: 2016-1-9 08:48
标题: vb如何向fortran传递参数(参数是函数)?
fortran生成dll
例如dll里有求积分的函数:function jf=f(x)*dx
        jf返回 f(x)从a到b的积分
f(x)在vb里编写例如:
[Visual Basic] 纯文本查看 复制代码
function f(x)
  f=sin(x)+x
end function

如何把vb里的函数传递到dll?




作者: li913    时间: 2016-1-10 18:55
本帖最后由 li913 于 2016-1-10 18:57 编辑

给你个例子作为参考。
[Visual Basic] 纯文本查看 复制代码
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] 纯文本查看 复制代码
!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
li913 发表于 2016-1-10 18:55
给你个例子作为参考。[mw_shl_code=vb,true]Public Class Form1
    Private Declare Sub exdll Lib " d1.d ...

谢谢!雪中送炭




欢迎光临 Fortran Coder (http://bbs.fcode.cn/) Powered by Discuz! X3.2