# USB驱动 **Repository Path**: mzsapi/usb-driver ## Basic Information - **Project Name**: USB驱动 - **Description**: 基于vs2017和wdk10开发usb驱动,配套配置文档、说明文档。难度系数高 - **Primary Language**: C++ - **License**: ISC - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-08-10 - **Last Updated**: 2025-08-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: usb驱动 ## README 软件名:USB应用层程序 开发工具:vs2013 wdk: 8.1 工具集: v120 界面:MFC 功能描述: 自动获取windows端USB设备列表,获取设备接口等详细信息。 具体函数功能请查看微软api文档。 基于 WinDDK_7600.16385.1 的UsbView,需要安装wdk8.1。 doc内为vs2017配合wdk10.0的驱动开发环境配置文档。 驱动开发建议采用虚拟机进行测试,驱动开发属于内核级开发,程序崩溃会引发蓝屏死机。 USBVIEW SUMMARY Usbview.exe is a Windows GUI application that allows you to browse all USB controllers and connected USB devices on your system. The left pane in the main application window displays a connection-oriented tree view, and the right pane displays the USB data structures pertaining to the selected USB device, such as the Device, Configuration, Interface, and Endpoint Descriptors, as well as the current device configuration. This functional application sample demonstrates how a user-mode application can enumerate USB host controllers, USB hubs, and attached USB devices, and query information about the devices from the registry and through USB requests to the devices. The IOCTL calls (see the system include file USBIOCTL.H) demonstrated by this sample include: •IOCTL_GET_HCD_DRIVERKEY_NAME •IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION •IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME •IOCTL_USB_GET_NODE_CONNECTION_INFORMATION •IOCTL_USB_GET_NODE_CONNECTION_NAME •IOCTL_USB_GET_NODE_INFORMATION •IOCTL_USB_GET_ROOT_HUB_NAME BUILDING THE SAMPLE The Usbview sample compiles and links in the standard DDK build environment with Microsoft® Visual C® 6.0 on both X86 and Alpha systems, producing a single executable binary Usbview.exe. Both free and checked versions can be built, with assertion error messages enabled in the checked build to indicate unexpected error conditions. CODE TOUR Files Description Usbview.htm Documentation for this sample (this file) Sources Generic build-compatible sources file for this sample Resource.h ID definitions for GUI controls Usbdesc.h USB descriptor type definitions Usbview.h Main header file for this sample Vndrlist.h List of USB Vendor IDs and vendor names Debug.c Assertion routines for the checked build Devnode.c Routines for accessing DevNode information Dispaud.c Routines for displaying USB audio class device information Display.c Routines for displaying USB device information Enum.c Routines for enumerating host controllers, hubs, and devices Usbview.c Entry point and GUI handling routines Usbview.rc Menu and dialog definitions Split.cur Cursor file Usb.ico Application icon file bang.ico Application icon file hub.ico Application icon file monitor.ico Application icon file port.ico Application icon file makefile DDK build environment makefile Programming Tour The major topics covered in this tour are: •GUI handling routines •Device enumeration routines •Device information display routines The file Usbview.c contains the sample application entry point and GUI handling routines. On entry, the main application window is created, which is actually a dialog box as defined in Usbview.rc. The dialog box consists of a split window with a tree view control on the left side and an edit control on the right side. The routine RefreshTree() is called to enumerate USB host controller, hubs, and attached devices and to populate the device tree view control. RefreshTree() calls the routine EnumerateHostControllers() in Enum.c to enumerate USB host controller, hubs, and attached devices. After the device tree view control has been populated, USBView_OnNotify() is called when an item is selected in the device tree view control. This calls UpdateEditControl() in Display.c to display information about the selected item in the edit control. The file Enum.c contains the routines that enumerate the USB bus and populate the tree view control. The USB device enumeration and information collection process is the main point of this sample application. The enumeration process starts at EnumerateHostControllers() and goes like this: (1) Enumerate Host Controllers and Root Hubs. Host controllers have symbolic link names of the form HCDx, where x starts at 0. Use CreateFile() to open each host controller symbolic link. Create a node in the tree view to represent each host controller. After a host controller has been opened, send the host controller an IOCTL_USB_GET_ROOT_HUB_NAME request to get the symbolic link name of the root hub that is part of the host controller. (2) Enumerate Hubs (Root Hubs and External Hubs). Given the name of a hub, use CreateFile() to open the hub. Send the hub an IOCTL_USB_GET_NODE_INFORMATION request to get info about the hub, such as the number of downstream ports. Create a node in the tree view to represent each hub. (3) Enumerate Downstream Ports. Given a handle to an open hub and the number of downstream ports on the hub, send the hub an IOCTL_USB_GET_NODE_CONNECTION_INFORMATION request for each downstream port of the hub to get info about the device (if any) attached to each port. If there is a device attached to a port, send the hub an IOCTL_USB_GET_NODE_CONNECTION_NAME request to get the symbolic link name of the hub attached to the downstream port. If there is a hub attached to the downstream port, recurse to step (2). Create a node in the tree view to represent each hub port and attached device. USB configuration and string descriptors are retrieved from attached devices in GetConfigDescriptor() and GetStringDescriptor() by sending an IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION() to the hub to which the device is attached. The file Display.c contains routines that display information about selected devices in the application edit control. Information about the device was collected during the enumeration of the device tree. This information includes USB device, configuration, and string descriptors and connection and configuration information that is maintained by the USB stack. The routines in this file simply parse and print the data structures for the device that were collected when it was enumerated. The file Dispaud.c parses and prints data structures that are specific to USB audio class devices.