/// <summary> /// Gets the matching drivers for a device. /// </summary> /// <param name="devInfoSet">The device info set.</param> /// <param name="devInfoData">The device info data.</param> /// <returns>An array of matching device drivers.</returns> private static DriverInstance[] GetMatchingDrivers( IntPtr devInfoSet, SP_DEVINFO_DATA devInfoData) { List <DriverInstance> result = null; SP_DRVINFO_DATA drvInfoData = new SP_DRVINFO_DATA(); drvInfoData.Size = Marshal.SizeOf(typeof(SP_DRVINFO_DATA)); if (Win32SetupApi.SetupDiBuildDriverInfoList(devInfoSet, ref devInfoData, Constants.SPDIT_COMPATDRIVER)) { result = new List <DriverInstance>(); for (int i = 0; Win32SetupApi.SetupDiEnumDriverInfo(devInfoSet, ref devInfoData, Constants.SPDIT_COMPATDRIVER, i, ref drvInfoData); i++) { result.Add(new DriverInstance { Description = drvInfoData.Description, Version = drvInfoData.DriverVersion, ManufacturerName = drvInfoData.MfgName, ProviderName = drvInfoData.ProviderName, DriverDate = drvInfoData.DriverDate.ToDateTime() }); } } return(result != null?result.ToArray() : new DriverInstance[] { }); }
/// <summary> /// Gets a driver handle from matching. /// </summary> /// <param name="driverInstance">The driver instance.</param> /// <param name="deviceInfoSet">The device info set.</param> /// <param name="deviceInfoData">The device info data.</param> /// <param name="drvInfoData">The DRV info data.</param> private static void GetDriverHandleFromMatch( DriverInstance driverInstance, IntPtr deviceInfoSet, SP_DEVINFO_DATA deviceInfoData, out SP_DRVINFO_DATA drvInfoData) { drvInfoData = new SP_DRVINFO_DATA(); drvInfoData.Size = Marshal.SizeOf(typeof(SP_DRVINFO_DATA)); if (Win32SetupApi.SetupDiBuildDriverInfoList(deviceInfoSet, ref deviceInfoData, Constants.SPDIT_COMPATDRIVER)) { for (int i = 0; Win32SetupApi.SetupDiEnumDriverInfo(deviceInfoSet, ref deviceInfoData, Constants.SPDIT_COMPATDRIVER, i, ref drvInfoData); i++) { if (driverInstance.Description.Equals(drvInfoData.Description)) { return; } } } drvInfoData = new SP_DRVINFO_DATA(); return; }