![]() Private static extern bool HidD_GetPreparsedData(SafeFileHandle hidDeviceObject, out IntPtr pointerToPreparsedData) Private const int HIDP_STATUS_INVALID_PREPARSED_DATA = -0x3FEF0000 Private const int HIDP_STATUS_SUCCESS = 0x110000 Private const uint GenericWrite = 1073741824 Private const uint GenericRead = 2147483648 ![]() Private const int DigcfDeviceinterface = 16 Here are two classes for dealing with USB/Hid at the raw Windows API level: ![]() Different platforms have different APIs for dealing with both USB and Hid. Hid is usually a little easier to work with than direct USB. A USB device may or may not be a Hid device and vice versa. USB devices usually fall in to two categories: Hid, and USB. Otherwise, you will receive a COM object error at runtime when closing. You have to make sure you call the Dispose() method when closing your application. Void watcher_EventRemoved(object sender, EventArrivedEventArgs e) Void watcher_EventArrived(object sender, EventArrivedEventArgs e) / Used to dispose of the USB device watchers when the USBControl class is disposed of. WatcherRemove.Query = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 3") WatcherRemove.EventArrived += new EventArrivedEventHandler(watcher_EventRemoved) var queryRemove = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 3") WatcherRemove = new ManagementEventWatcher() WatcherAttach.Query = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2") WatcherAttach.EventArrived += new EventArrivedEventHandler(watcher_EventArrived) ![]() var queryAttach = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2") WatcherAttach = new ManagementEventWatcher() Private ManagementEventWatcher watcherRemove Private ManagementEventWatcher watcherAttach used for monitoring plugging and unplugging of USB devices. I used the following code to detect when USB devices were plugged and unplugged from my computer: class USBControl : IDisposable ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |