我找到了以下用于在Qt中加载库的代码,但我不完全理解它是如何工作的。有人能从typedef int (*MyPrototype)(int, int);给我解释一下吗?
int r1 = 0;
QLibrary library("mathlib.so");
if (!library.load())
out << library.errorString() << endl;
if (library.load())
out << "library loaded" << endl;
typedef int (*MyPrototype)(int, int);
MyPrototype myFunction = (MyPrototype)library.resolve("add");
if (myFunction)
r1 = myFunction(a,b);
else
out << library.errorString() << endl;发布于 2017-07-17 00:21:54
或者dll有函数,我们想要使用它,那么我们如何调用它呢
int add(int in_iParam1, int in_iParam2)定义函数类型
typedef int (*MyPrototype)(int, int);在so文件中查找函数'add‘
MyPrototype myFunction = (MyPrototype)library.resolve("add");使用参数'a‘和'b’调用函数'add‘,并将结果返回给'r1’
r1 = myFunction(a,b);https://stackoverflow.com/questions/45119131
复制相似问题