Search code examples
c++winapiloadlibrary

LoadLibrary Error 126 dependent on user rights


I have a strange issue, where my application that runs at my place doesn't work somewhere at customers place. In my application I try to load another dll with LoadLibrary() from within the same folder. If the application is run as normal user a 126 error is returned. If the same application is started with Admin rights the dll is loaded correctly.

It's hard to diagnose because I cannot reproduce the error at my machine. Any ideas?


EDIT

OK, it was a dependency: the dll was a Debug-Build and the MSVCP120D.dll and MSVCR120D.dll could not be found. I could tell this by a Process Monitor-Log.

BUT: I have a log as normal user and a log as Admin and in both cases the dependencies cannot be found. Why does LoadLibrary work in case of Admin-rights??


Solution

  • That is ERROR_MOD_NOT_FOUND, which is pretty self-explanatory. Either the DLL you are loading, or one of its dependencies, cannot be found. Perhaps you failed to install the necessary dependencies, e.g. the MSVC runtime. Or perhaps it is something else.

    You'll need to do some debugging and investigation. I would start by profiling the DLL load using Dependency Walker.