6
votes

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

3
Turn on loader snaps. That will print information to the debugger explaining why the DLL failed to load.Raymond Chen
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.Remy Lebeau
@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?JosephA
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!JosephA

3 Answers

4
votes

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.

2
votes

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
0
votes

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