阅读:1009回复:0
急求救:一段显示USB设备信息的C++程序
这是一段显示USB设备信息的C++程序:
void CTestUSBDlg::ShowCenctInfo(PUSB_NODE_CONNECTION_INFORMATION connectionInfo) { ShowMessage(strShow); strShow.Format(\"Connect index:[port:%d]\\r\\n\", connectionInfo->ConnectionIndex); ShowMessage(strShow); strShow.Format(\"Device Class:0x%X\\r\\n VenderID:0x%X\\r\\n ProductID:0x%X\\r\\n\", connectionInfo->DeviceDescriptor.bDeviceClass, connectionInfo->DeviceDescriptor.idVendor, connectionInfo->DeviceDescriptor.idProduct); ShowMessage(strShow); strShow.Format(\"iManufacturer:0x%X\\r\\n iSerialNumber:0x%X\\r\\n\", connectionInfo->DeviceDescriptor.iManufacturer, connectionInfo->DeviceDescriptor.iSerialNumber); ShowMessage(strShow); if(connectionInfo->LowSpeed) strShow=\"Bus Speed: low\\r\\n\"; else strShow=\"Bus Speed: full\\r\\n\"; ShowMessage(strShow); strShow.Format(\"Device Address:0x%X\\r\\n Open Pipes:0x%X\\r\\n\", connectionInfo->DeviceAddress, connectionInfo->NumberOfOpenPipes); ShowMessage(strShow); } 其中函数的变量connectionInfo,PUSB_NODE_CONNECTION_INFORMATION这个类是在usbioctl.h里定义的,原文如下: typedef struct _USB_NODE_CONNECTION_INFORMATION { ULONG ConnectionIndex; /* usb device descriptor returned by this device during enumeration */ USB_DEVICE_DESCRIPTOR DeviceDescriptor; UCHAR CurrentConfigurationValue; BOOLEAN LowSpeed; BOOLEAN DeviceIsHub; USHORT DeviceAddress; ULONG NumberOfOpenPipes; USB_CONNECTION_STATUS ConnectionStatus; USB_PIPE_INFO PipeList[0]; } USB_NODE_CONNECTION_INFORMATION, *PUSB_NODE_CONNECTION_INFORMATION; USB_NODE_CONNECTION_INFORMATION中的USB_DEVICE_DESCRIPTOR是在usb100.h里定义的,原文如下: typedef struct _USB_DEVICE_DESCRIPTOR { UCHAR bLength; UCHAR bDescriptorType; USHORT bcdUSB; UCHAR bDeviceClass; UCHAR bDeviceSubClass; UCHAR bDeviceProtocol; UCHAR bMaxPacketSize0; USHORT idVendor; USHORT idProduct; USHORT bcdDevice; UCHAR iManufacturer; UCHAR iProduct; UCHAR iSerialNumber; UCHAR bNumConfigurations; } USB_DEVICE_DESCRIPTOR, *PUSB_DEVICE_DESCRIPTOR; 例如,插上USB设备后运行,最后在文本框里的显示结果是这样: Connect index:[port:1] Device Class:0x0 VenderID:0x6FF ProductID:0x8000 iManufacturer:0x1 iSerialNumber:0x3 Bus Speed:full Device Address:0x1 Open Pipes:0x2 我不懂的地方就是以上每项信息对应的变量的具体内容,为什么差不多都是16进制的1位数字呢? 这些数字具体代表什么意思呢?比如说Device Class:0x0代表什么类型的USB设备呢?iManufacturer:0x1代表哪个制造商呢? 我是想将USB设备信息显示出来,让一般人能看得懂,但这些16进制数代表的意思实在不知道,我没法去转化。 想请大家帮帮忙给我解释一下每一项信息的意思,或者分析一下上述2个类的每个变量的具体意义。非常感谢! |
|