OverTheOCean
24th October 2012, 12:41
Hi,
l want to load dynamically DLL ( instrument driver) so l can change on the fly which driver to use for my instruments.
The DLL contains a QDialog with a specific class containing all driver's commands. Overall works very well except when l change the DLL, can not open the Qdialog ( .exec() ), it crash.
the driver/ dll are tested individually and works fine.
I suspect something on class allocation below, but can not figure it out.
here is the code below:
- first copy the .dll to a specific name so can use same the driver multiple times in the application.
- then load teh class containing the GPIB commands
- then load the class for the Qdialog ( UI)
short GPIB_Dashboard::Load_Drivers_Vds_1(QString *error_msg)
{
QString drivername;
QString error;
QStringList message;
{
if(My_Vds1_Lib != NULL)
{
My_Vds1_Lib->unload();
delete My_Vds1_Lib;
My_Vds1_Lib = new QLibrary();
}
else
My_Vds1_Lib = new QLibrary();
//reserve DLL copy
drivername = QCoreApplication::applicationDirPath()+"//Driver_Vds1.dll";
if(QFile::exists(drivername))
if(!QFile::remove(drivername))
{
QTextStream(error_msg) << "error: could not image driver Vds1";
return 1;
}
if(!QFile::copy(Vds1.name,drivername ))
{
QTextStream(error_msg) <<"error: could not copy driver Vds1";
return 1;
}
My_Vds1_Lib->setFileName(drivername);
My_Vds1_Lib->load();
DCsource_Vds1_class = (My_DCsource_Prototype) My_Vds1_Lib->resolve("CreateDCSourceClass");
if(!DCsource_Vds1_class){
// DCsource_1_online = 0;
QTextStream(error_msg) <<"Vds1 driver: class unresolved";
return 1;
}
DCsource_Vds1 = DCsource_Vds1_class();
DCsource_Vds1->Instance_name = "Vds1";
DCsource_Vds1->LoadConfig();
DCsource_Vds1->Read_GPIB_config(&message, &error);
My_Dlg_Vds1_Class= NULL;
Dlg_DCsource_Vds1 = NULL;
My_Dlg_Vds1_Class = (Dlg_DCSource_Prototype) My_Vds1_Lib->resolve("CreateDCSourceDialogClass");
if(!My_Dlg_Vds1_Class){
// DCsource_1_online = 0;
QTextStream(error_msg) <<"Vds1 driver: class unresolved";
return 1;
}
// My_Vds1_Lib->unload();
Dlg_DCsource_Vds1 = My_Dlg_Vds1_Class(DCsource_Vds1);
QTextStream(error_msg) <<"Vds1 driver: successfully loaded";
}
return 0;
}
am l missing something ?
l want to load dynamically DLL ( instrument driver) so l can change on the fly which driver to use for my instruments.
The DLL contains a QDialog with a specific class containing all driver's commands. Overall works very well except when l change the DLL, can not open the Qdialog ( .exec() ), it crash.
the driver/ dll are tested individually and works fine.
I suspect something on class allocation below, but can not figure it out.
here is the code below:
- first copy the .dll to a specific name so can use same the driver multiple times in the application.
- then load teh class containing the GPIB commands
- then load the class for the Qdialog ( UI)
short GPIB_Dashboard::Load_Drivers_Vds_1(QString *error_msg)
{
QString drivername;
QString error;
QStringList message;
{
if(My_Vds1_Lib != NULL)
{
My_Vds1_Lib->unload();
delete My_Vds1_Lib;
My_Vds1_Lib = new QLibrary();
}
else
My_Vds1_Lib = new QLibrary();
//reserve DLL copy
drivername = QCoreApplication::applicationDirPath()+"//Driver_Vds1.dll";
if(QFile::exists(drivername))
if(!QFile::remove(drivername))
{
QTextStream(error_msg) << "error: could not image driver Vds1";
return 1;
}
if(!QFile::copy(Vds1.name,drivername ))
{
QTextStream(error_msg) <<"error: could not copy driver Vds1";
return 1;
}
My_Vds1_Lib->setFileName(drivername);
My_Vds1_Lib->load();
DCsource_Vds1_class = (My_DCsource_Prototype) My_Vds1_Lib->resolve("CreateDCSourceClass");
if(!DCsource_Vds1_class){
// DCsource_1_online = 0;
QTextStream(error_msg) <<"Vds1 driver: class unresolved";
return 1;
}
DCsource_Vds1 = DCsource_Vds1_class();
DCsource_Vds1->Instance_name = "Vds1";
DCsource_Vds1->LoadConfig();
DCsource_Vds1->Read_GPIB_config(&message, &error);
My_Dlg_Vds1_Class= NULL;
Dlg_DCsource_Vds1 = NULL;
My_Dlg_Vds1_Class = (Dlg_DCSource_Prototype) My_Vds1_Lib->resolve("CreateDCSourceDialogClass");
if(!My_Dlg_Vds1_Class){
// DCsource_1_online = 0;
QTextStream(error_msg) <<"Vds1 driver: class unresolved";
return 1;
}
// My_Vds1_Lib->unload();
Dlg_DCsource_Vds1 = My_Dlg_Vds1_Class(DCsource_Vds1);
QTextStream(error_msg) <<"Vds1 driver: successfully loaded";
}
return 0;
}
am l missing something ?