Windows Driver entry (2) code structure, windows code

Source: Internet
Author: User

Windows Driver entry (2) code structure, windows code

Windows Driver basics, reprinted indicated Source: http://blog.csdn.net/ikerpeng/article/details/38777641

Windows Driver structure:

What I want to talk about is that the structure of the windows Driver is the same as that of the C ++ program. After you know this, you will feel much simpler.

First, make some necessary preprocessing in a header file; then define the device extension struct (equivalent to Class) that will be used; then, declare the function. After all this is done, we will implement these functions in the. cpp file, but let's talk about them differently:

1. the struct declared here is used to store device information;

2. The declared function is outside the struct. To be compatible with C, use the extern "c ";

3. declared functions are generally divided into three parts: function entry (equivalent to the main function), device creation function, and device uninstallation.

Next let's take a look at the examples in the author's book: (Note: the last few lines are added after two examples from the author by iker)


#001 /************************************* *************************
#002 * file name: Driver. h
#003 * OPERATOR: Zhang Fan
#004 * completion date: 2007-11-1
#005 ************************************** **********************/
#006 # pragma once
#007
#008 # ifdef _ cplusplus
#009 extern "C"
#010 {
#011 # endif
#012 # include <NTDDK. h>
#013 # ifdef _ cplusplus
#014}
#015 # endif
#016
#017 # define PAGEDCODE code_seg ("PAGE ")
#018 # define LOCKEDCODE code_seg ()
#019 # define INITCODE code_seg ("INIT ")
#020
021   #define PAGEDDATA data_seg("PAGE")
#022 # define LOCKEDDATA data_seg ()
#023 # define INITDATA data_seg ("INIT ")
#024
#025 # define arraysize (p) (sizeof (p)/sizeof (p) [0])
#026 or above are pre-compiled: Imported header files required by the NT driver, compatible with the C ++ language, and some macro definitions

#027 typedef struct _ DEVICE_EXTENSION {
#028 PDEVICE_OBJECT pDevice;
#029 UNICODE_STRING ustrDeviceName; // device name
#030 UNICODE_STRING ustrSymLinkName; // Symbolic Link name
#031} DEVICE_EXTENSION, * PDEVICE_EXTENSION;
#032
#033 // function declaration
#034
#035 NTSTATUS CreateDevice (IN PDRIVER_OBJECT pDriverObject); // here is the function for creating a device #036 VOID HelloDDKUnload (IN PDRIVER_OBJECT pDriverObject); // here is
Declare a function to uninstall the driver.
#037 NTSTATUS HelloDDKDispatchRoutine (IN PDEVICE_OBJECT p1_bj,
#038 in pirp pIrp); // declare a default dispatch function.
#039
#040   extern "C"
#041   NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,
#042                        IN PUNICODE_STRING RegistryPath);
// Here is the entry to define the function, which is equivalent to the main function
The next step is to implement these functions in the. cpp file. You should be clear about them and will not go into details!


Refer:

Http://book.51cto.com/art/200807/79760.htm

Windows driver development technology details


Windows cannot load the device driver of this hardware. The driver can be corrupted or lost (code 39)

Start-run-regedit-go to the Registry and go to HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Class \ {4D36E965-E325-11CE-BFC1-08002BE10318} to delete the upperfilters item and loweverfilters item

Also find
You can use either of the following methods: 1. Go to the control panel and select "Add new hardware". Then, follow the prompts to proceed step by step. After the system check is complete, you can generally find the optical drive; 2. Go to the control panel, select "Device Manager", delete the "hard disk controller" item, and restart the computer. Because the optical drive and the hard drive use the same controller, when it is deleted and restarted, it will be automatically identified, and generally the drive letter of the optical drive can be retrieved.

Windows can successfully install the device driver software, but the driver software encountered a problem when trying to run the code is 39

Don't panic, I have encountered this problem just now, and it has been solved. The specific steps are as follows:
1. Put the drive CD you sent when buying a computer and re-install it. If the drive is unavailable, download it from the official website of the laptop manufacturer. The burner driver and the driver of the motherboard are required.
2. After the driver is installed, step 2 is to right-click the properties of the computer, open the Device Manager, say hello to the hardware to be updated, and select Update driver software, then, browse the computer to find the driver, select the "C: \ WINDOWS \ WINSXS" path, and click Next. If a prompt is displayed that the compatibility problem is skipped, select Continue. Generally, you can click here,
3. If the installation fails, repeat the second time and select C: \ WINDOWS \ SYSTEM32 \ DRIVERSTORE \ FILEREPOSITORY.
Reference: Absolutely original, despise plagiarism!

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.