DLL加载库 - 错误代码126(DLL Load Library - Error Code 126

2019-07-18 07:35发布

我使用从Windows API的“调用LoadLibrary”,当我运行的应用程序时,它抛出我的错误代码126,我读了它可能的依赖造成的,我检查有什么错像Dependency Walker中某些应用程序,但一切被罚款。

调用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");
}
}

Answer 1:

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

  1. 使用的Dependency Walker以寻找任何明显的问题(你已经这样做)
  2. 使用Sysinternals的工具进程监视器http://technet.microsoft.com/en-us/sysinternals/bb896645从微软来跟踪所有的文件访问,而你的DLL试图加载。 有了这个工具,你会看到该DLL试图拉,通常这个问题可以从那里来决定一切。


Answer 2:

可能发生这种错误,因为一些MFC库(如mfc120.dll),从该DLL的依赖在Windows / System32文件夹丢失。



文章来源: DLL Load Library - Error Code 126