Libusb-win32 using the VS2010 compilation process on Windows7

Source: Internet
Author: User

Libusb-win32 is a generic USB device driver for the Windows operating system (WIN98SE, WinME, Win2K, and WinXP, Vista, Win7, and so on). This driver allows the consumer to access any USB device on the Windows system without writing a single line of core driver code, with the following characteristics:

? Ability to communicate with any installed USB device

? Drivers that can be used as USB devices for their own development

? Supports batch and interrupt transfers

? Supports all standard device requests defined in the USB specification

? Support for custom requests from USB device manufacturers

By using several functions, you can easily communicate with USB devices, and the main process of communication can be divided into the following four steps:

1) Call the Usb_init function to initialize.

2) Open the handle to the USB device you want to communicate with. First call the usb_find_busses, Usb_find_devices, and usb_get_busses three functions to obtain the found USB bus sequence, and then traverse through the list of all USB devices, based on the known ID of the USB device to open (VID /PID), locate the appropriate USB device, and finally call the Usb_open function to open the USB device (assuming there are no USB devices of the same vid and PID on the bus). If there is a device with the same VID and PID on the bus, other conditions should be judged, such as the device name, to ensure that the desired USB device is turned on.

3) communicate with the USB device. Use the USB_CONTROL_MSG function to read data or write data to a USB device.

4) Turn off the USB device. When all is done, call the Usb_close function to close the USB device that is already open.

Compiling tools: VS2010 and WINDDK, can go to the official web direct download source code, address is http://sourceforge.net/projects/libusb-win32/files/, download the latest version for libusb-win32-src-1.2.6.0. VS2010 is used to compile Libusb-win32 dynamic link libraries, related tools, and demo programs. We also need WINDDK to compile the driver, that is, to generate the Libusb0.sys file. From the official Make.cfg file, the WINDDK 7600.16385.0 (WINDOW XP and above) WINDDK 6001.18002 (WINDOWS 2000 and later) are used. Here is the WINDDK 7600.16385.1, open the source of the project file as shown:


inf-wizard--Device driver Installation information File Generation Wizard. This wizard can scan the USB device on your computer and get the VID and PID generated INF files for your selected device.


Install-filter--filter driver installation.

libusb-dll--dynamic link library, generate Libusb0.dll. The "7 functions" described above are encapsulated in this area. At the same time, the Libusb0.lib file is generated for the program to link and implement the Libusb0.dll loading.

LIBUSB-SYS--USB driver, generate driver file Libusb0.sys. Note that it is a makefile project.

Testbulk--libusb-win32 's "hello,world!".

testlibusb--implements the traversal of the Libusb-win32-driven device and prints part of the device description information.

Testlibusb-win--winform version of Testlibusb.

Compile the project, there is no error, but there is no Libusb0.sys file in the Libusb-sys generated directory, Libusb-sys is to compile the link by WINDDK.

Review the project Properties page for Libusb-sys, and in the [Configuration Properties] column, review the build command line.

CD "$ (ProjectDir): \ddk_make "

CMD/C make.cmd "arch=x86" "App=driver" "Noclean=true" "outdir=$ (OutDir)" "dir_intermediate=$ (IntDir)" "Debugmode=true "

View the Make.cfg file under the directory.

; Default Winddkdirectory (s) Adjust these values to match your environment

; (REQUIRED)

Winddk_base=z:\winddk

winddk_dir=! Winddk_base!\7600.16385.0\

;

; (optional)

winddk_w2k_dir=! Winddk_base!\6001.18002\

Change these two to your WINDDK installation path.

; Default Winddkdirectory (s) Adjust these values to match your environment

; (REQUIRED)

Winddk_base=d:\winddk

winddk_dir=! Winddk_base!\7600.16385.1\

Compile the Libusb-sys.

Compile error Error MSB3073:, modify ddk_make/make.cmd,line175 W2K (end) modified to WIN7, compile successfully.

Then compile LIBWDI, always error error MSB3073, online search for a half-day data have no solution, finally found the cause of the problem, the included files are not placed in the corresponding location.

Copy the corresponding file from the compiled libusb-win32-src-1.2.6.0 (which can be downloaded from Http://sourceforge.net/apps/trac/libusb-win32/wiki) to E:/libusb-win32, Note that the directory is E:\libusb-win32\bin\x86, and the directory path corresponding to modify Config.h is as follows:

/* Embed WINUSB driver files from thefollowing DDK location */

#ifndef Ddk_dir

#define Ddk_dir"d:/winddk/7600.16385.1"

#endif

/* Embed libusb0 driver files from thefollowing location */

#ifndef Libusb0_dir

#define Libusb0_dir"E:/libusb-win32"

#endif

Then inf-wizard the project to compile the problem, error LNK2019: unresolved external symbols, by adding compilation generated Libwdi. Lib to the project path can be resolved, the final compilation completed the entire project.


The compilation process references the following articles:

Http://www.amobbs.com/archiver/tid-4096300.html

http://blog.csdn.net/hbsong75/article/details/12841301

http://m.blog.csdn.net/blog/whw8007/38895073

Libusb-win32 using the VS2010 compilation process on Windows7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.