How to obtain the product ID and vendor ID of a USB device in VC?

Source: Internet
Author: User

Void cgetudiskdriverdlg: searchudisk ()
{
Int ncount, Len; // mark the number of the same device
Hdevinfo hdevinfoset;
Bool bresult;
Char * devicename;
Char volume [max_path];
Char ch [100];

Memset (volume, 0, max_path );

Psp_device_interface_detail_data pdetail = NULL;

// Obtain a guid-related device information set handle
Hdevinfoset =: setupdigetclassdevs (lpguid) & harddisk_guid, // guid_class_usb_device, // class guid
Null, // No keyword
Null, // do not specify the parent window handle
Digcf_present using digcf_deviceinterface); // The Current Device

// Failed...
If (hdevinfoset = invalid_handle_value)
{
Return;
}

// Request device interface Data Space

Ncount = 0;
Bresult = true;

Sp_device_interface_data ifdata;
// Device No. =, 2... test the device interfaces one by one until the device fails.
While (bresult)
{

Ifdata. cbsize = sizeof (ifdata );
// Enumerate the device interfaces that match the guid
Bresult =: setupdienumdeviceinterfaces (
Hdevinfoset, // handle of the device information set
Null, // No additional device description required
(Lpguid) & harddisk_guid, // guid_class_usb_device, // guid
(Ulong) ncount, // device serial number in the device information set
& Ifdata); // Device Interface Information

If (bresult)
{
Ulong predictedlength = 0;
Ulong requiredlength = 0;
// Obtain the device interface details (device path)
Bresult = setupdigetinterfacedevicedetail (
Hdevinfoset, // handle of the device information set
& Ifdata, // Device Interface Information
Null, // Device Interface Details (device path)
0, // output buffer size
& Requiredlength, // The output buffer size does not need to be calculated (set value directly)
Null); // No additional device description required
// Obtain the device interface details (device path)
Predictedlength = requiredlength;

// If (pdetail)
//{
// Pdetail = NULL;
//}
Pdetail = (psp_interface_device_detail_data): globalalloc (lmem_zeroinit, predictedlength );
Pdetail-> cbsize = sizeof (sp_device_interface_detail_data );
Bresult = setupdigetinterfacedevicedetail (
Hdevinfoset, // handle of the device information set
& Ifdata, // Device Interface Information
Pdetail, // Device Interface Details (device path)
Predictedlength, // output buffer size
& Requiredlength, // The output buffer size does not need to be calculated (set value directly)
Null); // No additional device description required

If (bresult)
{
// Copy the device path to the output buffer
For (INT I = 0; I <17; I ++ ){
Ch [I] = * (pdetail-> devicepath + 8 + I );
}
Ch [17] = "/0 ";
If (strcmp (CH, "vid_11dd & pid_0101") = 0 then quit
Strcmp (CH, "vid_11dd & pid_11dd") = 0 commandid
Strcmp (CH, "vid_0101 & pid_0101") = 0 commandid
Strcmp (CH, "vid_0101 & pid_11dd") = 0) // compare the version to prevent unexpected errors
{
Len = strlen (pdetail-> devicepath );
Devicename = new char [Len];
Memset (devicename, 0, Len );
For (INT I = 0; I <(len-38); I ++)
{
Ch [I] = * (pdetail-> devicepath + I );
}
Ch[ len-38] = "/0 ";
Memset (volume, 0, max_path );
}
}
}
Ncount ++;
}
// Release the device interface Data Space
: Globalfree (pdetail );

// Close the device information set handle
: Setupdidestroydeviceinfolist (hdevinfoset );
}

Take the time to verify it!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.