Mercurial > hg > ucis.core
comparison 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 |
comparison
equal
deleted
inserted
replaced
92:ac0a29c05d03 | 93:d467cd38b34e |
---|---|
57 public static IList<DeviceNode> GetDevices(String enumerator) { | 57 public static IList<DeviceNode> GetDevices(String enumerator) { |
58 return GetDevices(enumerator, true); | 58 return GetDevices(enumerator, true); |
59 } | 59 } |
60 public static IList<DeviceNode> GetDevices(String enumerator, Boolean present) { | 60 public static IList<DeviceNode> GetDevices(String enumerator, Boolean present) { |
61 using (SafeDeviceInfoSetHandle dis = SetupApi.SetupDiGetClassDevsA(IntPtr.Zero, enumerator, IntPtr.Zero, (present ? DICFG.PRESENT : 0) | DICFG.ALLCLASSES)) { | 61 using (SafeDeviceInfoSetHandle dis = SetupApi.SetupDiGetClassDevsA(IntPtr.Zero, enumerator, IntPtr.Zero, (present ? DICFG.PRESENT : 0) | DICFG.ALLCLASSES)) { |
62 //using (SafeDeviceInfoSetHandle dis = SetupApi.SetupDiGetClassDevsA(IntPtr.Zero, enumerator, IntPtr.Zero, DICFG.ALLCLASSES | DICFG.DEVICEINTERFACE)) { | |
63 return GetDevicesInSet(dis); | 62 return GetDevicesInSet(dis); |
64 } | 63 } |
65 } | 64 } |
66 | 65 |
67 public UInt32 DevInst { get; private set; } | 66 public UInt32 DevInst { get; private set; } |
87 using (SafeDeviceInfoSetHandle dis = SetupApi.SetupDiGetClassDevsA(IntPtr.Zero, DeviceID, IntPtr.Zero, DICFG.DEVICEINTERFACE | DICFG.ALLCLASSES)) { | 86 using (SafeDeviceInfoSetHandle dis = SetupApi.SetupDiGetClassDevsA(IntPtr.Zero, DeviceID, IntPtr.Zero, DICFG.DEVICEINTERFACE | DICFG.ALLCLASSES)) { |
88 if (dis.IsInvalid) throw new Win32Exception(Marshal.GetLastWin32Error()); | 87 if (dis.IsInvalid) throw new Win32Exception(Marshal.GetLastWin32Error()); |
89 SP_DEVINFO_DATA dd = new SP_DEVINFO_DATA(true); | 88 SP_DEVINFO_DATA dd = new SP_DEVINFO_DATA(true); |
90 if (!SetupApi.SetupDiEnumDeviceInfo(dis, 0, ref dd)) | 89 if (!SetupApi.SetupDiEnumDeviceInfo(dis, 0, ref dd)) |
91 return null; | 90 return null; |
92 //throw new Win32Exception(Marshal.GetLastWin32Error()); | |
93 RegistryValueKind propertyType; | 91 RegistryValueKind propertyType; |
94 byte[] propBuffer = new byte[256]; | 92 byte[] propBuffer = new byte[256]; |
95 int requiredSize; | 93 int requiredSize; |
96 if (!SetupApi.SetupDiGetDeviceRegistryProperty(dis, ref dd, property, out propertyType, propBuffer, propBuffer.Length, out requiredSize)) | 94 if (!SetupApi.SetupDiGetDeviceRegistryProperty(dis, ref dd, property, out propertyType, propBuffer, propBuffer.Length, out requiredSize)) |
97 return null; | 95 return null; |
147 using (SafeDeviceInfoSetHandle dis = SetupApi.SetupDiGetClassDevsA(IntPtr.Zero, DeviceID, IntPtr.Zero, DICFG.DEVICEINTERFACE | DICFG.ALLCLASSES)) { | 145 using (SafeDeviceInfoSetHandle dis = SetupApi.SetupDiGetClassDevsA(IntPtr.Zero, DeviceID, IntPtr.Zero, DICFG.DEVICEINTERFACE | DICFG.ALLCLASSES)) { |
148 if (dis.IsInvalid) throw new Win32Exception(Marshal.GetLastWin32Error()); | 146 if (dis.IsInvalid) throw new Win32Exception(Marshal.GetLastWin32Error()); |
149 SP_DEVINFO_DATA dd = new SP_DEVINFO_DATA(true); | 147 SP_DEVINFO_DATA dd = new SP_DEVINFO_DATA(true); |
150 if (!SetupApi.SetupDiEnumDeviceInfo(dis, 0, ref dd)) | 148 if (!SetupApi.SetupDiEnumDeviceInfo(dis, 0, ref dd)) |
151 return null; | 149 return null; |
152 //throw new Win32Exception(Marshal.GetLastWin32Error()); | |
153 RegistryValueKind propertyType; | 150 RegistryValueKind propertyType; |
154 byte[] propBuffer = new byte[256]; | 151 byte[] propBuffer = new byte[256]; |
155 int requiredSize; | 152 int requiredSize; |
156 if (!SetupApi.SetupDiGetCustomDeviceProperty(dis, ref dd, name, DICUSTOMDEVPROP.NONE, out propertyType, propBuffer, propBuffer.Length, out requiredSize)) | 153 if (!SetupApi.SetupDiGetCustomDeviceProperty(dis, ref dd, name, DICUSTOMDEVPROP.NONE, out propertyType, propBuffer, propBuffer.Length, out requiredSize)) |
157 return null; | 154 return null; |
339 throw new Win32Exception(Marshal.GetLastWin32Error()); | 336 throw new Win32Exception(Marshal.GetLastWin32Error()); |
340 if (!SetupApi.SetupDiCallClassInstaller(UsbApi.DIF_PROPERTYCHANGE, dis, ref dd)) | 337 if (!SetupApi.SetupDiCallClassInstaller(UsbApi.DIF_PROPERTYCHANGE, dis, ref dd)) |
341 throw new Win32Exception(Marshal.GetLastWin32Error()); | 338 throw new Win32Exception(Marshal.GetLastWin32Error()); |
342 } | 339 } |
343 } | 340 } |
341 | |
342 public Boolean Uninstall() { | |
343 using (SafeDeviceInfoSetHandle dis = SetupApi.SetupDiGetClassDevsA(IntPtr.Zero, DeviceID, IntPtr.Zero, DICFG.DEVICEINTERFACE | DICFG.ALLCLASSES)) { | |
344 if (dis.IsInvalid) throw new Win32Exception(Marshal.GetLastWin32Error()); | |
345 SP_DEVINFO_DATA dd = new SP_DEVINFO_DATA(true); | |
346 if (!SetupApi.SetupDiEnumDeviceInfo(dis, 0, ref dd)) | |
347 throw new Win32Exception(Marshal.GetLastWin32Error()); | |
348 Boolean needsReboot; | |
349 if (!SetupApi.DiUninstallDevice(IntPtr.Zero, dis, ref dd, 0, out needsReboot)) | |
350 throw new Win32Exception(Marshal.GetLastWin32Error()); | |
351 return needsReboot; | |
352 } | |
353 } | |
344 } | 354 } |
345 } | 355 } |