PDA

View Full Version : QLibrary, reload DLL



nomprenom
22nd July 2012, 15:59
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 :confused:
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;
}


2) the main.cpp

#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;
}


myFunction= 5
myFunction= 5
myFunction= 5
myFunction= 5
=> Windows display a crash assistant

Thanks you.

nomprenom
22nd July 2012, 18:53
I found it comes from the "__stdcall" keyword.
I forget to add it also in the main program


typedef __stdcall int (*MyPrototype)(int a, int b);