DLL 加载库 - 错误代码 126

新手上路,请多包涵

我正在使用 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");
}
}

原文由 Spamdark 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.6k
2 个回答

Windows dll 错误 126 可能有许多根本原因。我发现调试这个的最有用的方法是:

  1. 使用依赖遍历器查找任何明显的问题(您已经完成了)
  2. 使用 Microsoft 的 sysinternals 实用程序进程监视器 https://learn.microsoft.com/en-us/sysinternals/downloads/procmon 在您的 dll 尝试加载时跟踪所有文件访问。使用此实用程序,您将看到该 dll 试图引入的所有内容,并且通常可以从那里确定问题。

原文由 DanS 发布,翻译遵循 CC BY-SA 4.0 许可协议

// PKG Fix - index.js

const isPkg = typeof process.pkg !== 'undefined';
const c_dir = isPkg ? path.dirname(process.execPath) : __dirname;

let soname;
if (os.platform() == 'win32') {
    // Update path to load dependent dlls
    let currentPath = process.env.Path;
    let dllDirectory = path.resolve(path.join(c_dir, "win-x86_64"));
    process.env.Path = dllDirectory + path.delimiter + currentPath;
    soname = path.join(c_dir, "win-x86_64", "libvosk.dll");
} else if (os.platform() == 'darwin') {
    soname = path.join(c_dir, "lib", "osx-universal", "libvosk.dylib");
} else {
    soname = path.join(c_dir, "lib", "linux-x86_64", "libvosk.so");
}

原文由 Ruslan 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题