Mercurial > hg > ucis.core
diff USBLib/Windows/Devices/DeviceNode.cs @ 93:d467cd38b34e
USBLib: fix for large transfers with libusb0 on Windows, added driver uninstall function
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Tue, 22 Apr 2014 16:40:35 +0200 |
parents | 57b4c2f895d1 |
children |
line wrap: on
line diff
--- a/USBLib/Windows/Devices/DeviceNode.cs Fri Apr 04 23:21:33 2014 +0200 +++ b/USBLib/Windows/Devices/DeviceNode.cs Tue Apr 22 16:40:35 2014 +0200 @@ -59,7 +59,6 @@ } public static IList<DeviceNode> GetDevices(String enumerator, Boolean present) { using (SafeDeviceInfoSetHandle dis = SetupApi.SetupDiGetClassDevsA(IntPtr.Zero, enumerator, IntPtr.Zero, (present ? DICFG.PRESENT : 0) | DICFG.ALLCLASSES)) { - //using (SafeDeviceInfoSetHandle dis = SetupApi.SetupDiGetClassDevsA(IntPtr.Zero, enumerator, IntPtr.Zero, DICFG.ALLCLASSES | DICFG.DEVICEINTERFACE)) { return GetDevicesInSet(dis); } } @@ -89,7 +88,6 @@ SP_DEVINFO_DATA dd = new SP_DEVINFO_DATA(true); if (!SetupApi.SetupDiEnumDeviceInfo(dis, 0, ref dd)) return null; - //throw new Win32Exception(Marshal.GetLastWin32Error()); RegistryValueKind propertyType; byte[] propBuffer = new byte[256]; int requiredSize; @@ -149,7 +147,6 @@ SP_DEVINFO_DATA dd = new SP_DEVINFO_DATA(true); if (!SetupApi.SetupDiEnumDeviceInfo(dis, 0, ref dd)) return null; - //throw new Win32Exception(Marshal.GetLastWin32Error()); RegistryValueKind propertyType; byte[] propBuffer = new byte[256]; int requiredSize; @@ -341,5 +338,18 @@ throw new Win32Exception(Marshal.GetLastWin32Error()); } } + + public Boolean Uninstall() { + using (SafeDeviceInfoSetHandle dis = SetupApi.SetupDiGetClassDevsA(IntPtr.Zero, DeviceID, IntPtr.Zero, DICFG.DEVICEINTERFACE | DICFG.ALLCLASSES)) { + if (dis.IsInvalid) throw new Win32Exception(Marshal.GetLastWin32Error()); + SP_DEVINFO_DATA dd = new SP_DEVINFO_DATA(true); + if (!SetupApi.SetupDiEnumDeviceInfo(dis, 0, ref dd)) + throw new Win32Exception(Marshal.GetLastWin32Error()); + Boolean needsReboot; + if (!SetupApi.DiUninstallDevice(IntPtr.Zero, dis, ref dd, 0, out needsReboot)) + throw new Win32Exception(Marshal.GetLastWin32Error()); + return needsReboot; + } + } } }