none
Opening Multiple Handles to WinUSB Device RRS feed

  • Question

  • I recently spent some time developing a dll to find a specific WinUSB device and query it's serial number. I found that if a handle to the device was already open, the subsequent call to CreateFile with the device path of the WinUSB device from another application would fail with ERROR_ACCESS_DENIED.

    Here is the call to CreateFile:

    devFileHandle = CreateFile(devInterfaceDetailData->DevicePath,
    GENERIC_WRITE | GENERIC_READ,
    FILE_SHARE_WRITE | FILE_SHARE_READ,
    NULL,
    OPEN_EXISTING,
    FILE_FLAG_OVERLAPPED,
    NULL);

    As you can see I am setting dwDesiredAccess to GENERIC_WRITE | GENERIC_READ and dwShareMode to FILE_SHARE_WRITE | FILE_SHARE_READ as I've seen in some examples which seems to make sense. These arguments suggest that this device can have a handle opened for it without an exclusive lock and the documentation for CreateFile seems to suggest the same.

    After doing lots of reading and research, I've seen posts that state WinUSB device handles opened via CreateFile are always opened in an exclusive mode which blocks subsequent attempts to open another handle to the device until the first handle is closed.

    While I believe that is true through my own experience and reading, I'd like to know, where is this explicitly documented? I've read countless MSDN articles and the documentation that comes with the SDK and DDK and I don't see any mention of this trait.

    Can someone post a link or provide the original documentation of the fact that you cannot open more than one device handle to a WinUSB device (preferable from a Microsoft source)?

    I'd post the specific links where people have stated that you cannot open multiple device handles to WinUSB devices via CreateFile, but account is not yet verified so I cannot post links.

    Thank you!

    Friday, March 13, 2015 7:48 PM

Answers

  • think about it this way: Io with a USB device is contextual and stateful. If you could open shared, you could mess with the other handles idea of what the state should be

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Friday, March 13, 2015 10:14 PM
  • I agree with you that this is a gap in the documentation. We will get it fixed.

    Thanks,

    Vivek

    Monday, March 16, 2015 3:13 PM

All replies

  • think about it this way: Io with a USB device is contextual and stateful. If you could open shared, you could mess with the other handles idea of what the state should be

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Friday, March 13, 2015 10:14 PM
  • Hi Doron,

    Thanks for taking the time to respond to my post!

    I understand why this mechanism is in place. I would just like to know where it is documented. I've seen a handful of people say it's documented somewhere, but in all of the MSDN and DDK documentation I've read I don't see where it's documented. 

    Monday, March 16, 2015 2:03 PM
  • I agree with you that this is a gap in the documentation. We will get it fixed.

    Thanks,

    Vivek

    Monday, March 16, 2015 3:13 PM
  • Well, FWIW, still not documented as of Feb, 2017. Just spent some time banging my head against this one too.
    Wednesday, March 1, 2017 10:23 PM
  • No special documentation is needed for this. In Windows, some devices are "exclusive" - only one handle can be opened on them, no matter what sharing more you specify in CreateFile call. Serial port is the most known type of such device. This behavior is defined by the device driver.

    -- pa

    Wednesday, March 1, 2017 10:33 PM