How to release the plugin's dll file when application is running
-
With regard to the use of dynamic libraries, the basic principle is to release when the last user exits. If it is not released, the dynamic library cannot be hot updated. In this way, we need to add a dynamic library version control module in the application, use a new name for each update, and delete useless files when the application restarts.
by the way, I tried, as long as loader->instance(); is called, the DLL file is locked. It has nothing to do with the call of loader->unload(). Is it possible that the unload method did not close the handle of the DLL file?
-
@qtyangyong said in How to release the plugin's dll file?:
With regard to the use of dynamic libraries, the basic principle is to release when the last user exits. If it is not released, the dynamic library cannot be hot updated. In this way, we need to add a dynamic library version control module in the application, use a new name for each update, and delete useless files when the application restarts.
I learned recently, that, while you cannot delete a .dll or .exe on Windows that is currently used, you can rename it (as long as the library or executable is still in the same folder).
So maybe you can just rename the .dll, extract the new .dll, and after a restart delete the old .dll?
-
You should take a look at QLibrary::setLoadHints()
-
Hi, on Windows removing .dll and .exe files that have been recebtly used is not likely to succeed due tio caching etc.
Why don”t you instead try renaming your plugin file to something like DeleteMe.dll? That usually works. After that, you can create a new copy with the original filename, and then you”ll have full read/write/delete acccess.
-
@qtyangyong said in How to release the plugin's dll file?:
With regard to the use of dynamic libraries, the basic principle is to release when the last user exits. If it is not released, the dynamic library cannot be hot updated. In this way, we need to add a dynamic library version control module in the application, use a new name for each update, and delete useless files when the application restarts.
I learned recently, that, while you cannot delete a .dll or .exe on Windows that is currently used, you can rename it (as long as the library or executable is still in the same folder).
So maybe you can just rename the .dll, extract the new .dll, and after a restart delete the old .dll?
@kkoehne yes, this is a good idea
-
Hi, on Windows removing .dll and .exe files that have been recebtly used is not likely to succeed due tio caching etc.
Why don”t you instead try renaming your plugin file to something like DeleteMe.dll? That usually works. After that, you can create a new copy with the original filename, and then you”ll have full read/write/delete acccess.
@hskoglund said in How to release the plugin's dll file when application is running:
Hi, on Windows removing .dll and .exe files that have been recebtly used is not likely to succeed due tio caching etc.
Exactly!
-
You should take a look at QLibrary::setLoadHints()
@Christian-Ehrlicher
thans, I tried it but didn't solve the problem. Maybe the usage is incorrect.
such as
loader.setloadhints (0);
loader.unload(); -
@Christian-Ehrlicher
thans, I tried it but didn't solve the problem. Maybe the usage is incorrect.
such as
loader.setloadhints (0);
loader.unload();@qtyangyong said in How to release the plugin's dll file when application is running:
Maybe the usage is incorrect.
For sure - they're load hints, not unload hints... set it before you load the library.
-
thank you very much, I moved "loader.setLoadHints(0);" before "loader.instance();", the problem was solved. the program such as below:
int main(int argc, char *argv[])
{
......
QPluginLoader loader("ExtraFiltersPlugin.dll");
loader.setLoadHints(0);
QObject *plugin = loader.instance();
if (plugin)
{
FilterInterface *fff = qobject_cast<FilterInterface *>(plugin);
fff->test();
}
MainWindow w;
w.ploader = &loader;
......
}void MainWindow::on_unloadBtn_clicked()
{
ploader->unload();
}