Qt-Dll相关问题
|
我只是在学习dll \。我在Qt中尝试过。首先,我发布与dll相关的文件。
第一个dll-专业版文件
TEMPLATE = lib
SOURCES += \\
check.cpp
HEADERS += \\
check.h
这是dll头文件\“ check.h \”
#ifndef CHECK_H
#define CHECK_H
#include <iostream>
extern \"C++\" __declspec(dllexport) std::string check();
#endif // CHECK_H
这是dll-源文件“ check.cpp”
#include <iostream>
#include \"check.h\"
extern \"C++\" __declspec(dllexport) std::string check()
{
return \"dll applied\";
}
我编译了上面的项目文件,并得到了dll。 dll的名称为\“ dll.dll \”
现在是主文件。在这里,我尝试通过dll访问\“ check \”函数。
#include \"check.h\"
#include <iostream>
#include \"MyMessageBox.h\"
#include <QApplication>
#include <QLibrary>
#include <QMessageBox>
typedef std::string (*CheckType) (void);
class MyMessageBox:public QMessageBox
{
public:
MyMessageBox(std::string message,QWidget*parent=0):
QMessageBox(QMessageBox::NoIcon,QString(\"ErrorMessage\"),QString(message.c_str()),QMessageBox::Ok,parent,Qt::Widget)
{
}
};
int main(int argc,char * argv[])
{
QApplication app(argc,argv);
CheckType myCheck;
QLibrary myLib(\"dll\");
myLib.load();
bool ok = myLib.load();
if(ok)
{
MyMessageBox mm(\"Load is done\");
mm.exec();
}
ok = myLib.isLoaded();
if(ok)
{
MyMessageBox mm(\"Loaded\");
mm.exec();
}
myCheck = (CheckType) (myLib.resolve(\"check\"));
if(!myCheck)
{
MyMessageBox m0(\"Resolving isn\'t happened\");
m0.exec();
}
std::string result = myCheck();
MyMessageBox mm(result);
mm.exec();
return app.exec();
}
但是,当我运行上面的应用程序时,得到了“没有解决”。这意味着,函数指针变为NULL。我不知道哪一部分错了。来人帮帮我?
没有找到相关结果
已邀请:
1 个回复
臀博
然后,将示例中的ѭ5替换为
,并确保在任何导出的符号之前都包含上述代码。 然后添加
到dll \的项目文件(当然,仅当以dll形式构建时!)和
到使用dll导出功能的任何项目。它很丑陋,但是很惯用,而且有效。