PDA

View Full Version : Export a module procedure from a DLL?


R. T. (Fortran Man)
02-09-2004, 08:05 PM
Is it possible to export a module procedure from a DLL? If so, how do you do it? What about exporting data?

Lahey Support
02-09-2004, 08:47 PM
It is not possible to explicitly export a procedure that is in a module. However, it is possible to export the module as a whole. When the module is imported and USEd, the procedure can then be called like any other module procedure. The calling procedure has access to both data and procedures in the module.

Example module (mod1.f90):

module mod1
dll_export :: mod1
integer :: i = 1, j = 2, k = 3
real :: a = 10., b = 20., c = 30.
contains
subroutine bar(x,l)
real ::x
integer :: l
a = x
b = x*2.
c = x*3.
i = l
j = l + 1
k = l + 2
end subroutine
end module


Example use (callmod1.f90):

program callmod1
use mod1
dll_import :: mod1
write(*,*) i,j,k
write(*,*) a,b,c
call bar(5.,5)
write(*,*) i,j,k
write(*,*) a,b,c
end program


Example compile commands:

lf90 mod1.f90 -dll
lf90 callmod1.f90 mod1.lib


Example execution output:
1 2 3
10.0000000 20.0000000 30.0000000
5 6 7
5.00000000 10.0000000 15.0000000