Commit 69153196839d1aaa9893b7d410a509cebd5900b6

Sam Lantinga 2013-12-27T10:18:19

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
diff --git a/src/core/windows/SDL_windows.c b/src/core/windows/SDL_windows.c
index 8de46a7..6a13ab1 100644
--- a/src/core/windows/SDL_windows.c
+++ b/src/core/windows/SDL_windows.c
@@ -45,7 +45,15 @@ WIN_SetError(const char *prefix)
 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! */