views:

433

answers:

3

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:\temp\Fcall.dll" (r1 As Long, ByVal num As String)

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

Anyone has any clue what could be wrong ?

+1  A: 

Not sure what could be wrong.

I couldn't get my hands on an ifort compiler, but I tried your code by copying a random DLL to the Temp folder specified the Declare statement. When I run it, the error I get is: "Can't find DLL entry point FortranCall in C:\Temp\RandomDLL.DLL", which is consistent with using the wrong DLL (that is, the DLL was found, but it doesn't jive with the calling code).

You could try to replace the DLL you compiled with a random other DLL and see if you get the same error. If you do, it is a problem with the OS environment, not the compiler.

This is probably not very helpful, but may eliminate one or two possibilities.

Environment I used: Win Vista, Excel 2003

KnomDeGuerre
+1  A: 

You could try moving your DLL to C:\Windows\system32 (or any other folder that's on the default path) and changing the Lib part to just "FCall.dll". That should eliminate any oddities with locating the actual file

barrowc
C:\temp is on the envir. var. PATH as well. So my guess is they are equal.
ldigas
A: 

Is there a definitive solution to this problem? I am trying to switch from Compaq Visual Fortran to Intel, using Office 2010, and have problems calling my DLL from Excel (VB). A tried a simple example:

Fortan: subroutine XtimesY(x,y,z)

!DEC$ ATTRIBUTES DLLEXPORT,STDCALL,DECORATE,ALIAS:"XTIMESY":: XtimesY !DEC$ ATTRIBUTES REFERENCE::x !DEC$ ATTRIBUTES REFERENCE::y !DEC$ ATTRIBUTES REFERENCE::z

    real*4 :: x,y,z
    z=x*y

    RETURN
    END

VB call:

Declare Sub XtimesY Lib "Fortrial" (ByRef Par1 As Single, ByRef Par2 As Single, ByRef Par1 As Single)


Sub Macro1() Dim xx As Single, yy As Single, zz As Single

xx = Worksheets("Computations").Range("C7").Value
yy = Worksheets("Computations").Range("d7").Value

Call XtimesY(xx, yy, zz)
Worksheets("Computations").Range("e9").Value = z

End Sub

Mark Randolph
Forgot to mention that I get a somewhat random result: 90 % of the time I get the standard "file not found" error (53), 5 % of the time I get "bad entry point in XtimesY" and 5 % of the time it works!!
Mark Randolph