I am trying to load a Fortran DLL at runtime, using this code:
INTEGER :: p
pointer (q,AWAPROPS_SUB)
p = loadlibrary("AWAProps.dll"C)
NAME = "AWAPropsLicense_F"
q = getprocaddress(p, TRIM(NAME)//""C)
CALL AWAPROPS_SUB(IResult, CopyR)
(I am also checking that p and q are non-zero)
When I call this, I get the following error:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
I suspect this is because the DLL has been set up for calling from VBA, and the DLLEXPORTS are like:
Subroutine AWAPropsLicense_F(IResult, CopyR)
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, ALIAS:'AWAPropsLicense_F' :: AWAPropsLicense_F
!DEC$ ATTRIBUTES REFERENCE :: CopyR
IMPLICIT NONE
INTEGER, INTENT(OUT) :: IResult(1)
CHARACTER(LEN=33), INTENT(OUT) :: CopyR
What do I need to add to my Fortran calling program to allow for this different calling convention?
Also, within the same run, can I reuse the pointer q to call different routines (with different numbers of arguments), or do need a separate pointer for each?
Thanks,
David