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

use dll in different folder

Christer_O_
Beginner
1,309 Views

Hello,

 

I have a question about calling dll files.

In my project I have created an exe-file developed in Fortran and this program uses functions from  dll-files in different subfolders. I have tested to have all dll-files in the same folder as my exe-file and everything works w/o any problems so this is not the problem.

But I want to use the dlls in the subfolders. (I do not want to ask my users to copy a lot of dlls from subfolders if I can avoid it)

 

Example what I want:

  1. The dll sub.dll with visible function calc is placed in subfolder c:user\program\calc
  2. The program myProg.exe in folder c:user\program  needs to use function calc from sub.dll in folder c:user\program\calc

Is there a trick to do this in Fortran?   (in other language it has worked with load and unload commands)

Very thankful if anyone can help me!

 

 

 

 

 

 

 

0 Kudos
3 Replies
mecej4
Honored Contributor III
1,309 Views

The most straightforward way is to modify PATH so that every one of the required DLLs may be found in one of the paths whose concatenation in some order gives %PATH%. This changing of PATH can be made within a batch file or surrounded by SETLOCAL ...ENDLOCAL,  if you do not wish to make permanent changes to PATH.

0 Kudos
Paul_Curtis
Valued Contributor I
1,309 Views

Assuming you load your .dll by using the WinAPI LoadLibrary(dllname), you can prepend path information onto dllname, so that the dll is always sought in a directory which has a defined relationship to where the exe file is located. My programs fetch the startup command line to determine where the exe was invoked from, and parse the original command path to make relative paths to other resources in a predetermined multi-directory structure.  This mechanism allows you to have multiple versions of your program and its dll resources, in different root directories.

0 Kudos
Christer_O_
Beginner
1,309 Views

mecej_4  and Paul Curtis,

 

Many thanks for your good advises, it was perfect. I was so into Fortran I forgot I can still use loadLibray that I have used so many times in C++.

Christer

0 Kudos
Reply