让我们考虑Qt-Documentation中的这段代码:
QLibrary myLib("mylib");
typedef void (*MyPrototype)();
MyPrototype myFunction = (MyPrototype) myLib.resolve("mysymbol");
if (myFunction)
myFunction();这会将符号加载到内存中并解析符号"mysymbol",因此我可以使用"myFunction“。我让它一直工作到现在。我也可以调用myFunction(arg_1)。
但是当我调用myFunction(arg_1,arg_2)时,我得到一个“函数的参数太多”的-error。那么,是否真的只有1个参数才能调用myFunction,还是我遗漏了什么?
发布于 2015-02-11 02:44:24
让我重写Mat的评论。我花了几个小时才找到我的问题。
假设dll:
extern "C" __declspec(dllexport) void function1()
{
//code
}
extern "C" __declspec(dllexport) int function2(int arg1)
{
//code
}
extern "C" __declspec(dllexport) char function3(int arg1, int arg2, int arg3)
{
//code
}实现应该是这样的:
typedef void (*_function1)();
typedef int (*_function2)(int);
typedef char (*_function3)(int, int, int);
QLibrary myLib("mylib");
_function1 function1 = (_function1) myLib.resolve("function1");
_function2 function2 = (_function1) myLib.resolve("function2");
_function3 function3 = (_function1) myLib.resolve("function3");
if (function1 && function2 && function3)
{
//implement them
function1();
int test = function2(123);
char test1 = function3(1, 2, 3);
}https://stackoverflow.com/questions/8559712
复制相似问题