Libusb
Author: e | 2025-04-24
libusb-1.0 API Reference. libusb uses the underlying libusb C shared library as specified in libusb.cfg (included libusb-X.X. is the default), but there is also ability to specify it programmatically by one of the following ways:. import libusb libusb. config (LIBUSB = libusb C shared library absolute path ) or libusb. config (LIBUSB = None) included libusb-X.X. will
libusb/libusb-1.0.pc.in at master libusb/libusb - GitHub
Table of ContentsOverviewAboutBinary Snapshotsvcpkg portmsys2 MinGW-w64 32bit/64bit packageBuild from SourceSupported EnvironmentsUSB 3.x Support.NET supportHow to use libusb on WindowsDriver InstallationDevelopment ConsiderationsKnown RestrictionsDevelopment LinksOverviewAboutThis page details the specifics of the Windows backend part of libusb, which helps developers easily communicate with USB devices on Windows.Currently it supports the WinUSB and HID drivers for generic USB device access as well as the libusb-win32 and libusbK drivers.Please note that libusb-win32 and libusbK are separate projects. libusb-win32 is a Windows-only project which provides a libusb-0.1 API compatible library for Windows and the associated kernel driver libusb0.sys. libusbK is a Windows only project which provides a new set of API for Windows (supporting WinUSB, libusb0.sys and libusbk.sys) and kernel driver libusbK.sys.Binary SnapshotsPre-built binary snapshots are provided in the Sourceforge files directory along with the source code archive. Since 1.0.21 release, they are also at the GitHub release page.The pre-built Windows binaries are provided AS IS for your convenience, generated for the following environments:Microsoft Visual Studio; MS32 (32 bit) and MS64 (64 bit) directoriesMinGW -> MinGW32 (32 bit) and MinGW64 (64 bit) directories. Note that these archives are provided in the 7z format so you may have to install 7-zip.vcpkg portvcpkg now includes libusb ports.Installing and building libusb via vcpkg:You can download and install libusb using the vcpkg dependency manager: git clone cd vcpkg .\bootstrap-vcpkg.bat .\vcpkg integrate install .\vcpkg install libusbThe libusb port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.msys2 MinGW-w64 32bit/64bit packagemsys2 has a libusb package. Please contact the msys2 project if you encountered issues with the msys2 package. It is recommended to use pkg-config (libusb-1.0.pc) on MSYS2 or other MinGW-w64 distributions. Reference: how to use libusb under MinGW-w64?Build from. libusb-1.0 API Reference. libusb uses the underlying libusb C shared library as specified in libusb.cfg (included libusb-X.X. is the default), but there is also ability to specify it programmatically by one of the following ways:. import libusb libusb. config (LIBUSB = libusb C shared library absolute path ) or libusb. config (LIBUSB = None) included libusb-X.X. will libusb-1.0 API Reference. libusb uses the underlying libusb C shared library as specified in libusb.cfg (included libusb-X.X. is the default), but there is also ability to specify it programmatically by one of the following ways:. import libusb libusb. config (LIBUSB = libusb C shared library absolute path ) or libusb. config (LIBUSB = None) included libusb-X.X. will libusb uses the underlying libusb C shared library as specified in libusb.cfg (included libusb-X.X. is the default), but there is also ability to specify it programmatically by one of the following ways: import libusb libusb. config (LIBUSB = libusb C shared library absolute path ) or libusb. config (LIBUSB = None) included libusb-X.X Download libusb-win32 for free. libusb-win32 is a port of libusb-0.1 under Windows. libusb-win32 is a port of the USB library libusb-0.1 Download libusb-win32 for free. libusb-win32 is a port of libusb-0.1 under Windows. libusb-win32 is a port of the USB library libusb-0.1 ( SourceYou may want to build from source if you encounter compatibility issues with the pre-built binaries. We recommend either Visual Studio or a MinGW-w64 based toolchain like MSYS2. Note that the MinGW.org toolchain is not supported. clang support patches are welcome. Patches to add support for other toolchains (including MinGW.org) may be accepted after review even though these toolchains are not officially supported. Supported EnvironmentsSupported systems are all Windows platforms, starting with Windows Vista, and including 64 bit versions. Windows XP support was dropped in libusb 1.0.24.USB 3.x Supportlibusb supports USB 3.x controllers and devices on Windows. Proprietary vendor controller drivers for Windows 7 and earlier as well as the Microsoft controller xHCI driver for Windows 8/8.1/10 are supported. If you are are using Windows 7 or earlier version, you will be using vendor driver. Make sure you upgrade to the latest version of the driver if you encounter problems. .NET supportA .NET version of libusb, called LibUsbDotNet, based on libusb 1.0. If you plan to use libusb in a .NET project, make sure you check out the latest release at github.How to use libusb on WindowsDriver InstallationIf your target device is not HID, and your device is not using WinUSB driver, you must install a driver before you can communicate with it using libusb. Currently, this means installing one of Microsoft's WinUSB, libusb-win32 or libusbK drivers. Two options are available:Recommended: Use the most recent version of Zadig, an Automated Driver Installer GUI application for WinUSB (recommended), libusbK (only if you hit WinUSB limitations) and libusb-win32 (only if you hit WinUSB/libusbK limitations).For version 1.0.21 or later, you can also use the usbdk backend. usbdk provides another driver option for libusb Windows backend. For 1.0.21, usbdk is a compile-time option, but it becomes a runtime option from version 1.0.22 onwards, soComments
Table of ContentsOverviewAboutBinary Snapshotsvcpkg portmsys2 MinGW-w64 32bit/64bit packageBuild from SourceSupported EnvironmentsUSB 3.x Support.NET supportHow to use libusb on WindowsDriver InstallationDevelopment ConsiderationsKnown RestrictionsDevelopment LinksOverviewAboutThis page details the specifics of the Windows backend part of libusb, which helps developers easily communicate with USB devices on Windows.Currently it supports the WinUSB and HID drivers for generic USB device access as well as the libusb-win32 and libusbK drivers.Please note that libusb-win32 and libusbK are separate projects. libusb-win32 is a Windows-only project which provides a libusb-0.1 API compatible library for Windows and the associated kernel driver libusb0.sys. libusbK is a Windows only project which provides a new set of API for Windows (supporting WinUSB, libusb0.sys and libusbk.sys) and kernel driver libusbK.sys.Binary SnapshotsPre-built binary snapshots are provided in the Sourceforge files directory along with the source code archive. Since 1.0.21 release, they are also at the GitHub release page.The pre-built Windows binaries are provided AS IS for your convenience, generated for the following environments:Microsoft Visual Studio; MS32 (32 bit) and MS64 (64 bit) directoriesMinGW -> MinGW32 (32 bit) and MinGW64 (64 bit) directories. Note that these archives are provided in the 7z format so you may have to install 7-zip.vcpkg portvcpkg now includes libusb ports.Installing and building libusb via vcpkg:You can download and install libusb using the vcpkg dependency manager: git clone cd vcpkg .\bootstrap-vcpkg.bat .\vcpkg integrate install .\vcpkg install libusbThe libusb port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.msys2 MinGW-w64 32bit/64bit packagemsys2 has a libusb package. Please contact the msys2 project if you encountered issues with the msys2 package. It is recommended to use pkg-config (libusb-1.0.pc) on MSYS2 or other MinGW-w64 distributions. Reference: how to use libusb under MinGW-w64?Build from
2025-03-25SourceYou may want to build from source if you encounter compatibility issues with the pre-built binaries. We recommend either Visual Studio or a MinGW-w64 based toolchain like MSYS2. Note that the MinGW.org toolchain is not supported. clang support patches are welcome. Patches to add support for other toolchains (including MinGW.org) may be accepted after review even though these toolchains are not officially supported. Supported EnvironmentsSupported systems are all Windows platforms, starting with Windows Vista, and including 64 bit versions. Windows XP support was dropped in libusb 1.0.24.USB 3.x Supportlibusb supports USB 3.x controllers and devices on Windows. Proprietary vendor controller drivers for Windows 7 and earlier as well as the Microsoft controller xHCI driver for Windows 8/8.1/10 are supported. If you are are using Windows 7 or earlier version, you will be using vendor driver. Make sure you upgrade to the latest version of the driver if you encounter problems. .NET supportA .NET version of libusb, called LibUsbDotNet, based on libusb 1.0. If you plan to use libusb in a .NET project, make sure you check out the latest release at github.How to use libusb on WindowsDriver InstallationIf your target device is not HID, and your device is not using WinUSB driver, you must install a driver before you can communicate with it using libusb. Currently, this means installing one of Microsoft's WinUSB, libusb-win32 or libusbK drivers. Two options are available:Recommended: Use the most recent version of Zadig, an Automated Driver Installer GUI application for WinUSB (recommended), libusbK (only if you hit WinUSB limitations) and libusb-win32 (only if you hit WinUSB/libusbK limitations).For version 1.0.21 or later, you can also use the usbdk backend. usbdk provides another driver option for libusb Windows backend. For 1.0.21, usbdk is a compile-time option, but it becomes a runtime option from version 1.0.22 onwards, so
2025-04-19You need to specify the usbdk backend using something like the following.libusb_context * ctx = NULL;libusb_init(&ctx);libusb_set_option(ctx, LIBUSB_OPTION_USE_USBDK);Note that if your device is using libusb-win32 driver (libusb0.sys), you will also need to install the libusbK DLL, as all libusb0.sys accesses are done through it. One way to install/update libusbK.dll is to install libusbk development kit (libusbK-x.x.x.x-setup.exe from Sourceforge site and choose to update the system files during the installation. However the support of libusb-win32/libusb0.sys filter driver mode is not good, please use the device driver mode when you have to use libusb0.sys. Warning: use of the HID backend is highly discouraged. libusb project recommends the user to switch to hidapi.Development ConsiderationsThe handling of composite devices under Windows is done with multiple drivers, that are children of the usbccgp.sys driver (Composite Generic Parent), as this is the default for the OS. If needed, it is also possible to replace the composite parent driver to access the device. Zadig can be used for this purpose.Because Windows does not provide a native poll() function, and cygwin is the only development environment that provides such a call, the use of libusb file descriptors with poll() on cygwin is NOT supported. In a future version of libusb, we should provide better handling of native Windows events, but this will require a redesign of the libusb API, so it probably won't occur before libusb 2.0.Known RestrictionsWinUSB cannot be used to send an actual reset command to an USB device. This is a limitation of WinUSB. WinUSB and libusbK cannot be used to set a device configuration that is different from the first one. This is a limitation of KMDF USB I/O Target. WinUSB does not support multiple concurrent applications (as per the Microsoft Windows Hardware Drivers documentation). libusbk driver allows this but it may have the limitation
2025-04-18Poll() on Windows, the ability to return externally pollable file descriptors on Windows libusb_get_pollfd() returns an error.If you use a composite device, and plan to install a libusb compatible driver for any of the interfaces, you should ensure that your driver package adds a Device Interface GUID in the registry, as proper enumeration of composite devices in libusb depends on it. This is typically achieved by adding something like the following in your inf:HKR,,DeviceInterfaceGUIDs,0x00010000,{12345678-1234-1234-1234-123456789ABC} This is in particular a problem with libusb-win32's inf-wizard which will be deprecated by libusb-win32 project. Please use Zadig instead.libusb0.sys and libusbk.sys access is done through the libusbK DLL, therefore, if you plan to use the libusb-win32/libusb0.sys or libusbK/libusbk.sys driver in libusb, you must have that library installed. If using a recent version of Zadig, you should not have to do anything, at it will install the library for you.libusb0.sys: the support of libusb0.sys filter driver has quite some issues, you should use the device driver mode if you really need to use libusb0.sys.libusb0.sys: cannot send libusb_control_transfer with zero wLength with libusb0.sys 1.2.6.0 version. Please use libusb0.sys 1.2.7.3 snapshot release or later. The recommendation is to use libusb-win32 1.4.0.0 release and later.uhubctl will not work under Windows. Please refer to Issue #391 due to limitation of the underlying drivers (libusb0.sys, libusbk.sys, usbdk and WinUSB) with regard to USB Hubs.Development LinksHow to Use WinUSB to Communicate with a USB Device & WinUSB (Winusb.sys) Installation.Note that the inf file given in the howto has a typo. If you don't change SourceDisksFiles.NTamd64 to SourceDisksFiles.amd64, the driver installation will fail to copy the required DLLs on 64 bit systems...Using WinUSB for User-Mode to USB Device CommunicationWinUSB User-Mode Client Support RoutinesMicrosoft's USB Core Team BlogMicrosoft HW Development Center -- USBadditional information about Windows Co-InstallersFinding Memory Leaks Using the CRT LibrarylibusbK documentationlibwdi/Zadig
2025-04-16