平台:WinXP SP2、Intel Fortran 11、Excel 2007
我在将 dll 文件与 excel 连接时遇到问题。
dll文件比较简单:
subroutine FortranCall (r1, num)
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS:"FortranCall" :: FortranCall
integer, intent(in) :: r1
character(10), intent(out) :: num
!DEC$ ATTRIBUTES REFERENCE :: num
num = ''
write (num,'(i0)') r1 * 2
return
end subroutine FortranCall
构建:ifort/nologo/dll Fcall.f90,然后复制到 C 盘上的“temp”目录(这里怎么写一个反斜杠,无论如何(除了复制/粘贴)?)
我有一个 Excel 文件,在 Sheet1 中:
Private Sub CommandButton1_Click()
Dim r1 As Long
Dim num As String * 10
r1 = 123
Call FortranCall(r1, num)
TextBox1.Text = "Answer is " & num
End Sub
在模块 1 中:
Declare Sub FortranCall Lib "C:\temp\Fcall.dll" (r1 As Long, ByVal num As String)
运行时报错:runtime error 53, file not found c:\temp\fcall.dll
有人知道哪里出了问题吗?
最佳答案
我遇到了同样的问题 - 非常令人沮丧!
我在 Excel VBA 中有类似的声明: 声明 Sub FortranCall Lib "C:\temp\Fcall.dll"(r1 As Long, ByVal num As String)
它在我的电脑上工作,但在我老板的电脑上不工作。文件名的所有拼写和路径规范都没有问题。我的 DLL 是在 Microsoft Visual C++ 6.0 中编译的。问题是——“文件未找到/运行时错误 53”的一个常见原因是调用应用程序无法找到相关 dll 实际依赖的 dll!我把我在 DEBUG 模式下编译的 DLL 交给了我的老板——在这种情况下,DLL 使用了许多其他调试版本的 DLL,这在普通计算机上并不常见。当我给我的老板 DLL 的 RELEASE 版本时,它工作正常! 也可以看看: http://software.intel.com/en-us/forums/showthread.php?t=42472
关于windows - excel/fortran dll 连接中的文件位置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/970404/