# Problem with changing Win32 Runtime via RoInitialize(RO\_INIT\_MULTITHREADED)

**URL:** <https://forums.unrealengine.com/t/problem-with-changing-win32-runtime-via-roinitialize-ro-init-multithreaded/1986765>\
**Category:** C++\
**Tags:** unreal-engine, question\
**Created:** [August 21, 2024, 11:34pm UTC](https://forums.unrealengine.com/t/problem-with-changing-win32-runtime-via-roinitialize-ro-init-multithreaded/1986765 "2024-08-21T23:34:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DatosLab](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DatosLab](https://forums.unrealengine.com/u/DatosLab)\
**Post date:** [August 21, 2024, 11:34pm UTC](https://forums.unrealengine.com/t/problem-with-changing-win32-runtime-via-roinitialize-ro-init-multithreaded/1986765/1 "2024-08-21T23:34:11Z")

</div>

Hi,

I need to change Windows Runtime to multithread mode for several windows async functions. It appears that in 5.0.2 Hotfix release, an issue with ::RoInitialize(RO\_INIT\_MULTITHREADED) has been resolved - [5.0.2 Hotfix Released Announcement](https://forums.unrealengine.com/t/5-0-2-hotfix-released/566149); however, I am unable to find any information on the UE public issues tracking site. I ran a test (in an UActorComponent) as follows:

```auto
int32_t cotype, qualifier;

get_apartment_result = WINRT_IMPL_CoGetApartmentType(&cotype, &qualifier);

if (cotype == APTTYPE_STA || cotype == APTTYPE_MAINSTA) {
    UE_LOG(LogTemp, Warning, TEXT("Single-threaded apartment detected, uninitializing."));
    RoUninitialize();
}

winrt::hresult result = RoInitialize(RO_INIT_MULTITHREADED);

if (result == S_OK) {
    UE_LOG(LogTemp, Display, TEXT("RoInitialize(RO_INIT_MULTITHREADED) successfully"));
}
else if (result == S_FALSE) {
    UE_LOG(LogTemp, Display, TEXT("RoInitialize(RO_INIT_MULTITHREADED) failed"));
}
else if (result == RPC_E_CHANGED_MODE) {
    UE_LOG(LogTemp, Display, TEXT("RoInitialize(RO_INIT_MULTITHREADED) returned RPC_E_CHANGED_MODE"));
}
else {
    UE_LOG(LogTemp, Warning, TEXT("RoInitialize: result= %d"), (uint32_t)result);
}

int32_t cotypeAfter, qualifierAfter;

get_apartment_result = WINRT_IMPL_CoGetApartmentType(&cotypeAfter, &qualifierAfter);

if (cotypeAfter == APTTYPE_STA || cotypeAfter == APTTYPE_MAINSTA) {//getting error C2065: 'APTTYPE_STA': undeclared identifier and error C2065: 'APTTYPE_MAINSTA': undeclared identifier
    UE_LOG(LogTemp, Warning, TEXT("Single-threaded apartment detected"));
}
else {
    UE_LOG(LogTemp, Warning, TEXT("Multi-threaded apartment detected"));
}

```

And the output log is as follows:

```auto
LogTemp: Warning: Single-threaded apartment detected, uninitializing.
LogTemp: Display: RoInitialize(RO_INIT_MULTITHREADED) returned RPC_E_CHANGED_MODE
LogTemp: Warning: Single-threaded apartment detected

```

I also searched for “RoInitialize” in the engine source in VS2022 and couldn’t find any results. Is there another way to change windows runtime threading mode?

---

<div class="post-metadata">

**Author:** ![DatosLab](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DatosLab](https://forums.unrealengine.com/u/DatosLab)\
**Post date:** [August 24, 2024, 2:54pm UTC](https://forums.unrealengine.com/t/problem-with-changing-win32-runtime-via-roinitialize-ro-init-multithreaded/1986765/2 "2024-08-24T14:54:47Z")

</div>

I was able to move WinRT async calls to a different UE thread and successfully get a response without the need to use RoInitialize; prior to this, it would hang on certain async calls. [UE5Coro](https://github.com/landelare/ue5coro) has made it much easier to handle mutl-threading in UE so many thanks to the author who created this amazing plugin.
