Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 823471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:57:10+00:00 2026-05-15T02:57:10+00:00

I am using Qt on windows platform. i want to get and display vendor

  • 0

I am using Qt on windows platform.

i want to get and display vendor id and product id of a plugged usb device from my local system.

Below is my full source code to get the vendor id and product id from the usb device.

when i run the my qt application it does not throw me any errors .

so i plug the usb device into the system.

but my print statement displays the result as below

qDebug ()<<pDetData->DevicePath;

i get the result as 0x4

Whether i have any implementation mistakes in my source code ?

if so please guide me what i am doing wrong..

Have i missed out any other functions ?

Is it possible to get the vendor id and product id from the usb device based on my source code .( my implementation of the code ) ?

kindly find my source code below

static GUID GUID_DEVINTERFACE_USB_DEVICE = { 0xA5DCBF10L, 0x6530, 0x11D2, 
    { 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED } };

HANDLE hInfo = SetupDiGetClassDevs(&GUID_DEVINTERFACE_USB_DEVICE,NULL,NULL,
    DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);

if ( hInfo == INVALID_HANDLE_VALUE )    
{    
    qDebug ()<<"invalid";   
}    
else    
{        
    qDebug ()<<"valid handle";    

    SP_DEVINFO_DATA DeviceInfoData;
    DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);

    SP_INTERFACE_DEVICE_DATA Interface_Info;    
    Interface_Info.cbSize = sizeof(Interface_Info);

    BYTE Buf[1024];
    DWORD i;
    DWORD InterfaceNumber= 0;

    PSP_DEVICE_INTERFACE_DETAIL_DATA pspdidd = 
        (PSP_DEVICE_INTERFACE_DETAIL_DATA) Buf;

    for (i=0;SetupDiEnumDeviceInfo(hInfo,i,&DeviceInfoData);i++)
    {
        DWORD DataT;
        LPTSTR buffer = NULL;
        DWORD buffersize = 0;

        while (!SetupDiGetDeviceRegistryProperty( hInfo,
            &DeviceInfoData,
            SPDRP_DEVICEDESC,
            &DataT,
            (PBYTE)buffer,
            buffersize,
            &buffersize))    
         {
            if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
            {
                // Change the buffer size.
                if (buffer) LocalFree(buffer);
                buffer = (LPTSTR)LocalAlloc(LPTR,buffersize);
            }
            else
            {
                // Insert error handling here.
                break;
            }

            qDebug ()<<(TEXT("Device Number %i is: %s\n"),i, buffer);

            if (buffer) LocalFree(buffer);

            if ( GetLastError() != NO_ERROR 
                     && GetLastError() != ERROR_NO_MORE_ITEMS )    
            {
                // Insert error handling here.
                qDebug ()<<"return false";
            }

            InterfaceNumber = 0; // this just returns the first one, you can iterate on this

            if (SetupDiEnumDeviceInterfaces(hInfo,
                                   NULL, 
                                   &GUID_DEVINTERFACE_USB_DEVICE,
                                   InterfaceNumber,
                                   &Interface_Info))
            {
                printf("Got interface");
                DWORD needed;
                pspdidd->cbSize = sizeof(*pspdidd);    
                SP_DEVICE_INTERFACE_DETAIL_DATA *pDetData = NULL;
                DWORD dwDetDataSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA) 
                                      + 256;

                SetupDiGetDeviceInterfaceDetail(hInfo, 
                    &Interface_Info, pDetData,dwDetDataSize, NULL,
                    &DeviceInfoData);

                qDebug ()<<pDetData->DevicePath;
                //qDebug ()<<QString::fromWCharArray(pDetData->DevicePath);
            }
            else
            {    
                printf("\nNo interface");

                //ErrorExit((LPTSTR) "SetupDiEnumDeviceInterfaces");

                if ( GetLastError() == ERROR_NO_MORE_ITEMS) 
                    printf(", since there are no more items found.");
                else 
                    printf(", unknown reason.");

            }
            // Cleanup

            SetupDiDestroyDeviceInfoList(hInfo);
            qDebug ()<<"return true";
        }
    }
}

