Silverfrost Forums

Welcome to our forums

Getting Variables in Modules from a DLL

29 Aug 2005 8:26 #290

Hello everybody,

I want to use the same variable in a main program and in a subroutine in a DLL. Therefore I am using in the main program and in the DLL's subroutine the same MODULE containing the definition of my variable. In the main program I set a value to the variable, but the value in the DLL's subroutine stays everytime at zero! What have I to do to share the variable between main program and DLL? (Compaq Fortran offers a DLL-Export / Import of variables).

Detlef Pannhorst

31 Aug 2005 3:07 #294

At the moment FTN95 does not enable you to link a common block (or module data) across a main program and a DLL or across two DLLs. If you use the Salford intrinsic LOC to get the addresses you will find that the two sets of data have different address spaces.

This limitation already appears on the wish list of things to do when time and resources permit.

What is needed is an EXTERNAL attribute that can be attached to a common block (or module data) in a way that is analogous to subprograms. Incidentally, you can embed a common block in a module so adding the feature for a common block alone may be sufficient.

A rather poor alternative is to put all the data into one array (using EQUIVALENCE statements for the variables) and to pass this array on each call. Since the array is passed by reference, the overhead is minimal. You could also put the relevant code in an INCLUDEd file.

Please login to reply.