debugging - 从 VB6.0 调用时,DLL 中的 Fortran `read(*,*)` 会导致 "run time error(39)"

标签 debugging dll vb6 fortran runtime-error

VB6.0中的代码是:

Private Declare Sub suba Lib "D:\try_vb\c_dll\Dll1\Dll1\Debug\Dll1.dll" (ByRef a As Single, ByRef b As Single, ByRef c As Single)
Private Sub Command1_Click()
    Dim a As Single
    Dim b As Single
    Dim c As Single
    a = 10#
    b = 2#
    Call suba(a, b, c)
    Text1.Text = c
End Sub

Fortran DLL 中的代码是:

subroutine suba(a,b,c)
!DEC$ ATTRIBUTES stdcall,DLLEXPORT ::suba
!DEC$ ATTRIBUTES ALIAS:"suba"::suba
!DEC$ ATTRIBUTES reference :: a,b,c
    implicit none
    real::a
    real::b
    real::c
    real::aaa

    c=a+b
    read(*,*)aaa       !This sentence seems wrong
end subroutine

如果read(*,*)aaa行不存在,程序可以返回正确答案c=12,如下所示: Fig 1

但是当read(*,*)aaa存在时,就会发生错误,即

forrtl:severe(39):error during read,unit -4,file CONIN$

forrtl:severe(39):error during read,unit -4,file CONIN$

我应该做什么?

最佳答案

这非常简单 - Fortran 代码正在尝试从控制台读取,而 VB 应用程序中没有。一般来说,您应该使用一种语言完成所有 I/O。您可以在 Fortran 中执行 READ 之前调用 Windows API 例程 AllocConsole 创建一个控制台,但这对于具有图形界面的 VB 应用程序来说似乎很愚蠢。

关于debugging - 从 VB6.0 调用时,DLL 中的 Fortran `read(*,*)` 会导致 "run time error(39)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42177086/

相关文章:

dll - 如何在 Windows 7 64 位上注册 DLL 文件?

dll - 发布 DLL azure

vb6 - 防止关闭表单

sql - VBA:将片段从 VBA 转换为 SQL

debugging - 调试 OCaml 代码时查看自定义数据类型的值

javascript - 我如何使一个组件具有全屏背景图像?

java - 如何在应用程序运行时探索 SQLite 数据库? Eclipse (Juno) > Android (adb)

linux - 我如何在 gdb 中查看 STL 列表值

c++ - 将 c++ dll 导入 vb.net 时,float*(图像类型)的等效数据类型是什么?

vb6 - 遗留 Visual Basic 代码中的隐式 ByRef