From 071760b7f4c28a131651233da47df8899c101b1f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 19 Apr 2020 16:59:59 +0200 Subject: [PATCH] Move OLE initialization to a module Previously this was done in wxMSW-specific wxApp version, which meant that initialization was done after the modules initialization and, especially problematically, uninitialization was done before modules uninitialization, which resulted in problems when doing anything using OLE from the modules OnExit(). This commit doesn't solve these problems yet, because it leaves modules initialization order undefined, but the upcoming commits using it will. --- src/msw/app.cpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/msw/app.cpp b/src/msw/app.cpp index 027a075fd0..be4bc5e9dc 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -145,6 +145,33 @@ wxVector gs_regClassesInfo; LRESULT WXDLLEXPORT APIENTRY wxWndProc(HWND, UINT, WPARAM, LPARAM); +// ---------------------------------------------------------------------------- +// Module for OLE initialization and cleanup +// ---------------------------------------------------------------------------- + +class wxOleInitModule : public wxModule +{ +public: + wxOleInitModule() + { + } + + virtual bool OnInit() wxOVERRIDE + { + return wxOleInitialize(); + } + + virtual void OnExit() wxOVERRIDE + { + wxOleUninitialize(); + } + +private: + wxDECLARE_DYNAMIC_CLASS(wxOleInitModule); +}; + +wxIMPLEMENT_DYNAMIC_CLASS(wxOleInitModule, wxModule); + // =========================================================================== // wxGUIAppTraits implementation // =========================================================================== @@ -622,8 +649,6 @@ bool wxApp::Initialize(int& argc_, wxChar **argv_) InitCommonControls(); - wxOleInitialize(); - wxSetKeyboardHook(true); callBaseCleanup.Dismiss(); @@ -739,8 +764,6 @@ void wxApp::CleanUp() wxSetKeyboardHook(false); - wxOleUninitialize(); - // for an EXE the classes are unregistered when it terminates but DLL may // be loaded several times (load/unload/load) into the same process in // which case the registration will fail after the first time if we don't