Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29234 Discussions

Accessing a routine in a program FROM a dll (circular library reference?)

nbunderson
Beginner
732 Views
I have the following situation:
RoutineA and RoutineB are compiled in a static library (Lib1)
RoutineC is compiled in a dynamic linked library (Dll1)
Lib1 is linked to an executable EXE. At runtime I load Dll1 into the executable and RoutineA calls RoutineC (I learned how to do this from a forum entry onhttp://www.xeffort.com).
This all works great, the problem is that I would like RoutineC to call RoutineB in the original library. Right now the only way I can get this to work is by passing a reference to RoutineB into RoutineC: e.g:
subroutine RoutineA
...
call RoutineB(... , RoutineC)
...
ensubroutine
Is there a way to do this without passing the reference?
I have Composer XE 2011 and use windows, linux, and mac versions. Thanks guys!
Nate
0 Kudos
4 Replies
jimdempseyatthecove
Honored Contributor III
732 Views
Look in the IVF reference guide under "proceedure pointers".
In routine C (the dll)
add a collection of proceedure pointers (uninitialized (=>NULL))
add an init function that is passed the pointer(s) and copies pointer(s) into appropriate proceedure pointer

Once this is done the dll can use the proceedure pointer for calling the proper function.

Also, in place of default initilaization to =>NULL you could point to a function that gracefull informs the user that the init was not called

Jim Dempsey
0 Kudos
Steven_L_Intel1
Employee
732 Views
I don't think we support the F2008 feature of having a function for default initialization of a procedure pointer.
0 Kudos
nbunderson
Beginner
732 Views
Thank you Jim and Steve! I haven't implemented this yet but it looks like just what I need. Since the initialization will be done right after the dll is loaded and can be initiated by LIB1 then as the programmer of LIB1 (clients will write their own DLL1's)I can put in the appropriate error checking there and unload the dll if the initialization fails preventing further problems.
Nate
0 Kudos
ZlamalJakub
New Contributor III
732 Views
I use DLLEXPORT to export routines from my exe file. Then dll libraries used by this exe file can use these routines (in the same way as exe file uses exported routines from dll). It works well.
0 Kudos
Reply