DLL 中的实例化类在 QT 的 LoadLibrary 中引发 127 错误
Instantiate class in DLL throws a 127 error in LoadLibrary in QT
>我正在尝试使用 LoadLibrary 在 qt 中加载 DLL(仅用于测试而不是 QLibrary),dll 是在 eclipse CDT 中编译的,但奇怪的是,当我尝试实例化 Dll 内任何函数中的任何类时,加载库失败并出现错误 127(使用 GetLastError),但如果我没有实例化任何东西,加载库就成功了, 为什么会这样?我的代码是下一个,标题和你的实现:
页眉:
#ifndef DESKTOPWINUTILS_H_
#define DESKTOPWINUTILS_H_
#ifdef __dll__
#define DESKTOPUTILSEXP __declspec(dllexport)
#else
#define DESKTOPUTILSEXP __declspec(dllimport)
#endif // __dll__
#include <iostream>
#include <stdio.h>
#include <string.h>
#include "ximage.h"
#include "IDesktopUtils.h"
class DesktopUtils:public IDesktopUtils{
public:
DesktopUtils();
~DesktopUtils(void);
char* sayHello();
};
extern "C" DESKTOPUTILSEXP bool create(IDesktopUtils**);
#endif /* DESKTOPWINUTILS_H_ */
实现:
#define __dll__
#include "DesktopUtils.h"
DesktopUtils::DesktopUtils(){
sayHello();
}
char* DesktopUtils::sayHello(){
return (char *)("I say Hello");
}
bool create(IDesktopUtils** desktoputils){
//DesktopUtils *desktoputils = new DesktopUtils();
if(!desktoputils)
return false;
*desktoputils =(IDesktopUtils*) new DesktopUtils; //if comment this the load is successful
return true;
}
在qt项目中,我使用它来加载DLL,仅用于知道是否加载,我什至没有使用GetProcAddress:
typedef char*(*createInst)(void);
HINSTANCE dll;
dll = LoadLibrary(TEXT("libDesktopWinUtils.dll"));
if(dll){
message.setText("library loaded");
message.exec();
}else{
char error[10];
itoa(GetLastError(),error,10);
message.setText(error);
message.exec();
}
似乎您注释掉的代码创建了系统无法解析的依赖项。 例如,使用 new
的代码要求 new 的系统实现已加载到进程中,或者可以找到并加载提供它的 DLL。 如果不能,则加载库调用将失败。
找出缺少的依赖项的方法:
- 在记录所有已加载和卸载模块的调试器中运行程序。
- 使用依赖步行者程序。 (现在很少见,因为 SxS 使该过程复杂化。
- 在程序运行时运行类似进程监视器的内容。 这将准确显示正在搜索的 DLL 以及搜索的位置。
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- C++单元测试项目 LoadLibrary 失败,出现"序号未找到"错误
- LoadLibrary失败带有错误4250:此操作仅在应用程序容器的上下文中有效
- winapi函数loadLibrary()导致函数在执行错误期间失败
- LOADLIBRARY(..)失败错误代码1627:error_function_failed
- 带有绝对路径的LoadLibrary返回不正确的HMODULE,没有任何错误
- 不满意的链接错误在iOS但不是Android上,loadLibrary总是成功的
- DLL 中的实例化类在 QT 的 LoadLibrary 中引发 127 错误
- LoadLibrary失败,错误代码为14001
- 如何删除LoadLibrary()函数中不兼容变量类型的错误