Patryk
Patryk

Reputation: 24092

How can I run an .exe with DLLs in separate directory?

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)

Upvotes: 11

Views: 23956

Answers (2)

Ali1S232
Ali1S232

Reputation: 3411

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")

Upvotes: 4

Simone-Cu
Simone-Cu

Reputation: 1129

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

Upvotes: 1

Related Questions