- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a problem with the following code, which calls a routine named "SALTCHEM" located in a dll (saltchem.dll):
This procedure works when all these statements are in the main program.
However, what I really want to do, is to call this routine "SALTCHEM" from another subroutine X,
i.e. not from the main program where I loaded the dll.
So, I'm setting up the pointers pp and qq in the main program, as above,
then I'm bringing them over to subroutine X which now contains the call to "SALTCHEM" (call rtn_saltchem(...)).
This seems to work when I bring over the pointers pp and qq from the main program to subroutine X
through a COMMON block, but it doesn't work when I bring them over through a module.
In the latter case, I get the following compiler error:
Error: This scalar name is invalid in this context. [RTN_SALTCHEM]
Why does it work with a COMMON block but not with a MODULE? Any suggestions?
pointer(pp,ii) pointer(qq,rtn_saltchem) pp = loadlibrary("saltchem.dll"C) ! load the dll into memory qq = getprocaddress(pp, "SALTCHEM"C) ! set up a pointer to the routine "SALTCHEM" located in the dll call rtn_saltchem(...) ! call the routine "SALTCHEM"
This procedure works when all these statements are in the main program.
However, what I really want to do, is to call this routine "SALTCHEM" from another subroutine X,
i.e. not from the main program where I loaded the dll.
So, I'm setting up the pointers pp and qq in the main program, as above,
then I'm bringing them over to subroutine X which now contains the call to "SALTCHEM" (call rtn_saltchem(...)).
This seems to work when I bring over the pointers pp and qq from the main program to subroutine X
through a COMMON block, but it doesn't work when I bring them over through a module.
In the latter case, I get the following compiler error:
Error: This scalar name is invalid in this context. [RTN_SALTCHEM]
Why does it work with a COMMON block but not with a MODULE? Any suggestions?
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Looks to me as if the compiler doesn't know rtn_saltchem is a pointee. Is the POINTER declaration visible to routine X?
Steve
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok, I whipped up a small example and I can see that if you have just a POINTER statement in the module, then the compiler doesn't treat rtn_saltchem as a callable routine. This sort of makes sense to me - there's nothing in the context of the module to say that it's a routine. When you use a COMMON, you have the call and the pointer declaration in the same program unit, so the compiler figures it out.
Here's the solution - add an INTERFACE for RTN_SALTCHEM to the module. Here's a complete example that works:
Here's the solution - add an INTERFACE for RTN_SALTCHEM to the module. Here's a complete example that works:
module mymod pointer (p,q) interface subroutine q end subroutine q end interface end module mymod subroutine one use mymod external three p = loc(three) return end subroutine two use mymod call q return end subroutine three write (*,*) "I'm three!" return end program main call one call two end
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page