Author Name: Generation Winter Army Email Address: Daisun1998@163.net
Author's self-introduction: fan of VC.
Code download
Development environment: VC6 WindowsXP DDK Test Environment: WindowsXP
Use license: code is free
Explanation: Features: There are many USB devices now, so you must not be less than the lookup of USB devices. But you can find less information about USB read and write. The use of VC demonstrate some methods for obtaining USB information.
A $b device
Enumerate the USB controller -> enumerate the USB HUB-> enumerated HUB's ports -> obtain device information. Enumerate the controller. The USB main controller on the computer is named by HCD1, HCD2, etc. With the controller name, open it with CCREATEFILE. Use DeviceioControl to get its driver name, and the name of the HUB connected to it. Use ccreatefile to open the HUB to get connection information. Another port of the HUB can be enumerated to obtain the connected device information.
Two HID equipment
The HID device is a standard human interface specification defined by Microsoft. For example, a USB mouse, a USB game handle, etc. You don't have to find the GUID of the specific device, you can get the GUID using the API Hidd_GethidGuid (& GUIDHID). There is a GUID to get a device connection if you have a device connection via API SetupdienumDeviceInterface. If this type of device is connected to get its device path information via SetupdiGetDeviceInterfaceTail. Use ccreatefile to open it, get its basic attribute information via HIDD_GETATTRIBUTES. Use DeviceioControl to get more detailed properties. If the USB game handle is inserted on this code, its information can be obtained. But I don't know why XP can't get information about USB mouse.
Three raise U disk
First get the type of device with the GetDriveType API. If the type of REMOVABLE (of course, some large capacity U disk may report to fixed, then other methods can be determined), that is, the U disk. After opening with CCREATEFILE, use ioctl_storage_query_property to get its properties for DeviceIoControl of the parameter.
Conclusion:
The sample project is compiled under WinXP XPDDK VC6.
There are many types of USB equipment, but also more special, different manufacturers' hardware, control software is not the same (I think it is mainly ICTL code, it is not easy to find). Make the equipment that access the USB port is not as convenient to the serial port. This routine only shows the basic method of access. There are still some questions that have not been resolved, and I hope that everyone can notify me or publish it.
Some key code
WSPrintf (hcname, ".//hcd%D", hcnum);
HHCDEV = CREATEFILE (HcName,
Generic_Write,
File_share_write,
NULL,
Open_EXISTING,
0,
NULL);