DLL Load Library - Error Code 126
Windows dll error 126 can have many root causes.
The most useful methods I have found to debug this are:
- Use dependency walker to look for any obvious problems (which you
have already done) - Use the sysinternals utility Process Monitor https://learn.microsoft.com/en-us/sysinternals/downloads/procmon from Microsoft to trace all file access while your dll is trying to load. With this utility, you will see everything that that dll is trying to pull in and usually the problem can be determined from there.
C++ - LoadLibrary returns 126 error for self-made DLL
LoadLibrary((LPCWSTR)filename.c_str());
This is a common error, trying to hide compiler error by using (LPCWSTR)
cast. The cast is meaningless here. You mignt as well try to cast from integer to string.
Use the ANSI version LoadLibraryA
for ANSI parameter:
HINSTANCE hGetProcIDDLL = LoadLibraryA(filename.c_str());
Or use wide string functions std::wstring
LoadLibrary fails to load dll with error code 126, when building in Visual Studio
I figured it out.
By default the cl command uses the multibyte character set. While new projects set up in Visual Studio are configured for unicode.
LoadLibrary Error 126 dependent on user rights
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.
LoadLibrary returns 126 when loading a dll in runtime
I already found the root cause now. I forgot to tell that I'm attaching the dll in my application process while doing the debugging.
The application is requiring that the Soft.FXX.dll
should be in the same directory with it. I really thought that feeding the whole dll path to LoadLibrary
function is enough.
Related Topics
How to Make an Expandable/Collapsable Section Widget in Qt
Run an Application in Gdb Until an Exception Occurs
How to Get Current Timestamp in Milliseconds Since 1970 Just the Way Java Gets
How Does the Range-Based for Work for Plain Arrays
What Is the Simplest Way to Convert Array to Vector
Common Array Length MACro for C
Qgraphicsview Zooming in and Out Under Mouse Position Using Mouse Wheel
How to Get the Class Name from a C++ Object
When Should I Use C++14 Automatic Return Type Deduction
Variable Declarations in Header Files - Static or Not
How to Declare a Vector of Atomic in C++
Unordered_Map Hash Function C++
Why Are Redundant Scope Qualifications Supported by the Compiler, and Is It Legal