Switch back to apartment threaded COM initialization, which was the previous default.
authorSam Lantinga <slouken@libsdl.org>
Fri, 27 Dec 2013 10:18:19 -0800
changeset 8085 051c0c4cf161
parent 8084 96b1986b1e61
child 8086 b744b3f8754b
Switch back to apartment threaded COM initialization, which was the previous default. We do succeed now if the application previously initialized COM in multi-threaded mode.
src/core/windows/SDL_windows.c
--- a/src/core/windows/SDL_windows.c	Fri Dec 27 10:18:18 2013 -0800
+++ b/src/core/windows/SDL_windows.c	Fri Dec 27 10:18:19 2013 -0800
@@ -45,7 +45,15 @@
 HRESULT
 WIN_CoInitialize(void)
 {
-    const HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
+    /* SDL handles any threading model, so initialize with the default, which
+       is compatible with OLE and if that doesn't work, try multi-threaded mode.
+
+       If you need multi-threaded mode, call CoInitializeEx() before SDL_Init()
+    */
+    HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
+    if (hr == RPC_E_CHANGED_MODE) {
+        hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
+    }
 
     /* S_FALSE means success, but someone else already initialized. */
     /* You still need to call CoUninitialize in this case! */