From 1d21c74e680658a8ce584206e2bcc4d1a443eea6 Mon Sep 17 00:00:00 2001 From: PhyxionNL <7643972+PhyxionNL@users.noreply.github.com> Date: Mon, 7 Dec 2020 11:57:54 +0100 Subject: [PATCH] Check whether Ftd2xx DLL exists. --- .../Controller/TBalancer/TBalancerGroup.cs | 20 +++++++------------ LibreHardwareMonitorLib/Interop/Ftd2xx.cs | 11 ++++++++++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/LibreHardwareMonitorLib/Hardware/Controller/TBalancer/TBalancerGroup.cs b/LibreHardwareMonitorLib/Hardware/Controller/TBalancer/TBalancerGroup.cs index 9fa6dce..380fb81 100644 --- a/LibreHardwareMonitorLib/Hardware/Controller/TBalancer/TBalancerGroup.cs +++ b/LibreHardwareMonitorLib/Hardware/Controller/TBalancer/TBalancerGroup.cs @@ -25,25 +25,19 @@ namespace LibreHardwareMonitor.Hardware.Controller.TBalancer uint numDevices; try { + if (!Ftd2xx.DllExists()) + { + _report.AppendLine("Status: missing DLL"); + return; + } + if (Ftd2xx.FT_CreateDeviceInfoList(out numDevices) != Ftd2xx.FT_STATUS.FT_OK) { _report.AppendLine("Status: FT_CreateDeviceInfoList failed"); return; } } - catch (DllNotFoundException) - { - return; - } - catch (ArgumentNullException) - { - return; - } - catch (EntryPointNotFoundException) - { - return; - } - catch (BadImageFormatException) + catch (Exception e) when (e is DllNotFoundException || e is ArgumentNullException || e is EntryPointNotFoundException || e is BadImageFormatException) { return; } diff --git a/LibreHardwareMonitorLib/Interop/Ftd2xx.cs b/LibreHardwareMonitorLib/Interop/Ftd2xx.cs index 5c07aca..23c7e17 100644 --- a/LibreHardwareMonitorLib/Interop/Ftd2xx.cs +++ b/LibreHardwareMonitorLib/Interop/Ftd2xx.cs @@ -14,6 +14,17 @@ namespace LibreHardwareMonitor.Interop { private const string DllName = "Ftd2xx.dll"; + public static bool DllExists() + { + IntPtr module = Kernel32.LoadLibrary(DllName); + if (module == IntPtr.Zero) + return false; + + + Kernel32.FreeLibrary(module); + return true; + } + [DllImport(DllName)] public static extern FT_STATUS FT_CreateDeviceInfoList(out uint numDevices);