问题描述
平台:WinXP SP2、Intel Fortran 11、Excel 2007
Platform: WinXP SP2, Intel Fortran 11, Excel 2007
我在用 excel 连接 dll 文件时遇到问题.
I'm having trouble connecting a dll file with 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"目录(如何在这里写一个反斜杠,无论如何(除了复制/粘贴)?)
build with: ifort /nologo /dll Fcall.f90, and after that copied to "temp" directory on C drive (how does one write a backslash in here, anyway (except copy/pasting) ?)
我在 Sheet1 中有一个 Excel 文件:
and I have an Excel file with, in 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
在 Moduel1 中:
and in Moduel1:
Declare Sub FortranCall Lib "C: empFcall.dll" (r1 As Long, ByVal num As String)
运行时报错:runtime error 53, file not found c:empfcall.dll
任何人都知道可能出了什么问题吗?
推荐答案
我知道这是一个非常古老的问题,但前几天我遇到了这个问题,并认为我会为后代提供一个答案.我调用 Fortran DLL 的 VBA 代码在我的计算机上运行良好,但在我老板或其他任何人的计算机上却不行.尽管在发布"模式而不是调试"模式下编译,问题最终还是依赖于其他 DLL.我使用 Dependency Walker 在无法工作的计算机上检查 DLL 中的依赖关系,找到了两个 DLL它带有所需的英特尔编译器,并与我自己编译的 DLL 一起分发.
I know this is a very old question, but I came across this issue the other day and thought I'd put an answer up for posterity. My VBA code calling a Fortran DLL worked fine on my computer, but not on my boss's or anyone else's computer. The problem ended up being dependency on other DLLs, despite compiling in "release" mode instead of "debug". I used Dependency Walker to check the dependencies in the DLL on a computer where it wouldn't work, found two DLLs which come with the intel compiler that were needed, and distributed these with my own compiled DLL.
这篇关于excel/fortran dll连接中的文件位置问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!