diff options
authorMike Kaganski <>2020-05-24 09:18:10 +0200
committerMike Kaganski <>2020-05-24 10:28:59 +0200
commit1126515226b60630b3a0fd72c45258b230dfe8fd (patch)
parente3ca594d63daa7e59cee1f9745015f582ab4e773 (diff)
Try to blind-solve cppunittester hangs on Windows
... calling OleInitialize early in sal_main to initialize COM and concurrency. Seeing intermittent hangs in main thread in CAPNDataObject::GetData calling m_rIDataObjectOrg->GetData, and the inner stack waiting objects in the code doing apartment switching (I forgot to save a stack to paste unfortunately), I suspect that being related to incorrect concurrency model. OleInitialize docs [1] mention: Applications that use the following functionality must call OleInitialize before calling any other function in the COM library: * Clipboard * Drag and Drop * Object linking and embedding (OLE) * In-place activation ... Because OLE operations are not thread-safe, OleInitialize specifies the concurrency model as single-thread apartment. CoInitializeEx sets COINIT_MULTITHREADED by default, so possibly that might get called somewhere before clipboard/OLE code is called. I hope that this change would fix those hangs. [1] Change-Id: I7213c9d6cb4bd0691a3ce355995157797d7db93f Reviewed-on: Tested-by: Jenkins Reviewed-by: Mike Kaganski <>
2 files changed, 10 insertions, 4 deletions
diff --git a/sal/ b/sal/
index 3b9016783b80..65426e722240 100644
--- a/sal/
+++ b/sal/
@@ -28,6 +28,10 @@ $(eval $(call gb_Executable_add_exception_objects,cppunittester,\
sal/cppunittester/cppunittester \
+$(eval $(call gb_Executable_use_system_win32_libs,cppunittester,\
+ ole32 \
ifeq ($(COM),MSC)
$(eval $(call gb_Executable_add_ldflags,cppunittester,\
diff --git a/sal/cppunittester/cppunittester.cxx b/sal/cppunittester/cppunittester.cxx
index a760ecf8ff41..1b3c518c4b21 100644
--- a/sal/cppunittester/cppunittester.cxx
+++ b/sal/cppunittester/cppunittester.cxx
@@ -18,10 +18,9 @@
#ifdef _WIN32
-#if !defined WIN32_LEAN_AND_MEAN
-# define WIN32_LEAN_AND_MEAN
-#include <windows.h>
+#include <prewin.h>
+#include <ole2.h>
+#include <postwin.h>
#ifdef UNX
@@ -389,6 +388,9 @@ SAL_IMPLEMENT_MAIN()
+ // Tests may use e.g. OLE or clipboard; initialize COM and appropriate concurrency early
+ OleInitialize(nullptr);
std::vector<CppUnit::Protector *> protectors;