From 4de8857c8586d2012435e2370ca2ddd54c5e1b65 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 25 Jan 2021 00:10:10 +0100 Subject: [PATCH] Add wxDynamicLibrary::Attach() This is symmetric with Detach() and can be useful and doesn't cost anything to have. --- include/wx/dynlib.h | 3 +++ interface/wx/dynlib.h | 20 +++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/include/wx/dynlib.h b/include/wx/dynlib.h index 1036771c06..93473b0add 100644 --- a/include/wx/dynlib.h +++ b/include/wx/dynlib.h @@ -242,6 +242,9 @@ public: // library couldn't be loaded but simply returns NULL static wxDllType RawLoad(const wxString& libname, int flags = wxDL_DEFAULT); + // attach to an existing handle + void Attach(wxDllType h) { Unload(); m_handle = h; } + // detach the library object from its handle, i.e. prevent the object from // unloading the library in its dtor -- the caller is now responsible for // doing this diff --git a/interface/wx/dynlib.h b/interface/wx/dynlib.h index 93cb2ef2e1..991642c700 100644 --- a/interface/wx/dynlib.h +++ b/interface/wx/dynlib.h @@ -147,9 +147,23 @@ public: wxPluginCategory cat = wxDL_PLUGIN_GUI); /** - Detaches this object from its library handle, i.e.\ the object will not - unload the library any longer in its destructor but it is now the - callers responsibility to do this using Unload(). + Attaches the object to an existing handle. + + This allows to give ownership of an existing handle, possibly obtained + from Detach(), to this object, so that it will unload it when destroyed. + + @since 3.1.5 + */ + void Attach(wxDllType h); + + /** + Detaches this object from its library handle. + + This means that the object will not unload the library any longer in + its destructor but it is now the callers responsibility to do this + using static Unload(). + + @see Attach() */ wxDllType Detach();