我想使用从这里下载的MediaInfo.dll v0.7.94
1:https://mediaarea.net/bg/MediaInfo/Download/Windows。我的问题是如何使用Qt框架在这个.dll中调用一些函数。
#include <QCoreApplication>
#include <QLibrary>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
if (QLibrary::isLibrary("MediaInfo.dll")) { // C:/MediaInfo.dll
QLibrary lib("MediaInfo.dll");
lib.load();
if (!lib.isLoaded()) {
qDebug() << lib.errorString();
}
if (lib.isLoaded()) {
qDebug() << "success";
}
}
return a.exec();
}发布于 2017-04-12 12:59:32
在QLibrary文档中有一个很好的例子。基本上,你必须知道函数的名称(符号)和它的原型。
#include <QCoreApplication>
#include <QLibrary>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
if (QLibrary::isLibrary("MediaInfo.dll")) { // C:/MediaInfo.dll
QLibrary lib("MediaInfo.dll");
lib.load();
if (!lib.isLoaded()) {
qDebug() << lib.errorString();
}
if (lib.isLoaded()) {
qDebug() << "success";
// Resolves symbol to
// void the_function_name()
typedef void (*FunctionPrototype)();
auto function1 = (FunctionPrototype)lib.resolve("the_function_name");
// Resolves symbol to
// int another_function_name(int, const char*)
typedef int (*AnotherPrototypeExample)(int, const char*);
auto function2 = (AnotherPrototypeExample)lib.resolve("another_function_name");
// if null means the symbol was not loaded
if (function1) function1();
if (function2) int result = function2(0, "hello world!");
}
}
return a.exec();
}发布于 2017-04-12 12:57:33
您需要声明一个函数原型,并获得一个指向DLL中函数的指针。
QLibrary myLib("mylib");
typedef void (*MyPrototype)();
MyPrototype myFunction = (MyPrototype) myLib.resolve("mysymbol");
if (myFunction)
myFunction();请参阅有关QLibrary的更多信息。
发布于 2017-04-13 08:36:44
当存在C/C++绑定时,为什么要使用QLibrary?
有点隐藏,但所有内容都包含在您在问题中提供的链接中的DLL zip包中。
Jér me,MediaInfo的开发者
https://stackoverflow.com/questions/43369694
复制相似问题