Reputation: 1435
I found the following code for loading libraries in Qt but I do not fully understand how it works. Could someone explain to me from: 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;
Upvotes: 1
Views: 2501
Reputation: 36
so or dll has function and we want to use it, so how we can call it
int add(int in_iParam1, int in_iParam2)
define function type
typedef int (*MyPrototype)(int, int);
looking for function 'add' in so file
MyPrototype myFunction = (MyPrototype)library.resolve("add");
Call function 'add' with parameters 'a' and 'b' and get result to 'r1'
r1 = myFunction(a,b);
Upvotes: 2