windows: Fix RoInitialize() failure after a CoInitializeEx() call using apartment threading

This mirrors the same codepath in WIN_CoInitialize() which handles STA and MTA.
This commit is contained in:
Cameron Gutman 2022-04-18 21:19:25 -05:00 committed by Sam Lantinga
parent 923cb4463e
commit 8982d9f403
1 changed files with 13 additions and 1 deletions

View File

@ -148,7 +148,19 @@ WIN_RoInitialize(void)
typedef HRESULT (WINAPI *RoInitialize_t)(RO_INIT_TYPE initType);
RoInitialize_t RoInitializeFunc = (RoInitialize_t)WIN_LoadComBaseFunction("RoInitialize");
if (RoInitializeFunc) {
return RoInitializeFunc(RO_INIT_MULTITHREADED);
/* RO_INIT_SINGLETHREADED is equivalent to COINIT_APARTMENTTHREADED */
HRESULT hr = RoInitializeFunc(RO_INIT_SINGLETHREADED);
if (hr == RPC_E_CHANGED_MODE) {
hr = RoInitializeFunc(RO_INIT_MULTITHREADED);
}
/* S_FALSE means success, but someone else already initialized. */
/* You still need to call RoUninitialize in this case! */
if (hr == S_FALSE) {
return S_OK;
}
return hr;
} else {
return E_NOINTERFACE;
}