sparkyfx
sparkyfx

Reputation: 11

how to get vendor id and pid of usb device in qt on windows?

I'm using qt on Windows. My program need to know vendor id and product id of plugged usb flash drive.

I was trying to implement example from this topic, but I'm getting segmentation fault on WinUsb_Initialize function.

This is my code:

HANDLE hDevice = CreateFileA("\\\\.\\PhysicalDrive1", GENERIC_WRITE | GENERIC_READ ,
     FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);

if(hDevice == INVALID_HANDLE_VALUE)
{
    qDebug() << "hDevice - INVALID_HANDLE_VALUE";
}
else
{
    qDebug() << "hDevice handle ok";
    PWINUSB_INTERFACE_HANDLE phWinUSBHandle;
    BOOL result = false;
    result = WinUsb_Initialize(hDevice, phWinUSBHandle); //seg
}

I need phWinUSBHandle to use WinUsb_GetDescriptor function.

I'll be very grateful for any help. Maybe someone knows some alternative way to get vendor id and product id in windows?

Upvotes: 1

Views: 1755

Answers (1)

Mandar Pande
Mandar Pande

Reputation: 12994

Have you referred libusb library ? It might help you.

Upvotes: 1

Related Questions