Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Important Update: Community Platform Migration​. Learn more​>
29657 Discussions

Loading DLL routines from a string variable

Anonymous51
Beginner
1,173 Views
I would like to be able to dynamically load DLL files, with something like:

character*255: DLL_name_and_path
character*255: DLL_routine_name

and be able to the following: (approximate, from Google searches)

ierr = LoadLibrary(DLL_name_and_path)
iHandle = GetProcAdd(DLLL_routine_name)

How do I then call the routne?

It would be along the lines of

CALL iHandle(Param1, Param2, Param3)

I can find Windows-centric help on the LoadLibrary/GetProcAddr parts, but the final part - how to use within Fortran - has beaten me.
0 Kudos
1 Reply
drgfthomas
Beginner
1,173 Views

Omit the two character statements.

Use the kernel32 module, Cray pointers, C strings, and supply an interface:

eg,

use kernel32 !(or whatever has the LoadLibrary, GetProcAddress, FreeLibraryAPI's)

implicit none

interface
subroutine locMyDLLSub(...)

...
end subroutine locMyDLLSub
end interface


integer(4) p
pointer (r,locMyDLLSub)

logical(4) :: res = .false.

p = LoadLibrary('MyDLL.dll'C) !put the DLL in the same folder asits client
r = GetProcAddress(p,'MyDLLSub'C)

call locMyDLLSub(...)

...

res = FreeLibrary(p)

...

0 Kudos
Reply