Merge branch 'ole-init-module'

Do OLE initialization from a module to fix problems due to
uninitializing it too early.

See https://github.com/wxWidgets/wxWidgets/pull/1807
This commit is contained in:
Vadim Zeitlin
2020-04-19 22:22:55 +02:00
4 changed files with 34 additions and 18 deletions

View File

@@ -145,6 +145,33 @@ wxVector<ClassRegInfo> gs_regClassesInfo;
LRESULT WXDLLEXPORT APIENTRY wxWndProc(HWND, UINT, WPARAM, LPARAM); 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 // wxGUIAppTraits implementation
// =========================================================================== // ===========================================================================
@@ -622,8 +649,6 @@ bool wxApp::Initialize(int& argc_, wxChar **argv_)
InitCommonControls(); InitCommonControls();
wxOleInitialize();
wxSetKeyboardHook(true); wxSetKeyboardHook(true);
callBaseCleanup.Dismiss(); callBaseCleanup.Dismiss();
@@ -739,8 +764,6 @@ void wxApp::CleanUp()
wxSetKeyboardHook(false); wxSetKeyboardHook(false);
wxOleUninitialize();
// for an EXE the classes are unregistered when it terminates but DLL may // 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 // 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 // which case the registration will fail after the first time if we don't

View File

@@ -458,10 +458,6 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxClipboard, wxObject);
wxClipboard::wxClipboard() wxClipboard::wxClipboard()
{ {
#if wxUSE_OLE_CLIPBOARD
wxOleInitialize();
#endif
m_lastDataObject = NULL; m_lastDataObject = NULL;
m_isOpened = false; m_isOpened = false;
} }
@@ -472,10 +468,6 @@ wxClipboard::~wxClipboard()
{ {
Clear(); Clear();
} }
#if wxUSE_OLE_CLIPBOARD
wxOleUninitialize();
#endif
} }
void wxClipboard::Clear() void wxClipboard::Clear()

View File

@@ -5247,14 +5247,14 @@ class wxDirect2DModule : public wxModule
public: public:
wxDirect2DModule() wxDirect2DModule()
{ {
// Using Direct2D requires OLE and, importantly, we must ensure our
// OnExit() runs before it is uninitialized.
AddDependency("wxOleInitModule");
} }
virtual bool OnInit() wxOVERRIDE virtual bool OnInit() wxOVERRIDE
{ {
HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); return true;
// RPC_E_CHANGED_MODE is not considered as an error
// - see remarks for wxOleInitialize().
return SUCCEEDED(hr) || hr == RPC_E_CHANGED_MODE;
} }
virtual void OnExit() wxOVERRIDE virtual void OnExit() wxOVERRIDE
@@ -5289,8 +5289,6 @@ public:
gs_ID2D1Factory->Release(); gs_ID2D1Factory->Release();
gs_ID2D1Factory = NULL; gs_ID2D1Factory = NULL;
} }
::CoUninitialize();
} }
private: private:

View File

@@ -463,6 +463,9 @@ class wxToastNotifMsgModule : public wxModule
public: public:
wxToastNotifMsgModule() wxToastNotifMsgModule()
{ {
// Using RT API requires OLE and, importantly, we must ensure our
// OnExit() runs before it is uninitialized.
AddDependency("wxOleInitModule");
} }
virtual bool OnInit() wxOVERRIDE virtual bool OnInit() wxOVERRIDE