31 lines
795 B
Fortran
31 lines
795 B
Fortran
program dynload
|
|
use kernel32
|
|
use iso_c_binding
|
|
implicit none
|
|
|
|
abstract interface
|
|
function ffun_int(x, y)
|
|
!DEC$ ATTRIBUTES STDCALL, REFERENCE :: ffun_int
|
|
double precision :: ffun_int, x, y
|
|
end function
|
|
end interface
|
|
|
|
procedure(ffun_int), pointer :: ffun_ptr
|
|
|
|
integer(c_intptr_t) :: ptr
|
|
integer(handle) :: h
|
|
double precision :: x, y
|
|
|
|
h = LoadLibrary("dllfun.dll" // c_null_char)
|
|
if (h == 0) error stop "Error: LoadLibrary"
|
|
|
|
ptr = GetProcAddress(h, "ffun" // c_null_char)
|
|
if (ptr == 0) error stop "Error: GetProcAddress"
|
|
|
|
call c_f_procpointer(transfer(ptr, c_null_funptr), ffun_ptr)
|
|
read *, x, y
|
|
print *, ffun_ptr(x, y)
|
|
|
|
if (FreeLibrary(h) == 0) error stop "Error: FreeLibrary"
|
|
end program
|