- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have been using the CVF syntax POINTER (p,MYSUB) to assign p the address of the subroutine MYSUB. I then modify the address of p using p=GetProcAddress(...). When I later call MYSUB, it is found at the new address. This seems to work very well. However, what I really need is for p to be an array of pointers, each of which points to a different subroutine and I am having trouble finding the proper syntax.
I declare the array of pointers INTEGER, POINTER :: p(:) and allocate space for it. I then use p(1)=LOC(MYSUB1) in order to associate MYSUB1 with p(1). Again, I use p(1)=GetProcAddress(...) to modify the address. However when I call MUSUB1 afterwards, it still has the old address.
I would highly appreciate any thoughts or comments that you might have and as always, many thanks in advance.
Cheers,
David
I declare the array of pointers INTEGER, POINTER :: p(:) and allocate space for it. I then use p(1)=LOC(MYSUB1) in order to associate MYSUB1 with p(1). Again, I use p(1)=GetProcAddress(...) to modify the address. However when I call MUSUB1 afterwards, it still has the old address.
I would highly appreciate any thoughts or comments that you might have and as always, many thanks in advance.
Cheers,
David
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Don't mix the Fortran 90 pointers with the integer pointer extension.
Get 6.5A, then do something like this:
INTEGER(INT_PTR_KIND()) P(n)
POINTER (PP, MYSUB)
Store your addresses in the elements of P, then when you want to use one:
PP = P(1)
CALL MYSUB (...)
Steve
Get 6.5A, then do something like this:
INTEGER(INT_PTR_KIND()) P(n)
POINTER (PP, MYSUB)
Store your addresses in the elements of P, then when you want to use one:
PP = P(1)
CALL MYSUB (...)
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's not 100% clear to me how you're trying to achieve it; it looks as if you mixed up a little integer ("cray") pointers and fortran pointers, which are quite different beasts (and, unfortunately, both are described with POINTER keyword, used differently in different contexts). Please note that POINTER in declaration INTEGER, POINTER:: p(:) has absolutely nothing related with use of pointers to functions. In order to simulate an "array of functions", it's enough to have an ordinary static or ALLOCATABLE array;
you fill it in with LOCs of functions and later dereference it, smt. like:
Note that you can literally use name GenericFunction for your subroutine: INTERFACE block above accompanied with a integer POINTER
only describes routine prototype, but routine GenericFunction exists only "in vain" until you assign address of an existing function (szRealFunctionNameX) to lpfnGeneric. When you call GenericFunction, you really call szRealFunctionName1, 2,...
HTH
Jugoslav
you fill it in with LOCs of functions and later dereference it, smt. like:
INTERFACE SUBROUTINE GenericRoutine(arg1, arg2,...) !arg declarations here END INTERFACE POINTER (lpfnGeneric, GenericFunction) INTEGER:: locFunction(20) locFunction(1)=GetProcAddress(hDll, szRealFunctionName1) locFunction(2)=GetProcAddress(hDll, szRealFunctionName2) ... DO i=1,nWhatever lpfnGeneric = locFunction(i) CALL GenericFunction(...) END DO
Note that you can literally use name GenericFunction for your subroutine: INTERFACE block above accompanied with a integer POINTER
only describes routine prototype, but routine GenericFunction exists only "in vain" until you assign address of an existing function (szRealFunctionNameX) to lpfnGeneric. When you call GenericFunction, you really call szRealFunctionName1, 2,...
HTH
Jugoslav

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