summaryrefslogtreecommitdiffstats
path: root/src/corelib/plugin/qlibrary_win.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2016-04-28 14:09:32 -0700
committerThiago Macieira <thiago.macieira@intel.com>2016-05-08 06:51:24 +0000
commita63ca3fa106f4b0f9776bf2004661ef6dec2c0c6 (patch)
tree27d41f94aab6c63ae057ad07e49844d2f507ab05 /src/corelib/plugin/qlibrary_win.cpp
parent04ca11e6f9c69ac47cca8a35135718cc67f5019c (diff)
Implement QLibrary::PreventUnloadHint for Windows
It's interesting that the HMODULE/HINSTANCE pointer points to something in the actual module that got loaded, so we can use its value as "address of something in the module" for GetModuleHandleEx. The "PIN" flag tells the Windows DLL loader to never unload. Change-Id: Ifea6e497f11a461db432ffff1449a2169eb6293e Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Kai Koehne <kai.koehne@qt.io> Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'src/corelib/plugin/qlibrary_win.cpp')
-rw-r--r--src/corelib/plugin/qlibrary_win.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/corelib/plugin/qlibrary_win.cpp b/src/corelib/plugin/qlibrary_win.cpp
index deec54db0a..95e5afa837 100644
--- a/src/corelib/plugin/qlibrary_win.cpp
+++ b/src/corelib/plugin/qlibrary_win.cpp
@@ -148,6 +148,16 @@ bool QLibraryPrivate::load_sys()
else
qualifiedFileName = dir.filePath(moduleFileName);
#endif // !Q_OS_WINRT
+
+ if (loadHints() & QLibrary::PreventUnloadHint) {
+ // prevent the unloading of this component
+ HMODULE hmod;
+ bool ok = GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_PIN |
+ GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
+ reinterpret_cast<const wchar_t *>(pHnd),
+ &hmod);
+ Q_ASSERT(!ok || hmod == pHnd);
+ }
}
return (pHnd != 0);
}