barrera
Joined: 29 Apr 2020 Posts: 3
|
Posted: Thu Apr 30, 2020 1:09 am Post subject: Calling A FORTRAN DLL From Excel & VBA |
|
|
Using:
Windows 8.1 © 2013
64 bit OS, x64-based processor
MS Office 2013 x64
Download the example from https://myengineeringworld.net/2014/03/fortran-dll-excel-vba.html
Copy the “Calling A FORTRAN DLL From Excel & VBA.xlsm” to the folder ..\MySample\Release\x64
Open the .xlsm
Click on the “Enable Content” button
In VBA window, add “PtrSafe” to both Public Declare…
Save and Close
As seen in https://www.silverfrost.com/32/ftn95/ftn95_personal_edition.aspx just downloaded the compiler FTN95 Personal Edition (FTN95PE) version 8.61 from http://www.ftn95.co.uk/ftn95/ftn95-8.61/ftn95_personal.exe
Run "C:\Program Files (x86)\Silverfrost\FTN95\plato.exe"
File > New > Project:
Project Type: Fortran DLL
Name: MySample
OK
In “Project Explorer”, right click on “Source Files”, click on “Add New Item”
Type: Free format Fortran file
Name: MyCode
And paste the content of the downloaded MyCode.f90 in a new .f95 source file
Configuration: Release Platform: x64
Build > Build
So far so good:
“Compiling file: MyCode.f95
C:\Users\BarRErA\Documents\MySample\MyCode.F95(17) : warning 197 - Variable C has been declared but not used
C:\Users\BarRErA\Documents\MySample\MyCode.F95(17) : warning 197 - Variable D has been declared but not used
C:\Users\BarRErA\Documents\MySample\MyCode.F95(51) : warning 197 - Variable I has been declared but not used
Compilation completed with no errors.
Linking...
Creating dynamic link library C:\Users\BarRErA\Documents\MySample\Release\x64\MySample.dl”
When opening the .xlsm, Excel crashes or a exception is thrown.
“FATAL ERROR > Silverfrost exception handler has failed”
Commenting the FRICTIONFACTOR on the .f95 code, compiling again, then going to Excel > tab Sub > clicking RUN (i.e. running the VBA Sub CallDoubleArray()), it works. The problem is with the function call.
I have no clue about what to do. It is my first contact with FORTRAN, I’m an engineer that wants to translate some thermodynamic calculations from VBA to Fortran.
And I got this log:
"Silverfrost 64-bit exception report on C:\Program Files\Microsoft Office 15\Root\Office15\EXCEL.EXE Wed Apr 29 15:08:57 2020
Unknown exception (c004f012) at address 7ffd8cec908c
Within file KERNELBASE.dll
In RaiseException at address 6C
In RpcRaiseException at address 51
Within file RPCRT4.dll
In RpcRaiseException at address 14
In NdrClientCall3 at address F6A
In NdrClientCall3 at address FE
Within file sppc.dll
In SLUnregisterPlugin at address 993
In SLGetPolicyInformation at address 63
In Ordinal7162 at address 12B8
Within file mso.dll
In Ordinal7162 at address 11B4
In Ordinal7162 at address 14C0
RAX = 000000391254e420 RBX = 00000000c004f012 RCX = 00007ffd8ecec750 RDX = 0000000000000000
RBP = 0000000000000003 RSI = 0000000000000000 RDI = 000000391254eaf0 RSP = 000000391254e670
R8 = 000000391254e420 R9 = 00007ffd66dc1438 R10 = 00007ffd8ecfe844 R11 = 000000391254e420
R12 = 0000000000000000 R13 = 0000000000000001 R14 = 000000391254ef28 R15 = 000000391254f228
7ffd8cec908c) mov_q RCX,[c0+RSP]" |
|