Dynamic Loading of Windows CE downstream drivers

Source: Internet
Author: User
Embedded online favorites | print

I think many wince developers, especially those who are just getting started with driver development, have encountered such a problem and want to write a driver for the peripheral device, taking the simplest gpio Driver For example, writing a driver may only take a while. You can package the compiled DLL into a previously prepared operating system image. The simplest thing is makeimg, you also need to modify the bib file and registry file so that the driver can be loaded when the system is started. All work is done, and it takes several minutes to download the entire operating system to the memory for running, it also takes several minutes. If a person with strong abilities succeeds at a time, he will not go back.

If the driver is written incorrectly, you have to change it.Code, Re-compile and redo what you just did. I am not afraid of making jokes. I just started to drive the program. I tried again and again. After half a day, I was able to debug a simple driver. In fact, a large part of the time is wasted on repeated operations. This debugging-driven method is too inefficient. It is convenient to think of driver debugging in Linux! Click "insmod" and apply it.ProgramIt can be called. If there is a problem, rmmod does not need to reset the image file of the operating system. So, isn't there such a simple method under wince? The answer is yes.

If you have less time to talk about it, go to the topic. Find the EVC help and find that the activatedevice () function can be used to load the driver. This function is quite simple to use. I will not say much about it. I have posted a help article to illustrate the problem. Of course, you can also use ActivateDeviceEx ().

Handle activatedevice (

Lpcwstr lpszdevkey,

DWORD dwclientinfo

);

Parameters

Lpszdevkey

[In] pointer to the Registry path string of the device's driver key under HKEY_LOCAL_MACHINE. A driver key contains the DLL name, the device prefix, friendly name, and other device information.

Dwclientinfo

[In] data that will be stored in the device's active key in the clientinfo value. the Registry path to the driver's active key is passed in as the context parameter to the device's xxx_init function. the value in dwclientinfo is stored in the registry before xxx_init is called.

Return values

On success, activatedevice returns a handle to the device that can be used in subsequent callto deactivatedevice.

Remarks

This function is superseded by ActivateDeviceEx.

activatedevice loads a device driver. activatedevice reads the registry key specified in lpszdevkey to get the DLL name, device prefix, index, and other values. next it adds the device to the active device list in the Registry branch HKEY_LOCAL_MACHINE \ drivers \ Active, and stores the relevant values there. if no device index was specified in the key named in lpszdevkey, then it assigns a free index. then it loads the device driver DLL in the process space of the Device Manager. then it broadcasts a wm_devicechange message for the new device and triggers a icationication_event_device_change event in the Application Notification System to inform y applications of the presence of the new device.

As described above, when using this function, we only need to provide the first parameter, which is a path string in the registry. Therefore, to easily and dynamically load any driver, we also need to know about the registry. However, the most important one is to put the registry information of your driver under HKEY_LOCAL_MACHINE. The main contents include prefix, DLL, index, order, and other information. It is not described here.

I spent so much time at first, and it was really depressing. After finding out the principles, we made a small tool to dynamically load the stream driver to improve development efficiency and facilitate future users. The following describes how to use this tool and how to dynamically load a stream driver.

. Copy these three files and the driver (dm.exe) to the wince system, as shown in.

Run drvdemo.exe first, and click open device or another button. We find that the device fails to be opened and it is normal that drvdemo. dll is not working yet.

Run the driver's helper software dm.exe, click the "Driver debugging" menu, select "Import Registry", and browse the prepared Registry File drvdemo. reg, select and click OK. In this way, drvdemo. the contents in Reg have been imported into the system. The corresponding information can be seen in "operation information echo.

In this case, you can directly click "Activate driver" under the "Driver debugging" menu. Of course, you can also choose "Driver debugging"> "Driver list" to activate the driver. Under normal circumstances, the Operation echo will prompt you "The driver is loaded successfully ".

Now, go to drvdemo.exe and click open device.

If the driver is faulty during the test, you can select "Uninstall driver", copy the modified driver, and click "Activate driver. Until the debugging is successful.

So far, we have activated the driver by importing the Registry file. Next we will talk about how to directly load the driver by browsing the DLL file itself when there is no registry file. First, uninstall the loaded driver.

Run the driver debugging Assistant Software and click the "Driver debugging" menu -- select "Browse DLL file" to browse the prepared drvdemo. dll file. In the displayed dialog box, set the correct prefix, order, and index information and click "OK ".

In the same way, you can directly activate the driver through "Activate driver" under "Driver debugging" or activate the driver from the "Driver list.

The remaining operations are exactly the same as described above and will not be repeated.

How is this method similar to insmod and rmmod in Linux?

In fact, if the corresponding key already exists in the registry, you can even directly select it and then select "Activate driver" in "Driver debugging". If everything works properly, the above two methods can also be achieved, but this saves the cost of importing files. If you are interested, you can give it a try.

Well, I believe that everyone should have an understanding of the principles and methods of dynamic loading of the stream driver, and can also get rid of the nightmare of makeimg and download, saving a lot of valuable development time.

Finally, a few notes for the driver debugging assistant.

1. When debugging a driver, do not close the driver debugging assistant after the driver is loaded to minimize it. Otherwise, it will automatically uninstall the driver when it is disabled.

2. In wince4.2, drivers with interruptions cannot be dynamically loaded directly using this method, which is not limited in 5.0 and 6.0. This is because of the interrupt processing mechanism in wince4.2.

3. The driver debugging assistant can load several drivers at the same time. At this time, it is recommended to write all registry information to a file and import it. The rest of the work is to load the driver you need from the driver list.

4. The registry editing function in the driver debugging assistant has been modified several times and is basically complete. There are no problems with editing, importing, and exporting. If the system supports HIVE-REG, you can choose to save this registry modification when you exit the driver debugging assistant.

5. The above is done on the wince6.0 simulator. It should be regarded as the kernel-state driver. As for the user-state driver, it can be loaded using this method, but the corresponding registry information needs to be set.

6. make such a small tool to improve your work efficiency. Now, I hope it can be used by the same person. If you have any problem using this program, please send an email to the wince.he@gmail.com and I will try my best to solve it. The video recordings in this article and the latest driver debugging assistant can be downloaded at http://files.cnblogs.com/we-hjb/wincedm.rar.

The above is not a fresh or advanced technology, but I believe it will be helpful to some technical personnel. Of course, the text is not satisfactory. Please forgive me. In the future, I will try to write more things and learn Windows Embedded with everyone.

Finally, do not be considered "ad-oriented"Article". This article is an award for the Windows Embedded essay competition.

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.