Find out which process has an exclusive lock on a USB device handle

后端 未结 4 1964
死守一世寂寞
死守一世寂寞 2021-01-12 11:02

I have a library that reads/writes to a USB-device using CreateFile() API. The device happens to implement the HID-device profile, such that it\'s compatible with Microsoft\

4条回答
  •  有刺的猬
    2021-01-12 11:48

    There's a trick you can do where you open the device handle requesting neither read nor write permission and interact with it using only feature reports. Jan Axelson mentions this trick in her books about USB HID devices. I believe this gets around the problem with the exclusive lock, which you would encounter (for example) when trying to open a handle to a device that Windows considers a system keyboard or mouse. Even though you can't read or write the handle, you can still send a feature report to the device using HidD_SetFeature and read a report from the device using HidD_GetFeature. I don't know offhand of a way to read input reports or send output reports under these circumstances, and perhaps it's impossible to do so, but you might not need either of those, especially if the device is "your" device in the sense that you control the firmware. Strictly speaking this does nothing to answer your question as asked, but it seemed potentially relevant so I figured I'd throw it out there.

提交回复
热议问题