Page 1 of 1

Question Regarding DLL Bundling

Posted: 23 Apr 2025, 04:52
by ulyssesmiller
Hello everyone!

I have a quick inquiry about DLL file loading. I have an executable file, program.exe, that attempts to load the DLL libpq.dll from a specified directory. Is it possible to arrange it to load libpq.dll from the executable's directory instead?

Essentially, I want my Rust application to prioritize looking for essential DLLs in the executable's location. Here's how my project structure looks:

Copy Project Dir, Program.exe, and libpq.dll (<--). I want Program.exe to use this version rather than the one in the system directory.
Is it possible? Thanks in advance for your assistance!

Re: Question Regarding DLL Bundling

Posted: 29 Apr 2025, 02:46
by ulyssesmiller
Does anyone have the answer?

Re: Question Regarding DLL Bundling

Posted: 27 May 2025, 16:02
by fethiye
Solution: Load libpq.dll from the executable’s directory
On Windows, DLL search order is well-defined. By default, Windows searches in this order (simplified):

The directory where the executable is located

The system directory (e.g., C:\Windows\System32)

The Windows directory

The current working directory

The directories listed in the PATH environment variable

Re: Question Regarding DLL Bundling

Posted: 31 May 2025, 02:20
by ulyssesmiller
ulyssesmiller wrote: 23 Apr 2025, 04:52 Hello everyone!

I have a quick inquiry about DLL file loading. I have an executable file, program.exe, that attempts to load the DLL libpq.dll from a specified directory. Is it possible to arrange it to load libpq.dll from the executable's directory instead?

Essentially, I want my Rust application to prioritize looking for essential DLLs in the executable's location. Here's how my project structure looks:
viewtopic.phpMonkey Mart
Copy Project Dir, Program.exe, and libpq.dll (<--). I want Program.exe to use this version rather than the one in the system directory.
Is it possible? Thanks in advance for your assistance!
Oh, I looked it up, Windows will actually load DLLs from the program's directory first, as long as the DLL is in the same directory as program.exe. If you want to be extra sure or have more control, you can use LoadLibrary with the full path in your code.

Re: Question Regarding DLL Bundling

Posted: 10 Jun 2025, 11:22
by ulyssesmiller
Oh, I looked it up, Windows will actually load DLLs from the program's directory first, as long as the DLL is in the same directory as program.exe. If you want to be extra sure or have more control (Monkey Mart), you can use LoadLibrary with the full path in your code.