————— Edited to add: —————–

Hi… the application comes and prints this

\?\usb#vid_04f2&pid_0111#5&1ba5a77f&0&2#{a5dcbf1 0-6530-11d2-901f-00c04fb951ed}

again it goes to while loop …. here it gets breaked in the else statement…

Qt Code:

if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { 
    // Change the buffer size. 
    if (buffer) LocalFree(buffer); 
    buffer = (LPTSTR)LocalAlloc(LPTR,buffersize); 
} else { 
    qDebug ()<<"Here it quits the application"; 
    // Insert error handling here. break; 
} 

Any ideas in this….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:57:10+00:00Added an answer on May 15, 2026 at 2:57 am

    After this line:

    SP_DEVICE_INTERFACE_DETAIL_DATA *pDetData = NULL;
    

    Add this:

    DWORD dwDetDataSize = sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA) + 256;
    pDetData = (_SP_DEVICE_INTERFACE_DETAIL_DATA_A*) malloc (dwDetDataSize);
    pDetData->cbSize = sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA);
    

    After this line:

    qDebug ()<<pDetData->DevicePath;
    

    Add this:

    free(pDetData);
    

    But eventually you’re going to have to read the docs for SetupDiGetDeviceInterfaceDetail(). Do it, there are lots of functions that work like this, with pointers to variable-size structs.

    ——– Edited to add: ——–

    You’re really going about this the wrong way. I see you’re following the advice you got here, and it’s taken you down the wrong path. idVendor and idProduct can only be found in the USB_DEVICE_DESCRIPTOR (MSDN).

    It looks like you already know how to get the device handle (using CreateFile()). After that, you call WinUsb_Initialize() (MSDN). That gets you a WINUSB_INTERFACE_HANDLE.

    Once you have that handle, you want to call WinUsb_GetDescriptor() (MSDN), with the DescriptorType set to URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE. I can’t test code now, but it will look something like this:

    USB_DEVICE_DESCRIPTOR udd;
    memset(&udd, 0, sizeof(udd));
    ULONG LengthTransferred = 0;
    
    WinUsb_GetDescriptor(
        winusb_interface_handle, // returned by WinUsbInitialize
        URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE,
        0,     // not sure if we need this
        0x409, // not sure if we need this
        &udd,
        sizeof(udd),
        &LengthTransferred);
    

    After that, udd->idVendor and udd->idProduct should have what you want.

    Microsoft used to supply sample code for all this in the DDK, and probably still does, but I don’t have access to one.

    ———- Edited to add: ———-

    Daniel K writes that the code should really be:

    USB_DEVICE_DESCRIPTOR udd;
    memset(&udd, 0, sizeof(udd));
    ULONG LengthTransferred = 0;
    
    WinUsb_GetDescriptor(
        winusb_interface_handle,    // returned by WinUsbInitialize
        USB_DEVICE_DESCRIPTOR_TYPE, // Daniel K's suggestion
        0,
        0x409,     // asks for English
        &udd,
        sizeof(udd),
        &LengthTransferred);
    

    See the comments for further details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to stream an audio from server using windows phone 7 the audio
I want to migrate sourcecode from SVN to TFS2010 using the TFS Integration Platform.
Using unmanaged C++ on a Windows platform, is there a simple way to detect
I am using PIL 1.1.6, Python 2.5 on the Windows platform. In my program,
I have installed Qt for windows CE using this link http://qt.nokia.com/products/platform/qt-for-windows-ce for visual studio8,
Using Windows So I'm reading from a binary file a list of unsigned int
Using Windows Mobile 6.5 and C# The CharacterCasing property seems to be missing from
Using Windows form (Vb.net & Datagridview) Checkbox is using in datagridview row. I want
How do I get the UTC time in milliseconds under the Windows platform? I
Using system() or exec() , I can get any command to execute but they

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.