From 450019dc218f94146a30549994976e9d804b1c05 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Wed, 30 Dec 2015 17:41:17 +0100 Subject: [PATCH] Ensure COM is still active when Direct2D renderer is in use Some internal D2D operations need active COM library so ensure it is properly initialized and released in wxDirect2DModule. Closes #17308. --- src/msw/graphicsd2d.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/msw/graphicsd2d.cpp b/src/msw/graphicsd2d.cpp index 7addd85e64..340d15d44c 100644 --- a/src/msw/graphicsd2d.cpp +++ b/src/msw/graphicsd2d.cpp @@ -3759,7 +3759,10 @@ public: virtual bool OnInit() wxOVERRIDE { - return true; + HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + // 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 @@ -3781,6 +3784,8 @@ public: delete gs_D2DRenderer; gs_D2DRenderer = NULL; } + + ::CoUninitialize(); } private: