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!
Question Regarding DLL Bundling
Moderators: DllAdmin, DLLADMIN ONLY
-
- Posts: 4
- Joined: 23 Apr 2025, 04:49
Re: Question Regarding DLL Bundling
Does anyone have the answer?
Re: Question Regarding DLL Bundling
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
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
-
- Posts: 4
- Joined: 23 Apr 2025, 04:49
Re: Question Regarding DLL Bundling
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.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!
-
- Posts: 4
- Joined: 23 Apr 2025, 04:49
Re: Question Regarding DLL Bundling
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.