Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 857
Patryk Avatar asked Apr 23 '11 18:04

Patryk


1 Answers

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

like image 118
Ali1S232 Avatar answered Oct 06 '22 15:10

Ali1S232