Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

windows - Trouble with file location in excel/fortran dll connection

Platform: WinXP SP2, Intel Fortran 11, Excel 2007

I'm having trouble connecting a dll file with excel.

The dll file is relatively simple:

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

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) ?)

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

and in Moduel1:

Declare Sub FortranCall Lib "C:empFcall.dll" (r1 As Long, ByVal num As String)

When ran it reports an error: runtime error 53, file not found c:empfcall.dll

Anyone has any clue what could be wrong ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had the same problem - super frustrating!

I had the similar kind of declaration in Excel VBA: Declare Sub FortranCall Lib "C:empFcall.dll" (r1 As Long, ByVal num As String)

It worked on my computer but it did not work on my boss's computer. All the spelling of the file name and the path specification were fine. My DLL was compiled in Microsoft Visual C++ 6.0. The problem was - A common cause for "File not found/Runtime error 53" is that the calling application cannot find dll's on which the dll in question actually depends!!! I gave my boss the DLL that I compiled in DEBUG mode - in this case DLL uses lots of other debug versions of DLL which not commonly found on regular computers. When I gave my boss RELEASE version of DLL it worked fine! See also: http://software.intel.com/en-us/forums/showthread.php?t=42472


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...