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

Changing external dll directory

onkelhotte
New Contributor II
1,074 Views
Hi there,
I have only a minor problem. My program needs a third party dll to be executed correctly. We have in our department a structure for our directories:
Project
Projectin
Projectdata
Projectdll
Projectdocumentation
Projectsource
Now I have to put this dll in the Projectdll directory and the exe is located in the Proectin directory.
How can I tell the program to load this dll from ..dllfile.dll and not from .file.dll? I havent found an option in the project settings and I dont want to set an enviroment variable just for this.
Thanks in advance,
Markus
0 Kudos
8 Replies
Jugoslav_Dujic
Valued Contributor II
1,074 Views
Not that I know of. You can do it with dynamic binding (LoadLibrary/GetProcAddress) but that's an overkill.

Btw, I don't think such project organization is good. We use a similar one, except that both .dll's and .exe's go to in directory. Now, if you can persuade your project managers... :-).
0 Kudos
Les_Neilson
Valued Contributor II
1,074 Views

Hi

From another post Steve Lionel gives the following information :

"Windows looks for DLLs using the following order:

Current directory
Directory containing the executable
PATH
Windows
WindowsSystem"

Is it possible to add Project/dll to the PATH ?

Like Jugoslav we also put dlls in the bin directory along with the exe files.

Les

0 Kudos
onkelhotte
New Contributor II
1,074 Views

Would it be my decision, I would put the dll in the executable directory as well. But I have to use this structure :-( Company standard.

Adding the directory into PATH came to my mind too, but it wont work. When I use GetEnvQQ Iget the whole PATH, I append my dll path and useSetEnvQQ to set the new path. GetEnvQQ gets the updated path, but when I type PATH from the command line, its not in there.

Code:

l = GetEnvQQ('path',String)
write (NewString,'(4a)') 'PATH=',trim(String),';',trim(DllDir)
l = SetEnvQQ(NewString)
l = GetEnvQQ('path',string)

Neither does my program run because it wont find the dll. Could that be because the normal userdont have administrative rights in Windows?

Isnt it possible to compile put the dll into the exe while compiling or to do this with an extra tool?

Thanks in advance,
Markus

0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,074 Views
Is there a trailing char(0) in the string returned by GetEnvQQ? Also, you have an extra PATH= in it.

In any case, it won't work -- with static binding (linking with dll.lib), the dll is loaded on the application startup and there's nothing you can do from the code to make it be found.

Whoever made up that "Company standard" should be fired how they meant it to work at all?

See here. It seems that it's doable (didn't try) if you set the .dll directory as the "Startup directory" ("Start in") VS directory or application's shortcut, but that's a workaround -- as far as I know, it's not generally doable if user starts the application by double-clicking it.
0 Kudos
onkelhotte
New Contributor II
1,074 Views

GetEnvQQ does not return a trailing char(0).

LoadLibrary and LoadLibraryEx return both .false. and wont work too. Btw. I cant use loc(string) in the LoadLib syntax because "The type of the actual argument differs from the type of the dummy argument. [LOC]"...

The "PATH=..." is necessary for SetEnvQQ to be executed correctly. Thats the example from CVF help:

USE DFLIB
LOGICAL(4) success
success = SETENVQQ("PATH=c:mydir mp")

Fire the people behind those "company standards"? That would be great :-) People in higher positions dont see a problem to move one file in another directory.This crap costs me more time than anything else in my project (Not really, but it su*&s!) And all becauseit looks sooo good when there is only one file in the bin directory...

0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,074 Views
OK, your example with GetEnvQQ/SetEnvQQ does work for me, as well as LoadLibrary... but not together :-).

IOW, SetEnvQQ does work, but subsequent LoadLibrary("dllname.dll"C) doesn't take the new path into account.

What does work is:
i = SetCurrentDirectory("D:...in"//char(0))
i = LoadLibrary("mydll.dll"//char(0))

or

i = LoadLibrary("D:...inmydll.dll"//char(0))
Now, are you sure you want to do dynamic binding and GetProcAddress, pointer declaring, etc. for potentially zillion dll routines, introducing inportability as well? Isn't it worth a campaign for policy change?
0 Kudos
onkelhotte
New Contributor II
1,074 Views

SetCurrentDirectory wont work too. After that (or after ChangeDirQQ to dll) GetCurrentDirectory returns false. Something differentmust be wrong.

But I dont need that any more, we have to put the dll directory in our PATH permanently now. Great solution ;-)

Thanks again Jugoslav for your help, you are always a good source for advice.

Have a nice weekende!

Markus

0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,074 Views
It's tangential to the problem, but note that "" is an escape-character in C-strings, so you need either:

"D:FooBar"//char(0)

or

"D:FooBar"C
As I said, it works for me.

OK, never mind. I'm glad that the problem is, um, solved. Have a nice weekend too.
0 Kudos
Reply