Home > Software engineering >  MFC enumeration HID USB communication equipment appeared a lot of VID and PID
MFC enumeration HID USB communication equipment appeared a lot of VID and PID

Time:09-21

Doing a usb communication engineering recently, search the information, is probably HID writing of such equipment,

The enumeration of USB device function following

 m_combobox. ResetContent (); 
SP_DEVINFO_DATA DeviceInfoData;
SP_DEVICE_INTERFACE_DATA DeviceInterfaceData;
PSP_DEVICE_INTERFACE_DETAIL_DATA DeviceInterfaceDetailData;
//get the device id
GUID deviceId;

HidD_GetHidGuid (& amp; DeviceId);
//get device info
HDEVINFO handle;
Handle=SetupDiGetClassDevs (& amp; DeviceId, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);

Bool result1=false;
Bool result2=false;
DWORD strSize=0;
DWORD requiredSize=0;
Cstrings temp.
Int countNum=0;
DWORD dwError;
Do
{
DeviceInterfaceData. CbSize=sizeof (SP_DEVICE_INTERFACE_DATA);
Result1=SetupDiEnumDeviceInterfaces (the handle, NULL, & amp; DeviceId countNum, & amp; DeviceInterfaceData);
If (result1==FALSE)
{
DwError=GetLastError ();
break;

}
SetupDiGetDeviceInterfaceDetail (handle, & amp; DeviceInterfaceData, NULL, 0, & amp; StrSize, NULL);
RequiredSize=strSize;
DeviceInterfaceDetailData=https://bbs.csdn.net/topics/(PSP_DEVICE_INTERFACE_DETAIL_DATA) malloc (requiredSize);
DeviceInterfaceDetailData - & gt; The cbSize=sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA);
DeviceInfoData. CbSize=sizeof (SP_DEVINFO_DATA);
Result2=SetupDiGetDeviceInterfaceDetail (handle, & amp; DeviceInterfaceData DeviceInterfaceDetailData,
StrSize, & amp; RequiredSize, & amp; DeviceInfoData);
Temp=DeviceInterfaceDetailData - & gt; DevicePath;
The UpdateData (FALSE);
M_combobox. AddString (temp);
CountNum++;
Free (DeviceInterfaceDetailData);
} while (result1);


M_combobox is a combobox button bound variables,

This code can enumerate out equipment, only the results I'm a little don't understand.


The vid and pid, the first is my keyboard, the following is the human input in the device manager learn equipment and universal serial bus (usb) controller,
What I want is the keyboard, the code where there is a problem?

CodePudding user response:

enumeration match VID PID HID device, and returns the device path

CodePudding user response:

I saw this enumeration, no difference to me, I want to know why there will be a heap of vid and pid are exactly the same equipment? These devices also can be found in the device manager? What is this principle?

CodePudding user response:

Is a laptop, mouse and keyboard touchpad, and so on, there are so many HID device is normal ah

CodePudding user response:

Learn to use the devcon?

CodePudding user response:

reference kangji reply: 3/f
is a laptop, mouse and keyboard touchpad, and so on, there are so many HID device is normal ah

Is a desktop computer, insert the usb wireless keyboard, if I want to talk to the HID class of usb device communications what should I do?

CodePudding user response:

reference 4 floor zhao4zhong1 response:
devcon learn to use?


I want to use MFC, to provide users with interface,

CodePudding user response:

refer to 6th floor wangyiyu3 response:
Quote: refer to 4th floor zhao4zhong1 response:

Learn to use the devcon?


I want to use MFC, to provide users with interface,

It seems that you won't be in the MFC environment using
WinExec (" CMD/c devcon. Exe... & gt; Devcon. TXT ", SW_HIDE);
The contents of the//and then read file devcon. TXT
This kind of method call devcon. Exe,

CodePudding user response:


Int CTestapiDlg: : JudgeHid (void)
{
BOOL res;
Int finddevice=0;
//Windows objects for interacting with the driver.
Xf16f x4d1e55b2 GUID InterfaceClassGuid={0, 0, 0 x11cf, {XCB 0 x88, 0, 0 x00 to 0 x11, x11, 0 0 x00 to 0 x00 to 0 x30}};
SP_DEVINFO_DATA devinfo_data;
SP_DEVICE_INTERFACE_DATA device_interface_data;
SP_DEVICE_INTERFACE_DETAIL_DATA_A * device_interface_detail_data=https://bbs.csdn.net/topics/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 (& amp; InterfaceClassGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);

//to Iterate over each device in the HID class, & a for the right one.

For (;; ) {
HANDLE write_handle=INVALID_HANDLE_VALUE;
DWORD required_size=0;
//HIDD_ATTRIBUTES attrib;

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
//the size is put in & amp; Required_size.
Res=SetupDiGetDeviceInterfaceDetail (device_info_set,
& Device_interface_data,
NULL,
0,
& Required_size,
NULL);

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related