none
WinUSB getting interface path by class GUID/VID+PID RRS feed

  • Question

  • Hello,

    I'm having problems with the "enumeration features" of Winusb, if you can call them that. Specifically, I can't figure out how to get the SP_DEVICE_INTERFACE_DETAIL_DATA.DevicePath for a specific Class GUID, let alone VID and PID. 

    For a given device interface GUID, I do the following (and it works):

    SetupDiGetClassDevsA(my_guid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE)
    ...
    SetupDiEnumDeviceInterfaces(hdev, devdata, guid, 0, &iface_data)
    ...
    SetupDiGetDeviceInterfaceDetailA(hdev, &iface_data, detail_data, length, &length, NULL)

    My approach for a class GUID was the following:

    SetupDiGetClassDevsA(class_guid, NULL, NULL, DIGCF_PRESENT)
    ...
    SetupDiEnumDeviceInfo(hdev, 0, &dev_data)
    ...
    SetupDiEnumDeviceInterfaces(hdev, devdata, guid, 0, &iface_data) // returns FALSE + ERROR_NO_MORE_ITEMS

    The DEVINFO_DATA structure gets filled correctly by SetupDiEnumDeviceInfo() but SetupDiEnumDeviceInterfaces() fails.

    Also I was wondering how one would connect to a device by VID and PID because using it as an enumerator in SetupDiGetClassDevs() didn't work either, even though it's implied in the MSDN.

    I'd appreciate if someone could point me in the right direction with this, thanks in advance.

    Sunday, July 9, 2017 11:28 AM

All replies

  • I've used the following code successfully for a number of projects:

    HRESULT result;
    HDEVINFO deviceInfo;
    SP_DEVINFO_DATA	deviceInfoData;
    SP_DEVICE_INTERFACE_DATA deviceInterfaceData;
    PSP_DEVICE_INTERFACE_DETAIL_DATA interfaceDetailData;
    ULONG requiredLength;
    
    if ( SetupDiEnumDeviceInfo( deviceInfo, 0, &deviceInfoData ) )
    {
    
    
        // Get the specific device interface
        deviceInterfaceData.cbSize = sizeof( SP_INTERFACE_DEVICE_DATA );
        if ( !SetupDiEnumDeviceInterfaces( deviceInfo, &deviceInfoData, DeviceGuid, 0, &deviceInterfaceData ) )
        {
            result = HRESULT_FROM_WIN32( GetLastError( ) );
        }
    
        // Check the size needed for the device interface details and 
        // allocate the data needed to get the details
        if ( SUCCEEDED( result ) &&
            !SetupDiGetDeviceInterfaceDetail( deviceInfo, 
                &deviceInterfaceData, NULL, 0, &requiredLength, NULL ) ) 
        {
            if ( GetLastError( ) == ERROR_INSUFFICIENT_BUFFER && 
              requiredLength > 0 )
            {
                interfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA )LocalAlloc( LPTR, (SIZE_T) requiredLength );
                if ( interfaceDetailData == NULL ) 
    	    { 
    	        result = E_OUTOFMEMORY;
    	    }
    	    else
    	    {
    	        result = S_OK;
                }
             }
             else
             {
                  result = HRESULT_FROM_WIN32( GetLastError( ) );
              }
         }
    }


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    Sunday, July 9, 2017 4:44 PM
  • Thank you very much. Do you also have a code for finding a device by VID and PID?
    Monday, July 10, 2017 9:32 PM
  • Unfortunately, no I haven't worried about VID / PID except in the INF file.


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    Monday, July 10, 2017 9:34 PM
  • for each interface you find, you can get the hardware IDs. If the enumerator is USB, you can parse the VID and PID out of the hardware. For instance, my USB mouse reports

    USB\VID_045E&PID_0029&REV_0108
    USB\VID_045E&PID_0029

    d


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

    Tuesday, July 11, 2017 5:29 PM
  • I just got down to trying the code and unfortunately, I noticed that this code works by Device Interface GUID. This code doesn't work with a class GUID which is what I was having trouble with.
    Tuesday, July 11, 2017 10:01 PM
  • you don't enumerate instances of the class GUID. A class GUID is not an IO contract. A class guid is just a visual grouping of devices and perhaps default policy (secure open, an SDDL applied, etc). The truly interesting things are the device interface instances. 

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

    Wednesday, July 12, 2017 1:47 AM