LoadLibraryExW() fails, last error is ERROR_MOD_NOT_FOUND, but no missing dependencies?
Asked Answered
T

4

8

A customer is using our dll which is creating a child process which uses an open source library, which ultimately fails because of a call to LoadLibraryExW(), the last error returned is ERROR_MOD_NOT_FOUND. This occurs on WinXP 32-bit, but not on other machines. But we know the correct set of dependencies is installed and even in the same directory.

So we thought naturally, to use Dependency Walker to look for what dependency is missing on that particular machine. Unfortunately it doesn't show any missing, just some delay-load warnings that aren't direct dependencies of the library. In my experience using depends.exe has always revealed what the missing dependency is.

So at this point I've pulled my hair out trying to understand why I'm getting ERROR_MOD_NOT_FOUND if all of the library's dependencies are there? The only other thing that makes this machine unique is it's very secure because it's used by the government, but if we were having an access/permissions issue I'd expect a different type of error code.

I've built a small Win32 executable that does nothing but call LoadLibraryExW() on the said library, when it's run from the same directory as the library is located, it loads the library without issue, on the customer's problematic machine.

One thing is that our product is an ActiveX plugin which launches a child process, the child process calls into the 3rd party library, the 3rd party library has the problematic LoadLibraryExW() call. So maybe why it's failing is the context it's running (e.g. from the browser)?

Trengganu answered 22/5, 2013 at 20:14 Comment(4)
Turn on loader snaps. That will print information to the debugger explaining why the DLL failed to load.Tenia
And if that does not work (not using a Microsoft debugger, for instance), try SysInternals Process Monitor to see what files the offending process is actually looking for.Dosh
@Raymond Chen, that looks to be a very useful path. On my development machine I see the loader snaps with all the details in the Command Window, for some reason on the XP machine, once I've installed WinDbg, turning on loader snaps doesn't seem to generate any output to the WinDbg Command Window?...could I maybe be missing some sort of setting on a fresh install of WinDbg?Trengganu
This is interesting, I only get the loader snaps if I open an executable on the XP machine (e.g. notepad.exe), but if I attach to the process on XP I get the loader snaps. However on my Windows 7 machine, I get the snaps either way!Trengganu
G
6

The best way is to use loader snaps. Basically you use gflags.exe (which is included with windbg) to enable loader snaps; then, run the process with the debugger attached. Loader snaps will enable the loader to print out dbg messages of the process and it will print the failures.

gflags.exe -i yourcode.exe +sls
windbg yourcode.exe
Gahl answered 20/6, 2019 at 0:25 Comment(0)
A
4

Use the Profiling option of the Dependency Walker on your application. Possibly the library is trying to resolve some APIs dynamically (using LoadLibrary/GetProcAddress) and this won't show up in the static dependencies.

Aluminous answered 23/5, 2013 at 11:9 Comment(0)
O
1

Your dependencies might be present on the system but they could be in a folder that is not part of the search order during LoadLibraryExW(). A SetDllDirectory() or AddDllDirectory() call would ensure that the folder containing the dependencies is searched during the LoadLibraryExW() call

Obstinacy answered 31/5, 2020 at 12:38 Comment(0)
M
-1

The problem for me was I opened an app compiled in RELEASE mode that tried to load a resource DLL compiled in DEBUG mode.

Mani answered 26/6, 2024 at 0:22 Comment(5)
That sounds incredibly unlikely as the root cause.Stutman
Yeah I know. VC 6.0 (don't laugh - its still way better/quicker than the current IDE for development IMO.) BTW - if you want to down vote it because of your untested opinion, do everyone a favour and test it first.Mani
I cannot verify this because I do not know how to compile a resource-only DLL in DEBUG configuration (or what that is even supposed to mean).Stutman
That doesn't make sense. Neither rc.exe nor mc.exe support command line options that specify a particular configuration. It's still a mystery to anyone what "compiled in DEBUG mode" is supposed to mean. You need to figure out what the real issue is and update the answer accordingly.Stutman
IInspectable: I retried compiling in both release and debug modes. It does not make a difference. Except, when I had the problem before, when I recompiled in release mode, the DLL could be loaded. So, I do not have an explanation at this point. Points to you for keeping at it with me. Thanks! BTW "Release Mode" = "Win32 Release" in my IDE. Don't understand how that can be confusing.Mani

© 2022 - 2025 — McMap. All rights reserved.