Learning notes for wince USB camera driver (modifying)

Source: Internet
Author: User

Compared with a general streaming driver, USB streaming drivers have many similarities and differences. This is closely related to the working method and USB protocol of USB devices. The most intuitive is that, apart from the ten standard stream-driven interface functions such as xxx_init and xxx_open, there are also three special entry functions: usbinstalldriver (), usbdeviceattach (), and usbuninstalldriver (). The following is a brief introduction to the USB driver startup process.

1. USB driver Startup Process

All USB stream drivers under wince are generally stored in the system as DLL (dynamic link library. When a USB device is inserted, the wince Device Manager searches for information about the newly inserted USB device under the HKEY_LOCAL_MACHINE \ drivers \ USB \ loadclients \ key in the registry (as mentioned later ).

Assume that the driver information is not found when the device is inserted for the first time. A "Unrecognized USB device" dialog box is displayed, enter the driver name (the DLL file name ). After you enter a name, the system automatically calls the usbinstalldriver function of the DLL. This function is used to add information about the USB host driver to the registry so that the USB device can be identified when the device is inserted again. The prototype is as follows:

Bool usbinstalldriver (lpcwstrszdriverlibfile)

Szdriverlibfile: name of the input DLL file.

Return Value: True indicates that the registration is successful, and false indicates that the registration fails.

All in all, the usbinstalldriver function writes relevant information under Drivers \ USB \ loadclients \ and Drivers \ USB \ clientdrivers in the registry.

When writing loadclients, you must use two registration functions provided by usbd:

Bool registerclientdriverid (lpcwstr szuniquedriverid)

Bool registerclientsettings (maid, maid, maid)

In the routine, these two functions are generally used to open usbd. dll with loadlibrary, and then dynamically called using the getprocaddress function pointer.

Note that the lpdriversettings parameter is a usb_driver_settings struct. The statement is as follows:
Typedef struct {
DWORD dwcount;
DWORD dwvendorid;
DWORD dwproductid;
DWORD dwreleasenumber;
DWORD dwdeviceclass;
DWORD dwdevicesubclass;
DWORD dwdeviceprotocol;
DWORD dwinterfaceclass;
DWORD dwinterfacesubclass;
DWORD dwinterfaceprotocol;
} Usb_driver_settings;
Count is the structure size, and other items correspond to the USB descriptor. The fields except count can be set to usb_no_info if no specific value is set.
In wince, these settings are divided into three groups, each with three values,
Group 1:

Dwvendorid, dwproductid, dwreleasenumber
Group 2:

Dwdeviceclass, dwdevicesubclass, and dwdeviceprotocol
Group 3:

Dwinterfaceclass, dwinterfacesubclass, dwinterfaceprotocol

If the registration is successful, the first group \ second group \ third group \ registration ID will appear under the HKEY_LOCAL_MACHINE \ drivers \ USB \ loadclients \ key (this is determined by registerclientdriverid) \ DLL ", the key value is the DLL driver name. Each group is composed of three values underlined. If a value is set to usb_no_info, the key name does not include this value. If every value in the entire group is set to usb_no_info, the key name is default.

For example, if we configure lpdriversettings:

Driversettings. dwcount = sizeof (driversettings );
Driversettings. dwvendorid = 0x10c4;
Driversettings. dwproductid = 0x0003;
Driversettings. dwreleasenumber = usb_no_info;

Driversettings. dwdeviceclass = usb_no_info;
Driversettings. dwdevicesubclass = usb_no_info;
Driversettings. dwdeviceprotocol = usb_no_info;

Driversettings. dwinterfaceclass = 0;
Driversettings. dwinterfacesubclass = 0;
Driversettings. dwinterfaceprotocol = 0;

In my system, the following key names will be generated: HKEY_LOCAL_MACHINE \ drivers \ USB \ loadclients \ 4292_3 \ Default \ 0_0_0 \ usbtest \ DLL = "webcam" (my driver is webcam. DLL ). In this way, the system can identify the driver through the registry.

Writing to clientdrivers is relatively simple. Just use getsetkeyvalues.

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.