using System; using System.Threading.Tasks; using SimConnect.Unmanaged; namespace SimConnect.Concrete { /// /// Default implementation of ISimConnectClientFactory /// public class SimConnectClientFactory : ISimConnectClientFactory { /// public async Task TryConnect(string appName) { // FS 2020 SimConnect.dll is 64-bits, the others are 32-bits if (Environment.Is64BitProcess) return await TryDefaultClient(appName, "FS2020-SimConnect.dll"); // This order prevents a version mismatch, but perhaps an option to explicitly set the version might be nice as well return await TryDefaultClient(appName, "FSX-SimConnect.dll") ?? await TryDefaultClient(appName, "FSXSP2-SimConnect.dll") ?? await TryDefaultClient(appName, "FSX-SE-SimConnect.dll"); } private static async Task TryDefaultClient(string appName, string libraryFilename) { var library = new SimConnectDLLLibrary(libraryFilename); var client = new DefaultSimConnectClient(library); return await client.TryOpen(appName) ? client : null; } } }