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!