10

I know that this was already discussed somewhere in here but I have not find question that I wanted, namely: I have a C++ application that uses a lot (more than 20 -30 ) DLLs. I have defined in my Visual Studio 2010 project that the .exe will be copied to the ProjectDir (so that everything is neat and clear) but when the .exe is standing in the ProjectDir alone it cannot access the DLLs stored in the bin..// whatever folder along with many other files.

Can I somehow point the DLL folder so that the application will know where they are located ? (and the <myapp>.exe.local folder thing does not work in my Windows 7)

Patryk
  • 22,602
  • 44
  • 128
  • 244
  • possible duplicate of [How can I make a separate folder for my application's DLLs?](http://stackoverflow.com/questions/5139617/how-can-i-make-a-separate-folder-for-my-applications-dlls) – Emond Apr 23 '11 at 18:19
  • 2
    DLLs should be in the same directory as the EXE. That's where Windows looks first. Any other scheme starts with -1000 points. – Hans Passant Apr 23 '11 at 18:21
  • 2
    @Hans Passant: What do you mean by "Any other scheme starts with -1000 points." ? – Patryk Apr 23 '11 at 18:25
  • There are a thousand points worth of good reasons not to do this. – Hans Passant Apr 23 '11 at 18:29
  • 2
    @Hans: Could you mention the reasons? Would like to know for knowledge sake. – Nav Jan 21 '13 at 03:29
  • You can use a [Private Assembly Manifest to put dlls in a subdirectory](http://stackoverflow.com/a/36644602/321013). – Martin Ba Apr 15 '16 at 20:32

2 Answers2

4

first of all there is no need to copy your exe file to your project dir, whereever your .exe file is created when you are debuging your project the running dir would be your project dir. and after that when you are trying to import the dll if you look for it relatively windows first search for that dll in your running dir then then it checks if it can find the dll in the whatever directory defined system PATH variable, but if you check for a absolute address there will be no looking.

so the first trick is to set all your dll pathes abslote so that there will be no searching and dll are imported easily but there will be a lot of problems if you want to move your application to another computer (eg HINSTANCE hDLL = LoadLibrary(L"C:\\mydll.DLL");) . second you can give your dll pathes relative to the running dir (not the application path, these 2 may differ) and you can also specify directory for that (eg. HINSTANCE hDLL LoadLibrary("..\\dlls\\mydll.dll")

Ali1S232
  • 3,373
  • 2
  • 27
  • 46
1

You may set the PATH variable. Here you can find where windows looks for dll: http://msdn.microsoft.com/en-us/library/ms682586%28v=vs.85%29.aspx and here how to set the path in windows 7: http://geekswithblogs.net/renso/archive/2009/10/21/how-to-set-the-windows-path-in-windows-7.aspx

Simone-Cu
  • 1,109
  • 8
  • 21
  • yeah, I know that this is a possibility I forgot to mention about that but I would like to give this project to somebody, then what ? – Patryk Apr 23 '11 at 18:23
  • Ok, I haven't tried, but this solution seems good. http://www.codeguru.com/Cpp/W-P/dll/article.php/c99 – Simone-Cu Apr 23 '11 at 18:26
  • user675100 - If you're going to give the project to somebody, it looks like you'll be collecting up all those DLLs and putting them in his windows/system32, no? – Pete Wilson Apr 23 '11 at 18:27
  • Especially the part of using registry – Simone-Cu Apr 23 '11 at 18:27