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)

Qt Code:
  1. short GPIB_Dashboard::Load_Drivers_Vds_1(QString *error_msg)
  2. {
  3. QString drivername;
  4. QString error;
  5. QStringList message;
  6. {
  7. if(My_Vds1_Lib != NULL)
  8. {
  9. My_Vds1_Lib->unload();
  10. delete My_Vds1_Lib;
  11. My_Vds1_Lib = new QLibrary();
  12. }
  13. else
  14. My_Vds1_Lib = new QLibrary();
  15.  
  16.  
  17. //reserve DLL copy
  18. drivername = QCoreApplication::applicationDirPath()+"//Driver_Vds1.dll";
  19. if(QFile::exists(drivername))
  20. if(!QFile::remove(drivername))
  21. {
  22. QTextStream(error_msg) << "error: could not image driver Vds1";
  23. return 1;
  24. }
  25. if(!QFile::copy(Vds1.name,drivername ))
  26. {
  27. QTextStream(error_msg) <<"error: could not copy driver Vds1";
  28. return 1;
  29. }
  30.  
  31. My_Vds1_Lib->setFileName(drivername);
  32. My_Vds1_Lib->load();
  33.  
  34.  
  35. DCsource_Vds1_class = (My_DCsource_Prototype) My_Vds1_Lib->resolve("CreateDCSourceClass");
  36. if(!DCsource_Vds1_class){
  37. // DCsource_1_online = 0;
  38. QTextStream(error_msg) <<"Vds1 driver: class unresolved";
  39. return 1;
  40. }
  41. DCsource_Vds1 = DCsource_Vds1_class();
  42. DCsource_Vds1->Instance_name = "Vds1";
  43. DCsource_Vds1->LoadConfig();
  44. DCsource_Vds1->Read_GPIB_config(&message, &error);
  45.  
  46. My_Dlg_Vds1_Class= NULL;
  47. Dlg_DCsource_Vds1 = NULL;
  48. My_Dlg_Vds1_Class = (Dlg_DCSource_Prototype) My_Vds1_Lib->resolve("CreateDCSourceDialogClass");
  49. if(!My_Dlg_Vds1_Class){
  50. // DCsource_1_online = 0;
  51. QTextStream(error_msg) <<"Vds1 driver: class unresolved";
  52. return 1;
  53. }
  54. // My_Vds1_Lib->unload();
  55.  
  56. Dlg_DCsource_Vds1 = My_Dlg_Vds1_Class(DCsource_Vds1);
  57.  
  58. QTextStream(error_msg) <<"Vds1 driver: successfully loaded";
  59. }
  60.  
  61. return 0;
  62. }
To copy to clipboard, switch view to plain text mode 


am l missing something ?