mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 19:35:32 +08:00
[AFV] Ref T730, use CoInitializeEx on windows for threaded CAfvClient
This commit is contained in:
@@ -674,9 +674,37 @@ namespace BlackCore
|
||||
|
||||
void CAfvClient::initialize()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (!m_winCoInitialized)
|
||||
{
|
||||
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
||||
|
||||
// RPC_E_CHANGED_MODE: CoInitializeEx was already called by someone else in this thread with a different mode.
|
||||
if (hr == RPC_E_CHANGED_MODE)
|
||||
{
|
||||
CLogMessage(this).debug(u"CoInitializeEx was already called with a different mode. Trying again.");
|
||||
hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
||||
}
|
||||
|
||||
// S_OK: The COM library was initialized successfully on this thread.
|
||||
// S_FALSE: The COM library is already initialized on this thread. Reference count was incremented. This is not an error.
|
||||
if (hr == S_OK || hr == S_FALSE) { m_winCoInitialized = true; }
|
||||
}
|
||||
#endif
|
||||
CLogMessage(this).info(u"Initialize AFV client in thread: %1") << CThreadUtils::threadInfo(this->thread());
|
||||
}
|
||||
|
||||
void CAfvClient::cleanup()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (m_winCoInitialized)
|
||||
{
|
||||
CoUninitialize();
|
||||
m_winCoInitialized = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void CAfvClient::onPositionUpdateTimer()
|
||||
{
|
||||
if (hasContext())
|
||||
|
||||
Reference in New Issue
Block a user