2013-01-16 635 views
21

我使用Windows API中的'LoadLibrary',当我运行应用程序时,它会抛出一个错误代码126.我读到它可能是由依赖项引起的,我检查了什么是有些应用程序如Dependency Walker错误,但一切都很好。DLL加载库 - 错误代码126

调用LoadLibrary中的应用:

  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(); 
      } 

插件代码:

#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"); 
} 
} 
+0

你在哪个平台上编程?我只是在Google上输入“LoadLibrary failed”,并立即自动完成“LoadLibrary失败,错误代码为126”,给出了类似41.000的结果,包括YouTube视频如何修复它。是不是真的有用的那些链接? –

+0

我跟着一些教程,他们谈论了依赖......关于这个DLL不存在,好吧,我有4个小时的搜索,我不能用任何教程修复它,我已经检查了依赖关系.... :S – Spamdark

+1

调用'FreeLibrary(dll_mod);'if'(dll_mod == NULL)'' – borisbn

回答

46

的Windows DLL错误126可以有很多根源。 我发现调试这个最有用的方法是:

  1. 使用的Dependency Walker以寻找任何明显的问题(你 已经完成)
  2. 使用Sysinternals的工具进程监视器从微软http://technet.microsoft.com/en-us/sysinternals/bb896645追查所有文件访问,而你的DLL正在尝试加载。有了这个实用程序,你会看到这个DLL试图引入的所有东西,通常可以从那里确定问题。
+0

听起来不错,我试试吧 – Spamdark

+2

就是这样!有了这个工具,我发现了这个错误,非常感谢! – Spamdark

+0

@ Spamdark:我们为你感到高兴。请发布什么是 –

1

这个错误可能会发生,因为某些MFC库(例如.mfc120.dll)从该DLL依赖是缺少在Windows/system32。