mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Check if SimConnect was properly loaded before attempting to use it
This commit adds a check that loadAndResolveSimConnect actually succeeds and moves it right before SimConnect_Open is called. The method itself was improved to check whether symbols got loaded already in a previous run, before doing everything again.
This commit is contained in:
committed by
Klaus Basan
parent
f3024d15cb
commit
ce99c0535f
@@ -99,6 +99,9 @@ QString getLastErrorMsg()
|
||||
|
||||
bool loadAndResolveSimConnect(bool manifestProbing)
|
||||
{
|
||||
// Check if already loaded
|
||||
if (gSymbols.SimConnect_Open) { return true; }
|
||||
|
||||
QLibrary simConnectDll;
|
||||
simConnectDll.setFileName("SimConnect.dll");
|
||||
simConnectDll.setLoadHints(QLibrary::PreventUnloadHint);
|
||||
@@ -171,6 +174,11 @@ bool loadAndResolveSimConnect(bool manifestProbing)
|
||||
gSymbols.SimConnect_CreateClientData = reinterpret_cast<PfnSimConnect_CreateClientData>(simConnectDll.resolve("SimConnect_CreateClientData"));
|
||||
gSymbols.SimConnect_AddToClientDataDefinition = reinterpret_cast<PfnSimConnect_AddToClientDataDefinition>(simConnectDll.resolve("SimConnect_AddToClientDataDefinition"));
|
||||
}
|
||||
else
|
||||
{
|
||||
CLogMessage(static_cast<SimConnectSymbols*>(nullptr)).error("Failed to load SimConnect.dll: %1") << getLastErrorMsg();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -87,6 +87,9 @@ namespace BlackSimPlugin
|
||||
{
|
||||
if (this->isConnected()) { return true; }
|
||||
this->reset();
|
||||
|
||||
if (!loadAndResolveSimConnect(true)) { return false; }
|
||||
|
||||
if (FAILED(SimConnect_Open(&m_hSimConnect, sApp->swiftVersionChar(), nullptr, 0, 0, 0)))
|
||||
{
|
||||
// reset state as expected for unconnected
|
||||
@@ -2017,7 +2020,6 @@ namespace BlackSimPlugin
|
||||
constexpr int QueryInterval = 5 * 1000; // 5 seconds
|
||||
m_timer.setInterval(QueryInterval);
|
||||
m_timer.setObjectName(this->objectName().append(":m_timer"));
|
||||
loadAndResolveSimConnect(true);
|
||||
connect(&m_timer, &QTimer::timeout, this, &CSimulatorFsxCommonListener::checkConnection);
|
||||
}
|
||||
|
||||
@@ -2027,6 +2029,9 @@ namespace BlackSimPlugin
|
||||
m_simConnectVersion.clear();
|
||||
m_simulatorName.clear();
|
||||
m_simulatorDetails.clear();
|
||||
|
||||
if (!loadAndResolveSimConnect(true)) { return; }
|
||||
|
||||
m_timer.start();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user