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

Identify DLL at runtime

DavidWhite
Valued Contributor II
522 Views
I want to use the same code in two different applications, both delivered as a DLL called from Excel. This common code includes the same entry points which are exported in the DLL's and appear identical to Excel (normally users would only have one or other app installed).

At runtime, can I identify the DLL in use without passing the name as an argument to the DLL?

I tried GET_COMMAND_ARGUMENT, but this returns the exe name (Excel).

Thanks for any ideas,

David
0 Kudos
1 Reply
IanH
Honored Contributor III
522 Views
The Windows API's that you could use are GetModuleHandleEx (using the GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS flag and passing LOC(some_proc_in_your_dll)) and GetModuleFilename.

But I think you're going to have to write your own interface to the first one - I couldn't find the bits in kernel32.f90.

A simpler alternative might be to have /fpp plus some sort of /Dsymbol=value on the compile command line, where the value is application specific and ends up in a parameter that you can test in code. This is robust to the user renaming the DLL.

ifort /fpp /DFLAVOUR_STRING='xxx'

CHARACTER(*), PARAMETER :: flavour = FLAVOUR_STRING
IF (flavour == 'xxx') CALL SpecialStuff(...)
0 Kudos
Reply