replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Modules in DLL
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 

Modules in DLL

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



Joined: 29 Aug 2005
Posts: 165
Location: Berlin, Germany

PostPosted: Tue Apr 30, 2013 4:42 pm    Post subject: Modules in DLL Reply with quote

Is there any way to use a module of the calling program within a DLL?

Thanks for any help or information,

Detlef
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


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

PostPosted: Tue Apr 30, 2013 6:22 pm    Post subject: Reply with quote

No. Not in a direct way.

Modules contain data and subprograms that should operate on the data.
The usual way to pass data (and I guess subprograms) from an executable to a DLL would be via an subprogram argument list.

For a fuller explanation, it would help if you could give more details about what you have in mind. Do you want to pass both data and subroutines?
Back to top
View user's profile Send private message AIM Address
dpannhorst



Joined: 29 Aug 2005
Posts: 165
Location: Berlin, Germany

PostPosted: Tue Apr 30, 2013 6:38 pm    Post subject: Reply with quote

I want to separate some parts of a large program in a DLL. The modules are containing only data. Because the amount of data used is very large, a subprogram argument list gets very long.

There is also another question:

Is it possible to call subroutines of the main program to call from within the DLL?
Back to top
View user's profile Send private message Visit poster's website
JohnCampbell



Joined: 16 Feb 2006
Posts: 2615
Location: Sydney

PostPosted: Wed May 01, 2013 1:25 am    Post subject: Reply with quote

Modules are a good way to define a data structure and contain routines that operate on that data structure.

I am not a user of DLLs and don't understand why they are essential.
I also use static libraries, which include modules and these work well with slink.
I am not sure if DLL's can't also include modules. If they can then they would operate similar to libraries.
I think the key point is that routines that operate on the module database should be contained with the module, while third party or other DLL's should have a more generic database interface.

Again, going down the module path, using derived type data structures, I would consider it essential to operate on these data structure via a CONTAINS or USE. The DLL needs to know the data structure, which means that it has a USE. The derived type data structure is a key component of teh program operation.

Can someone clarify if you can use modules in a DLL and if so they should be defined in the DLL. If not then DLL's should be used in a more general way.

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


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

PostPosted: Wed May 01, 2013 6:11 am    Post subject: Reply with quote

The key to passing a large amount of data is to pack the data into a structure (i.e. a Fortran user-defined type). Then pass the structure (i.e. its address) as an argument. The DLL will know the form of the structure and can access data members that way.

The usual way to call local subprograms from a DLL is to pass the subprogram as an argument. This is what happens in ClearWin+ when you use a callback function.
Back to top
View user's profile Send private message AIM Address
dpannhorst



Joined: 29 Aug 2005
Posts: 165
Location: Berlin, Germany

PostPosted: Wed May 01, 2013 8:35 am    Post subject: Reply with quote

Do you have some small examples for both cases?
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


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

PostPosted: Wed May 01, 2013 8:27 pm    Post subject: Reply with quote

Passing data....

Code:
subroutine foo(obj)
type my_object
 sequence
 real real_member
 integer integer_member
end type
type(my_object)::obj
obj%integer_member = 42
end subroutine foo

program main
type my_object
 sequence
 real real_member
 integer integer_member
end type
type(my_object)::obj1
 call foo(obj1)
 print*, obj1%integer_member
end program main
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


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

PostPosted: Wed May 01, 2013 8:48 pm    Post subject: Reply with quote

Passing subroutines...

This is not what you need but it might help to point you in the right direction.
It's been a long day.

Code:
subroutine foo(val)
integer val
print*,val
end subroutine foo

subroutine bar(f,v)
external f
integer v
call f(v)
end subroutine bar

program main
external foo
call bar(foo,42)
end program main
Back to top
View user's profile Send private message AIM Address
dpannhorst



Joined: 29 Aug 2005
Posts: 165
Location: Berlin, Germany

PostPosted: Thu May 02, 2013 8:08 am    Post subject: Reply with quote

I will try this.

Many thanks for your support,

Detlef
Back to top
View user's profile Send private message Visit poster's website
dpannhorst



Joined: 29 Aug 2005
Posts: 165
Location: Berlin, Germany

PostPosted: Thu May 02, 2013 8:58 am    Post subject: Reply with quote

Paul, sorry I have problems to understand the subroutine example.

This is my code, I want to run:

Main:

Code:

!***********************************************************************
      PROGRAM DLL_TEST
!
      IMPLICIT NONE
!-----------------------------------------------------------------------
      CALL DLL
!
      END
!***********************************************************************
      SUBROUTINE MAINSUB(VAL)
!
      IMPLICIT NONE
!
      INTEGER*4 VAL
!-----------------------------------------------------------------------
      PRINT*,'HELLO MAINSUB-WORLD',VAL
!
      END
!***********************************************************************


DLL:

Code:

!***********************************************************************
      SUBROUTINE DLL
!
      IMPLICIT NONE
!
      EXTERNAL MAINSUB
!-----------------------------------------------------------------------
      PRINT*,'HELLO DLL-WORLD'
!
      CALL DLLSUB(10)
!
      CALL MAINSUB(20)
!
      END
!***********************************************************************
      SUBROUTINE DLLSUB(VAL)
!
      IMPLICIT NONE
!
      INTEGER*4 VAL
!-----------------------------------------------------------------------
      PRINT*,'HELLO DLLSUB-WORLD',VAL
!
      END
!***********************************************************************


My problem is to find a way to call subroutine MAINSUB from inside the DLL.

Detlef
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


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

PostPosted: Thu May 02, 2013 4:42 pm    Post subject: Reply with quote

Code:
!***********************************************************************
      PROGRAM DLL_TEST
!
      IMPLICIT NONE
      EXTERNAL MAINSUB
!-----------------------------------------------------------------------
      CALL DLL(MAINSUB)
!
      END
!***********************************************************************
      SUBROUTINE MAINSUB(VAL)
!
      IMPLICIT NONE
!
      INTEGER*4 VAL
!-----------------------------------------------------------------------
      PRINT*,'HELLO MAINSUB-WORLD',VAL
!
      END
!***********************************************************************

!***********************************************************************
      SUBROUTINE DLL(SUB)
!
      IMPLICIT NONE
!
      EXTERNAL SUB
!-----------------------------------------------------------------------
      PRINT*,'HELLO DLL-WORLD'
!
      CALL DLLSUB(10)
!
      CALL SUB(20)
!
      END
!***********************************************************************
      SUBROUTINE DLLSUB(VAL)
!
      IMPLICIT NONE
!
      INTEGER*4 VAL
!-----------------------------------------------------------------------
      PRINT*,'HELLO DLLSUB-WORLD',VAL
!
      END
!***********************************************************************
Back to top
View user's profile Send private message AIM Address
dpannhorst



Joined: 29 Aug 2005
Posts: 165
Location: Berlin, Germany

PostPosted: Thu May 02, 2013 5:35 pm    Post subject: Reply with quote

Thanks Paul, now I have understood. It's working as I want.

Detlef
Back to top
View user's profile Send private message Visit poster's website
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