When CoInitializeEx returns RPC_E_CHANGED_MODE, it DOES NOT increase the reference counter of the COM library. Therefore version_name() decreases the reference counter without increment, and the COM library can be unloaded unintentionally.
My code which using infoware initially calls CoInitializeEx with COINIT_APARTMENTTHREADED, then calls version_name() via iware::system::OS_info(). In version_name() it unloads the COM library, and my following codes fails.
This commit fixes the issue by retrying CoInitializeEx with COINIT_APARTMENTTHREADED. By doing this, the reference counter of the COM library will be increased successfully.
When
CoInitializeEx
returnsRPC_E_CHANGED_MODE
, it DOES NOT increase the reference counter of the COM library. Thereforeversion_name()
decreases the reference counter without increment, and the COM library can be unloaded unintentionally.My code which using infoware initially calls
CoInitializeEx
withCOINIT_APARTMENTTHREADED
, then callsversion_name()
viaiware::system::OS_info()
. Inversion_name()
it unloads the COM library, and my following codes fails.This commit fixes the issue by retrying
CoInitializeEx
withCOINIT_APARTMENTTHREADED
. By doing this, the reference counter of the COM library will be increased successfully.Refers to: https://docs.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-coinitializeex