Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29233 Discussions

Accessing a common block using GetProcAddress

devteam
Beginner
939 Views

Hi,

I am trying to explicitly load a dll within a main program.

LoadLibrary works fine.

GetProcAddress allows me to access exported subroutines in my dll.

However, it cannot use this function to access common blocks, although I have exported them.

Win32 documentation on the function suggests it is designed to access functions as well as variables.

Does anybody have a suggestion ?

Andy

PS. I want to avoid having to link with my dll's lib file - i.e. I need to load the dll explicitly

0 Kudos
4 Replies
devteam
Beginner
939 Views

I have got the address now (a lower/upper case stupid problem), but the content of the common (a real*8 variable) is not shared. Any ideas ?

0 Kudos
Steven_L_Intel1
Employee
939 Views

Where you build the DLL, add the following to the Linker "additional options:

/section:.data,RWS

This is required when you want to read-write share a COMMON with a DLL.

0 Kudos
devteam
Beginner
939 Views

Hi Steve,

Thank you for the suggestion. I still can't make it work.

In my main program, I have declared

real*8 mainvar

common/maincommon[dllexport]/ mainvar

mainvar = -1.D0

I then call an initialization function of my dll, in which I wish to make maincommon shared

real*8 mainvar

common/maincommon/ mainvar

integer hExe

integer*4 pcommon

hExe = LoadLibrary("main.exe") ! Open the main program

pcomm = GetProcAddress(hExe, "maincommon")

I would like to see mainvar = -1.D0, yet it is always 0.D0 even with the linker option

Thanks for any help !

0 Kudos
Steven_L_Intel1
Employee
939 Views

Oh, I see. You can't do it that way and I should have spotted that earlier. To reference the COMMON from the DLL you will have to do it as if it were an external variable, not a COMMON in the main program. So instead of:

common /maincommon/ mainvar

use:

pointer (pcommon, mainvar)

You should also remove the declaration of pcommon (let the POINTER statement declare it) and use the name pcommonand not pcomm in the assignment from GetProcAddress.

The only way to share COMMONs with a DLL and still use it as a COMMON is to link to an export library.

0 Kudos
Reply