Software Archive
Read-only legacy content

DLL Question

Intel_C_Intel
Employee
329 Views
Hello,

I am attempting to write a dll that will export one function, but will contain other helper functions that are used for the function I want to export. I have been able to get this part working. However I am having trouble with the variables that are contained in a COMMON statement. My idea is to declare them in the function I want to export, and then add the COMMON line to each of the helper functions that need access to the certain groups. This compiles as well.

Now from my main export function I call a subroutine that reads a file of data constants and assigns them to the variables in the COMMON block. I can step through this operation and I can see the variables are being assigned the correct value. However, when the subroutine exits and returns to the function I want to export the values stored in the variables in the COMMON are lost, or turned into garbage values. Can someone please help me determine what the problem is, or if what I am trying to do is even possible

N
0 Kudos
3 Replies
Jugoslav_Dujic
Valued Contributor II
329 Views
I can't tell immediately what is happening, but here are few tips how to debug it:

1) Switch on "Array & string bounds checking" (somewhere on Project/Settings/Fortran, probably "Run-time" category). Maybe you overwrite neighbouring items in COMMON.

2) Maybe your COMMON members declarations do not match? For example, Implicit integer*2 in one and Implicit integer*4 in another routine can make a nasty mess.

3) If 1) and 2) fail, examine (and write down) in the debugger values of LOC(a), LOC(b), LOC(c)... where a,b,c are first, second,... variable in the same COMMON block in the calling routine and the callee. Normally, these should be identical; if not, you've either an error in 2) or perhaps misspelled COMMON block name or have corrupted stack or... then, please repost (along with some code)

HTH

Jugoslav
0 Kudos
Intel_C_Intel
Employee
329 Views
I checked option 1 and 2, both check out fine. When I try 3, I get the same locations for all the variables in the common block

Basically, I am just trying to share the common blocks to the functions in the dll. Only one such functions is suppose to be accessible, all others are to remain hidden. The data stored in the Common block is only necessary for the the routines in the dll, so I don't want to import/export data from my main VB executable

The following is an example piece of code that represents what I am tying to do:

DOUBLE PRECISION FUNCTION OXIDELEVEL(PATH,DATAID,LOC,TIME,TEMP,FLUX)

!DEC$ ATTRIBUTES DLLEXPORT :: OXIDELEVEL
!DEC$ ATTRIBUTES ALIAS:'OXIDELEVEL' :: OXIDELEVEL


USE DFIMSL

IMPLICIT DOUBLE PRECISION(A-H,OZ)

CHARACTER*(*), INTENT(IN) :: PATH
CHARACTER*(*), INTENT(IN) :: DATAID
DOUBLE PRECISION, INTENT(IN) :: LOC
DOUBLE PRECISION, INTENT(IN) :: TIME
DOUBLE PRECISION, INTENT(IN) :: TEMP
DOUBLE PRECISION, INTENT(IN) :: FLUX

DOUBLE PRECISION TEMP2

COMMON/CONPARAMS/CON1,CON2,CON3,CON4,CON5
COMMON/INITIALSTATES/REC1,LOCS1,REC2,LOCS2
COMMON/WORK/A,B,C,GT,XIT,ERRABS,ERRREL
COMMON/DATA/XI,OXIDE,DAVG,D95U,D95L
DATA ERRABS,ERRREL/1.D-12,1.D-12/

!CALL INPUT TO READ THE VALUES OF THE CONFIG FILE INTO THE CONPARAMS !AND INITIALSTATES COMMONS

CALL INPUT(PATH)

TEMP2 = CALC(LOC,TIME,TEMP,FLUX)
END FUNCTION OXIDELEVEL

SUBROUTINE INPUT(PATH)

IMPLICIT DOUBLE PRECISION(A-H,OZ)

CHARACTER*(*), INTENT(IN) :: PATH
COMMON/CONPARAMS/CON1,CON2,CON3,CON4,CON5
COMMON/INITIALSTATES/REC1,LOCS1,REC2,LOCS2

OPEN(FILE=PATH,UNIT=1,STATUS='OLD')

READ(1,*) CON1
READ(1,*) CON2
READ(1,*) CON3
READ(1,*) CON4
READ(1,*) CON5

READ(1,*) REC1
READ(1,*) LOCS1
READ(1,*) REC2
READ(1,*) LOCS2

CLOSE(UNIT=1)

RETURN

END SUBROUTINE INPUT

DOUBLE PRECISION FUNCTION CALC(LOC,TIME,TEMP,FLUX)

!CONTENTS NOT INCLUDED
!USES MANY FUNCTIONS IN THE ISML LIBRARY

COMMON/CONPARAMS/CON1,CON2,CON3,CON4,CON5
COMMON/INITIALSTATES/REC1,LOCS1,REC2,LOCS2
COMMON/DATA/XI,OXIDE,DAVG,D95U,D95L

END FUNCTION CALC

Thanks for your help,

Nathan
0 Kudos
Intel_C_Intel
Employee
329 Views
Thanks for your help guys, I got it working later that day. I am not sure what I changed, but the COMMON blocks are correctly retaining their values.
0 Kudos
Reply