|
From: Ben F. <dr....@gm...> - 2015-06-11 10:22:42
|
Hi,
I'm having trouble with some Fortran I've compiled as a DLL. When I call it
via VBA, it crashes Excel instantly. The original Fortran is quite large,
and requires a licence to some of it, so I've thrown together a simple
function. It also crashes, although the crash isn't instant now - it
manages to cycle through the "Excel has stopped working" messages.
I think the original Fortran should work, because if I change the Function
declaration to a Program, replace the function line with a command to write
the value to an output file, and compile as .exe, it works. The same goes
for my simple code.
My simple code is times2.for:
FUNCTION TIMES2(VBANUM)
REAL*8:: TIMES2, VBANUM
!GCC$ ATTRIBUTES DLLEXPORT :: TIMES2
!GCC$ ATTRIBUTES STDCALL :: TIMES2
TIMES2 = VBANUM * 2.
END FUNCTION TIMES2
The minGW commands I used are as follows:
gfortran -fno-underscoring -c times2.for
gfortran -fno-underscoring times2.o -shared -o doubling.dll -Wl,--kill-at
Then the VBA is below:
Public Declare Function times2 Lib "C:\F\doubling.dll" (ByVal VBANUM As
Double) As Double
Sub Twice()
Dim a As Double
a = Cells.Range("A1").Value
Cells.Range("A1").Value = times2(a)
End Sub
Now, I'm OK with VBA, have no experience with DLLs or minGW, and am trying
to recall rudimentary Fortran that I learned 10 years ago, so take it slow,
if you can.
Thanks for reading!
Ben
|