forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Accesing module variables in a DLL

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
StamK



Joined: 12 Oct 2016
Posts: 110

PostPosted: Tue Jul 02, 2019 10:55 pm    Post subject: Accesing module variables in a DLL Reply with quote

It doesn't seem possible to access global variables in a module in a DLL.
Module (in a separate file, to be made as a DLL)
Code:

!ftn95$free
MODULE TESTMOD      
 INTEGER*4      :: QT_NWIN   =  99
END MODULE


Main program (separate file, loads previous DLL)
Code:

!ftn95$free

program main
  USE TESTMOD

  SAVE
  print*," QT_NWIN =", QT_NWIN
   
END
 


When linking, it says:
Code:

WARNING the following symbols are missing:
MODULE TESTMOD


and when I run it, I can see that it has a random value of QT_NWIN.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6001
Location: Salford, UK

PostPosted: Wed Jul 03, 2019 6:57 am    Post subject: Reply with quote

When you compile a 32 bit module you get an interface in a .mod file and (usually) object code in a .obj file. Similarly for 64 bit code.

When you build something that accesses the module then the access at compile time is via a USE statement the uses the .mod file whilst the module .obj file is used at link time.

The process that you use to build a DLL is essentially the same as building an executable but there is no main program. A module still works via a .mod file and a .obj file. When linking you indicate that you want a DLL.

Routines that are in the DLL (within modules or not) are linked to the executable when it is loaded for running but there is no equivalent linking of module data. So the address of QT_NWIN in the DLL will not automatically be the same as the address of QT_NWIN in the executable. If you need to share data then the sharing must be done in some other way.
Back to top
View user's profile Send private message
StamK



Joined: 12 Oct 2016
Posts: 110

PostPosted: Wed Jul 03, 2019 9:16 am    Post subject: Reply with quote

Thanks for that. But why is there the warning

WARNING the following symbols are missing:
MODULE TESTMOD

Thanks
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6001
Location: Salford, UK

PostPosted: Wed Jul 03, 2019 9:19 am    Post subject: Reply with quote

I don't understand that. I would need a demonstration from your code and build process.
Back to top
View user's profile Send private message
StamK



Joined: 12 Oct 2016
Posts: 110

PostPosted: Wed Jul 03, 2019 9:36 am    Post subject: Reply with quote

If you copy the code above and make it into two files
testmod.for
app_main.for

and you do
ftn95 /windows /sparam 0 /zero /f2k /cfpp testmod.for
slink /3gb -dll -exportall testmod.obj
ftn95 /windows /sparam 0 /zero /f2k /cfpp app_main.for
slink /3GB testmod.dll app_main.obj

You will see the above warning
Back to top
View user's profile Send private message
StamK



Joined: 12 Oct 2016
Posts: 110

PostPosted: Wed Jul 03, 2019 9:46 am    Post subject: Reply with quote

I just realised the last line should be

slink /3GB app_main.obj testmod.dll

i.e. first the object file and then the DLL file, but the warning is still there.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6001
Location: Salford, UK

PostPosted: Wed Jul 03, 2019 10:39 am    Post subject: Reply with quote

I don't know exactly what is happening but there is nothing to export from this module. You can only export subprograms. You can't export variables.
Back to top
View user's profile Send private message
StamK



Joined: 12 Oct 2016
Posts: 110

PostPosted: Wed Jul 03, 2019 10:43 am    Post subject: Reply with quote

Even if you add a subroutine the same thing happens. It does work (i.e. you can call the subroutine), but you get this warning. I am hoping it is not an indication of something more sinister...

Code:

!ftn95$free

MODULE TESTMOD
 
 INTEGER*4      :: QT_NWIN   =  99

 contains

subroutine testmodinit
  QT_NWIN = 100
end subroutine

END MODULE
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6001
Location: Salford, UK

PostPosted: Wed Jul 03, 2019 1:59 pm    Post subject: Reply with quote

I don't know why there is this report of a missing symbol.

If there are no runtime errors then I would treat it as benign.

The QT_NWIN in the main program will not have the same address as the QT_NWIN in the DLL and in my testing the QT_NWIN in the main program cannot be accessed.

So if you need to put a module into a DLL then you will have to do something special in order to access the module data from the executable.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group