Quantcast
Channel: Intel® Software - Intel® Visual Fortran Compiler for Windows*
Viewing all articles
Browse latest Browse all 5691

DLL can't see main program's shared variables

$
0
0

Hi All,

I want to learn how to make a DLL share variables in a module USEd by both the DLL and its calling main program. From examples I can find I have put together a very small test program which unfortunately does not work. Here are the mainline, the DLL, and the module:

program DLLtester

use SharedVariables
use ifwin

implicit none

integer*4         hlb,iret
pointer           (cpaddr,calcpi)
character*1       ch

hlb = loadlibrary('..\..\CalcPi\Debug\calcpi.dll'//char(0))
if(hlb==0)then
   type *,"Can't find CalcPi.DLL"
   accept *, ch
   call exit
end if

cpaddr = getprocaddress(hlb,"CALCPI"C)
if(cpaddr==0)then
   type *,"Can't locate CalcPi in CalcPi.DLL"
   accept *, ch
   iret = freelibrary(hlb)
   call exit
end if

numerator = 355.0
denominator = 113.0

call CalcPi
iret = freelibrary(hlb)

type *, pi
accept *, ch

end program DLLtester

 

 

subroutine CalcPi

! Expose subroutine CalcPi to users of this DLL
!
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS:"CALCPI" :: CALCPI

use SharedVariables

implicit none

pi = numerator/denominator
return

end subroutine CalcPi

 

 

module SharedVariables

implicit none

real*8  ::           numerator
!DEC$ ATTRIBUTES DLLEXPORT :: NUMERATOR

real*8  ::           denominator
!DEC$ ATTRIBUTES DLLEXPORT :: DENOMINATOR

real*8  ::           pi
!DEC$ ATTRIBUTES DLLEXPORT :: PI

end module

 

What do I need to do to make this work?

With many thanks in advance

Mike


Viewing all articles
Browse latest Browse all 5691

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>