在此前应首先调用三个函数:
1.SetupDiGetClassDevs()
例://Get a list of devices matching the criteria (hid interface, present)
hardwareDeviceInfoSet = SetupDiGetClassDevs (&hidGUID,
NULL, // Define no enumerator (global)
NULL, // Define no
(DIGCF_PRESENT ¦ // Only Devices present
DIGCF_DEVICEINTERFACE)); // Function class devices.
2.SetupDiEnumDeviceInterfaces()
例://Go through the list and get the interface data//枚举设备
result = SetupDiEnumDeviceInterfaces (hardwareDeviceInfoSet,
NULL, //infoData,
&hidGUID, //interfaceClassGuid,
deviceIndex,
&deviceInterfaceData);
3.SetupDiGetDeviceInterfaceDetail()
例://Get the details with null values to get the required size of the buffer//获detaildata结构数组的长度SetupDiGetDeviceInterfaceDetail (hardwareDeviceInfoSet,
&deviceInterfaceData,
NULL, //interfaceDetail,
0, //interfaceDetailSize,
&requiredSize,
0); //infoData))
然后再调用一次SetupDiGetDeviceInterfaceDetail获得具体细节
此外,Get_att_capab()可以通过PID和VID找到合适的设备
然后用Createfile打开设备
//Open file on the device
deviceHandle = CreateFile (deviceDetail->DevicePath,
GENERIC_READ ¦ GENERIC_WRITE,
FILE_SHARE_READ ¦ FILE_SHARE_WRITE,
NULL, // no SECURITY_ATTRIBUTES structure
OPEN_EXISTING, // No special create flags
0,
NULL); // No template file