I'm a programmer for a company that has a Delphi application that allows users to write their own programs so they can process data in their own way. We allow users several choices of programming languages to do this, one of which is Fortran. In order to interface with the main application we provide an interface that their code needs to follow. As the main program has been ported to run on 64-bit platforms we have also ported this interface as the main program loads a DLL that is created from these users programs (as we call them). Most of these programs run correctly but one doesn't. So further details. I’ve uploaded a file that contains the source code for the 1 C and 2 Fortran programs mentioned below.
iplink.c is a small C source file that we use to interface with our main app. This source is compiled to an object file using
x86_64-w64-mingw32-gcc -c -DBUILDING_DLL=1 -I. -m64 -o iplink64.o iplink.c
We then have two Fortran 77 source files both of which we provide. One of them (Function.f) the users aren't meant to edit, but the other (UsersCode.f) is a functional bare bones template that they can edit. The two Fortran source files & the C object file are then compiled into a DLL using the following
x86_64-w64-mingw32-gfortran -c -O -m64 -o functions.o functions.f
x86_64-w64-mingw32-gfortran -c -O -m64 -o userscode.o userscode.f
x86_64-w64-mingw32-dllwrap --export-all-symbols --output-def UserProgram.def --implib UserProgram.a --driver-name x86_64-w64-mingw32-gfortran -m64 -o UserProgram.dll Iplink64.o functions.o userscode.o
This compiles without a problem (you get the usual: "x86_64-w64-mingw32-dllwrap: no export definition file provided. Creating one, but that may not be what you want").
Our main application (written in Delphi Pascal) loads up the UserProgram.dll without any problem (using a LoadLibrary API call) & then get a load of callbacks defined - eg
UserCode := IpUserCodeDelegate(Marshal.GetDelegateForFunctionPointer(GetProcAddress(UserProgDllHandle, 'usercode_'), TypeOf(IpUserCodeDelegate)));
where IpUserCodeDelegate is defined as a parameterless procedure.
We then set up various instance variables by calling delegate functions defined in the Iplinkc.c & Functions.f source files. However when we call the UserCode delegate (defined in UsersCode.f) we get an 0xC0000005 Access Violation error that takes down our main application. We have several of these User Programs but only one of the four we provide causes this problem. I have included a UsersCode.f file that works fine.
Any help would be greatly appreciated. Thanks for your time
Alastair