diff --git a/src/plugins/simulator/fsxcommon/simconnectsymbols.cpp b/src/plugins/simulator/fsxcommon/simconnectsymbols.cpp index 965d0b3d4..ee45f016d 100644 --- a/src/plugins/simulator/fsxcommon/simconnectsymbols.cpp +++ b/src/plugins/simulator/fsxcommon/simconnectsymbols.cpp @@ -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(simConnectDll.resolve("SimConnect_CreateClientData")); gSymbols.SimConnect_AddToClientDataDefinition = reinterpret_cast(simConnectDll.resolve("SimConnect_AddToClientDataDefinition")); } + else + { + CLogMessage(static_cast(nullptr)).error("Failed to load SimConnect.dll: %1") << getLastErrorMsg(); + return false; + } return true; } diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp index 984bed310..68a0f2c47 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp @@ -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(); }