Hello, i'm using QLibrary for loading a DLL on windows.
I want to unload then reload it after an upate for exemple without leaving the main program.
It works fine ! but only 4-5 times max before crashing
I wrote a simple program to illustrate the problem :
1) the DLL, dll.cpp
extern "C" __declspec( dllexport ) int __stdcall fonction( int a, int b )
{
return a+b;
}
extern "C" __declspec( dllexport ) int __stdcall fonction( int a, int b )
{
return a+b;
}
To copy to clipboard, switch view to plain text mode
2) the main.cpp
#include <QLibrary>
#include <qDebug>
int main(int argc, char *argv[])
{
typedef int (*MyPrototype)(int a, int b);
for( int i=0; i<4; i++ ) {
MyPrototype myFunction = (MyPrototype) myLib.resolve("fonction");
if (myFunction)
qDebug() << "myFunction=" << myFunction(2,3);
else
qDebug() << "erreur.";
myLib.unload();
}
return 0;
}
#include <QLibrary>
#include <qDebug>
int main(int argc, char *argv[])
{
QLibrary myLib("dll");
typedef int (*MyPrototype)(int a, int b);
for( int i=0; i<4; i++ ) {
MyPrototype myFunction = (MyPrototype) myLib.resolve("fonction");
if (myFunction)
qDebug() << "myFunction=" << myFunction(2,3);
else
qDebug() << "erreur.";
myLib.unload();
}
return 0;
}
To copy to clipboard, switch view to plain text mode
myFunction= 5
myFunction= 5
myFunction= 5
myFunction= 5
=> Windows display a crash assistant
myFunction= 5
myFunction= 5
myFunction= 5
myFunction= 5
=> Windows display a crash assistant
To copy to clipboard, switch view to plain text mode
Thanks you.
Bookmarks