Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

c++ - DLL Load Library - Error Code 126

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:
" << file_full.toStdString() << "
" << "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.
You can register your radio and play it later, also we have a gallery of radios that you can check.
This 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");
}
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Windows dll error 126 can have many root causes. The most useful methods I have found to debug this are:

  1. Use dependency walker to look for any obvious problems (which you have already done)
  2. Use the sysinternals utility Process Monitor http://technet.microsoft.com/en-us/sysinternals/bb896645 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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...