1

I am currently using the DeviceIOControl API from kernel32.dll to get the String Descriptors of the list of connected USB devices.

public static String GetStringDescriptor(IntPtr deviceHandle, Int32 ConnectionIndex, Byte DescriptorIndex, UInt16 LanguageID)
    {        
        USB_DESCRIPTOR_REQUEST Buffer = new USB_DESCRIPTOR_REQUEST();
        Buffer.ConnectionIndex = ConnectionIndex;
        Buffer.SetupPacket.wValue = (UInt16)((USB_STRING_DESCRIPTOR_TYPE << 8) | DescriptorIndex);
        Buffer.SetupPacket.wIndex = LanguageID;
        Buffer.SetupPacket.wLength = MAXIMUM_USB_STRING_LENGTH;
        Int32 nBytesReturned;
        Boolean Status = DeviceIoControl(deviceHandle,
                IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION,
                ref Buffer,
                Marshal.SizeOf(Buffer),
                ref Buffer,
                Marshal.SizeOf(Buffer),
                out nBytesReturned,
                IntPtr.Zero);
        if (Status)
            return Buffer.Data.bString;
        else
            return null;
    }

We use this function to get the descriptor details such as Language ID, Serial number, Manufacturer and Product String. Only while requesting the Serial Number, the Status returned is TRUE and we get the expected values. But the status returns false for Language id, manufacturer and Product string.

I checked the error status returned by the DeviceIoControl using:

int error = Marshal.GetLastWin32Error();

It returns 31 as the error code which means that the Device is not working properly/ the driver for the device is not properly installed.

I tried all the obvious solutions like reinstalling the driver for the device and restarting the PC etc., but none seems to work. I am sure there are no issues in the device or the code because it works flawlessly in windows 7 PCs. Also, since I am able to get the serial number, I think the device handle is also proper.

I am not able to proceed with any further debugging. Is there some update to the DeviceIoControl function in Windows 10? Or is the way to get the languageID, manufacturer and Product String changed in Windows 10?

Niranjan
  • 330
  • 1
  • 2
  • 13

1 Answers1

0

Most probably the device you are trying to get string descriptors from is in low power state. Check its current power state first, and if it differs from "PowerDeviceD0" - string descriptors may not be obtained (depending on device, actually, and actual power state level D1, D2, D3). This could be the cause of error code 31 from DeviceIOControl().

Try to wake the device first or get some stored strings with SetupAPI.

Vladimir Afinello
  • 1,211
  • 14
  • 16