DLL加载库 - 错误代码126

Spa*_*ark 30 c++ dll plugins loadlibrary

我正在使用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();
            }
Run Code Online (Sandbox Code Playgroud)

插件代码:

#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");
}
}
Run Code Online (Sandbox Code Playgroud)

小智 65

Windows DLL错误126可能有很多根本原因.我发现调试它的最有用的方法是:

  1. 使用依赖性walker查找任何明显的问题(您已经完成了)
  2. 使用Microsoft 的sysinternals实用程序Process Monitor http://technet.microsoft.com/en-us/sysinternals/bb896645在您的dll尝试加载时跟踪所有文件访问.使用此实用程序,您将看到该dll试图引入的所有内容,通常可以从那里确定问题.

  • 不幸的是,依赖步行者通常无法显示缺少的依赖关系,并且经常显示误报.几年前它似乎更可靠 - 也许它没有很好地跟上最近的操作系统. (9认同)
  • 我怀疑 Process Monitor 会显示任何内容,但是当我查看正在加载的 dll 周围的行时,我看到 MSVCP140D.dll 给出了 NAME NOT FOUND 的结果。原来无法加载我的 dll 的机器没有 MSVCP140.dll 的“D”版本。当我构建要发布的 dll 时,一切正常! (5认同)
  • 而已!有了这个实用程序,我发现了错误,非常感谢! (3认同)
  • 在我的情况下,LoadLibaryA(somedll.dll)返回126。somedll.dll在那里,但是它需要someOtherDll.dll,该文件未安装。ProcessMonitor帮助找到了这个问题。 (3认同)

Shi*_*yal 7

当您尝试加载 DLL 而这又需要另一个无法找到的 DLL 时,也会发生这种情况。