DLL Load Library - Error Code 126
151,244
Solution 1
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://docs.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.
Solution 2
This can also happen when you're trying to load a DLL and that in turn needs another DLL which cannot be not found.
Solution 3
This error can happen because some MFC library (eg. mfc120.dll) from which the DLL is dependent is missing in windows/system32 folder.
Author by
Spamdark
Updated on July 09, 2022Comments
-
Spamdark almost 2 years
I'm using the 'LoadLibrary' from the Windows API, when I run the application, it throws me an error code 126. I read that it may be caused by dependencies, I checked what's wrong with some applications like Dependency Walker, but everything was fine.
LoadLibrary in the application:
HMODULE dll_mod = LoadLibrary(L"path_to_dll"); if(dll_mod==NULL){ std::stringstream error; error << "Could not load plugin located at:\n" << file_full.toStdString() << "\n" << "Error Code: " << GetLastError(); FreeLibrary(dll_mod); return error.str(); }
Plugin code:
#include "stdafx.h" #define DLL_EXPORT #define PLUGIN_STREAM __declspec(dllexport) #include <iostream> #include <vector> using std::vector; using std::string; // Init event (After the loading) extern "C"{ PLUGIN_STREAM int onInit(char* argv){ return 0; } PLUGIN_STREAM void pluginInfo(vector<string> & info){ info.push_back("media_event=false"); info.push_back("status_event=false"); info.push_back("send_event=true"); info.push_back("plugin_name='RadioStream'"); info.push_back("description='This plugin was designed for that people that wants to listen to radio music.\nYou can register your radio and play it later, also we have a gallery of radios that you can check.\nThis plugin is original of Volt and it's originally implemented in the application.'"); info.push_back("success:0"); info.push_back("error:1=Could not open data file"); info.push_back("error:2=Could not prepare plugin"); info.push_back("alert:40=Could not connect to that radio"); } }
-
Spamdark over 11 yearsThat's it! With that utility I found the error, thanks so much!
-
Andriy Tylychko over 11 years@Spamdark: we're glad for you. Please post what was the reason
-
Spamdark over 11 yearsIt was a dependency, I don't know why the "dependency walker" didn't detect or didn't throw any error. It's working fine now :)
-
JDiMatteo over 9 yearsUnfortunately often dependency walker fails to show missing dependencies, and also often shows false positives. A few years ago it seemed much more reliable -- perhaps it isn't keeping up with recent operating systems very well.
-
TomEberhard over 8 yearsin my case, LoadLibaryA(somedll.dll) returned with 126. somedll.dll was there, but it needed someOtherDll.dll, which was not installed. ProcessMonitor helped find that issue.
-
Robson about 7 yearsthanks! I would edit the answer to add that in process monitor you can filter the results to show only what you are looking for!
-
Stein Åsmul over 6 yearsNice answer. Adding a link to the Dependency Walker help page with some descriptions of such potential " hidden depencencies" - in particular see items 4 and 5.
-
Pakman over 5 yearsI was dubious Process Monitor would reveal anything, but when I looked at the rows surrounding my dll being loaded I saw MSVCP140D.dll was giving a result of NAME NOT FOUND. Turns out the machine that couldn't load my dll doesn't have the 'D' version of MSVCP140.dll. Everything worked when I built my dll for release!
-
thomachan over 5 yearsI used process monitor, but the event is showing that it is trying to load some dll with japanese name. I am using Qt creator.
D:\thomas\works\qt\2\build-test1-Desktop_Qt_5_11_1_MSVC2017_64bit-Debug\debug\㩄琯潨慭⽳潷歲⽳瑱㈯戯極摬琭獥ㅴ䐭獥瑫灯兟彴張ㄱㅟ䵟噓㉃強㐶楢敄畢⽧敤畢⽧牃䥤挲㈳搮汬.DLL
-
hidefromkgb almost 5 yearsDependency Walker worked like a charm. Thanks for reminding me of its existence!
-
Alexander Samoylov over 4 yearsIn my case I built tesseract.dll from source and could not use it on the same build machine, because the dll load failed with error 126. Dependency Walker showed msvcp140.dll and vcruntime140.dll as missing. Yes, these dlls are installed with Visual C++ Redistributable for Visual Studio 2015 (microsoft.com/en-us/download/confirmation.aspx?id=48145).
-
Eric Duminil over 2 yearsWow, ProcessMonitor is really impressive. It worked like a charm, and I could understand what went wrong with DLL loading, and solve the problem in 2 minutes. I've also noticed that somehow, Adobe needs to check something every 100ms on my computer, even though no Adobe app has been launched. WTF.