int CTestapiDlg::JudgeHid(void)
{
BOOL res;
int finddevice=0;
// Windows objects for interacting with the driver.
GUID InterfaceClassGuid = {0x4d1e55b2, 0xf16f, 0x11cf, {0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30} };
SP_DEVINFO_DATA devinfo_data;
SP_DEVICE_INTERFACE_DATA device_interface_data;
SP_DEVICE_INTERFACE_DETAIL_DATA_A *device_interface_detail_data = NULL;
HDEVINFO device_info_set = INVALID_HANDLE_VALUE;
int device_index = 0;
// Initialize the Windows objects.
devinfo_data.cbSize = sizeof(SP_DEVINFO_DATA);
device_interface_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
// Get information for all the devices belonging to the HID class.
device_info_set = SetupDiGetClassDevs(&InterfaceClassGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
// Iterate over each device in the HID class, looking for the right one.
res = SetupDiEnumDeviceInterfaces(device_info_set,
NULL,
&InterfaceClassGuid,
device_index,
&device_interface_data);
if (!res) {
// A return of FALSE from this function means that
// there are no more devices.
break;
}
// Call with 0-sized detail size, and let the function
// tell us how long the detail struct needs to be. The
// size is put in &required_size.
res = SetupDiGetDeviceInterfaceDetail(device_info_set,
&device_interface_data,
NULL,
0,
&required_size,
NULL);
// Allocate a long enough structure for device_interface_detail_data.
device_interface_detail_data = (SP_DEVICE_INTERFACE_DETAIL_DATA_A*) malloc(required_size);
device_interface_detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A);
// Get the detailed data for this device. The detail data gives us
// the device path for this device, which is then passed into
// CreateFile() to get a handle to the device.
res = SetupDiGetDeviceInterfaceDetail(device_info_set,
&device_interface_data,
device_interface_detail_data,
required_size,
NULL,
NULL);
if (!res) {
//register_error(dev, "Unable to call SetupDiGetDeviceInterfaceDetail");
// Continue to the next device.
goto cont;
}
cont:
// We no longer need the detail data. It can be freed
free(device_interface_detail_data);
device_index++;
}
// Close the device information handle.
SetupDiDestroyDeviceInfoList(device_info_set);
return finddevice;
}
uj5u.com熱心網友回復:
int CTestapiDlg::JudgeHid(void)
{
BOOL res;
int finddevice=0;
// Windows objects for interacting with the driver.
GUID InterfaceClassGuid = {0x4d1e55b2, 0xf16f, 0x11cf, {0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30} };
SP_DEVINFO_DATA devinfo_data;
SP_DEVICE_INTERFACE_DATA device_interface_data;
SP_DEVICE_INTERFACE_DETAIL_DATA_A *device_interface_detail_data = NULL;
HDEVINFO device_info_set = INVALID_HANDLE_VALUE;
int device_index = 0;
// Initialize the Windows objects.
devinfo_data.cbSize = sizeof(SP_DEVINFO_DATA);
device_interface_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
// Get information for all the devices belonging to the HID class.
device_info_set = SetupDiGetClassDevs(&InterfaceClassGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
// Iterate over each device in the HID class, looking for the right one.
res = SetupDiEnumDeviceInterfaces(device_info_set,
NULL,
&InterfaceClassGuid,
device_index,
&device_interface_data);
if (!res) {
// A return of FALSE from this function means that
// there are no more devices.
break;
}
// Call with 0-sized detail size, and let the function
// tell us how long the detail struct needs to be. The
// size is put in &required_size.
res = SetupDiGetDeviceInterfaceDetail(device_info_set,
&device_interface_data,
NULL,
0,
&required_size,
NULL);
// Allocate a long enough structure for device_interface_detail_data.
device_interface_detail_data = (SP_DEVICE_INTERFACE_DETAIL_DATA_A*) malloc(required_size);
device_interface_detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A);
// Get the detailed data for this device. The detail data gives us
// the device path for this device, which is then passed into
// CreateFile() to get a handle to the device.
res = SetupDiGetDeviceInterfaceDetail(device_info_set,
&device_interface_data,
device_interface_detail_data,
required_size,
NULL,
NULL);
if (!res) {
//register_error(dev, "Unable to call SetupDiGetDeviceInterfaceDetail");
// Continue to the next device.
goto cont;
}
cont:
// We no longer need the detail data. It can be freed
free(device_interface_detail_data);
device_index++;
}
// Close the device information handle.
SetupDiDestroyDeviceInfoList(device_info_set);
return finddevice;
}
GUID InterfaceClassGuid這個值是怎么來的?代表什么?
uj5u.com熱心網友回復:
int CTestapiDlg::JudgeHid(void)
{
BOOL res;
int finddevice=0;
// Windows objects for interacting with the driver.
GUID InterfaceClassGuid = {0x4d1e55b2, 0xf16f, 0x11cf, {0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30} };
SP_DEVINFO_DATA devinfo_data;
SP_DEVICE_INTERFACE_DATA device_interface_data;
SP_DEVICE_INTERFACE_DETAIL_DATA_A *device_interface_detail_data = NULL;
HDEVINFO device_info_set = INVALID_HANDLE_VALUE;
int device_index = 0;
// Initialize the Windows objects.
devinfo_data.cbSize = sizeof(SP_DEVINFO_DATA);
device_interface_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
// Get information for all the devices belonging to the HID class.
device_info_set = SetupDiGetClassDevs(&InterfaceClassGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
// Iterate over each device in the HID class, looking for the right one.
res = SetupDiEnumDeviceInterfaces(device_info_set,
NULL,
&InterfaceClassGuid,
device_index,
&device_interface_data);
if (!res) {
// A return of FALSE from this function means that
// there are no more devices.
break;
}
// Call with 0-sized detail size, and let the function
// tell us how long the detail struct needs to be. The
// size is put in &required_size.
res = SetupDiGetDeviceInterfaceDetail(device_info_set,
&device_interface_data,
NULL,
0,
&required_size,
NULL);
// Allocate a long enough structure for device_interface_detail_data.
device_interface_detail_data = (SP_DEVICE_INTERFACE_DETAIL_DATA_A*) malloc(required_size);
device_interface_detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A);
// Get the detailed data for this device. The detail data gives us
// the device path for this device, which is then passed into
// CreateFile() to get a handle to the device.
res = SetupDiGetDeviceInterfaceDetail(device_info_set,
&device_interface_data,
device_interface_detail_data,
required_size,
NULL,
NULL);
if (!res) {
//register_error(dev, "Unable to call SetupDiGetDeviceInterfaceDetail");
// Continue to the next device.
goto cont;
}