Friday, December 11, 2020

When LoadLibrary fails with ERROR_MOD_NOT_FOUND for an existent library

Today I wrote a small DLL in C++ and tried to use it on another machine. Strangely, the host process didn't load it, nor could a manual LoadLibraryW call in SprintDLL. I did have the path right and Process Monitor confirmed that the file was being opened (by both the host process and CSRSS for some reason), but LoadLibraryW returned null with ERROR_MOD_NOT_FOUND. To get more details, I used the GFlags utility to enable "show loader snaps" for SprintDLL, attached WinDbg to the SprintDLL process, and tried the load call again. Output in the debugger showed that loading my DLL also triggered the loading of vcruntime140d.dll, which did not exist on my other machine. So a module was not being found - it was "just" a dependency instead of my library itself. Using a Release build, which links against the release version of that redistributable which is actually present on the other machine, fixed the problem.

No comments:

Post a Comment