Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DLL dependency question / SetDLLDirectory

I have the following situation and can't come up with any good solution.

I have a C++ application (app.exe) installed in C:\ProgFiles\MyApp. It needs a bunch of DLLs, which I install in C:\ProgFiles\MyApp\bin. I'd like to put them in a subfolder because there are so many of them.

Now when I start app.exe, something needs to let Windows know where the required DLLs are. In the past I was using the PATH environment variable for this, but I can't do this anymore because I will create another application with a separate installer, which uses many of the DLLs that have the same name.

I was thinking of calling SetDLLDirectory at the beginning of the app - but I forgot that because required DLLs are missing, it fails before getting there.

Any suggestions?

like image 619
Warpin Avatar asked Feb 24 '26 08:02

Warpin


1 Answers

See this article from Microsoft which discusses the DLL search path and related issues.

In particular, notice that if you do not put them in your app’s directory the current directory takes precedence, which is a security hole.

One solution would be to use LoadLibrary (with a fully-qualified path), then GetProcAddress. That would be kind of painful.

No normal user is going to go digging around in C:\Program Files\YourApp and that is where you should put them unless you have a good reason not to.

like image 190
Nate Avatar answered Feb 26 '26 22:02

Nate



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!