How to prevent FTDI.NET DLL from warning users when drivers are not installed

I have a C # application that uses FTD2XX.DLL from FTDI. This application is used for several generations of a single product and abstracts the physical equipment. There FTDI and implementation of HID.

The application is looking for suitable FTDI and HID devices, although there probably are no FTDI drivers if the user has HID generation.

History aside. When I create an instance of the FTDI class, I get a modal code that is not generated by my code that I did not find the FTDI driver and asks the user if the drivers are installed. I tried wrapping this in a TRY / CATCH block, but no exception was thrown.

1: Is there a way to determine if FTDI drivers are installed before trying to instantiate the FTDI class?

2: If not, is there a way to prevent the FTDI DLL from warning the user when this happens?

+4
source share
4 answers

I have the same requirements - in my case, I list the list of standard serial ports and add them with a list of any connected FTDI devices. If the driver is not installed, then I would not want these modal dialogs to be displayed. One quick and dirty way that I decided to do was check the FTD2XX.DLL file located in c: \ windows \ system32 (or where the windows are installed). The existence of this file basically means that the driver is installed.

// c# example string path = Environment.GetFolderPath(Environment.SpecialFolder.System); bool installed = File.Exists(path + Path.DirectorySeparatorChar + "FTD2XX.DLL"); 
+4
source

Another way:

 [DllImport("kernel32.dll")] private static extern IntPtr LoadLibrary(string dllToLoad); [DllImport("kernel32.dll")] private static extern bool FreeLibrary(IntPtr hModule); public bool IsDriverInstalled() { //trying to load library IntPtr handler = LoadLibrary(@"FTD2XX.DLL"); if (handler == IntPtr.Zero) return false; else return true; // Driver is installed //Don't forget to free .dll FreeLibrary(handler); } 
+2
source

It sounds like you are associating FTD2XX.DLL with your application.

You should not do this, you should use the latest DLL installed in the Windows system directory by the FTDI driver. If you have an old version of the DLL in the application directory and the user has newer drivers (possibly installed by some other FTDI-based device), you may have all kinds of problems.

As a bonus, this solves your problem in most cases: if FTD2XX.DLL is not installed on the system, you will get an exception trying to execute p / invoke, which you can catch.

However, to avoid the error, you need to perform the same check that FTD2XX.DLL does internally (since the DLL can obviously exist on the system without any driver). For example, checking for a driver in the registry under HKLM\System\CurrentControlSet\services will be a more reliable check than the one you have. Still not sure if this is equivalent to FTDI's own validation.

0
source

I rewrote the FTDI library that caused the error: it was called MessageBox.Show in the constructor. I replaced this with the usual Exception throw.

See my blog for redesigned wrappers and code: connecting to FTDI devices in Silverlight 5 RC

0
source

Source: https://habr.com/ru/post/1343355/


All Articles