Getting Started with Windows drivers (ii) code structure

Source: Internet
Author: User

Windows Driver basics, reproduced in the source:

Windows Driver Architecture:

What I want to say is that the structure of the Windows driver is the same as the C + + program structure, and you will feel a lot easier after you know it.

First, do the necessary preprocessing in a header file, then define the device extension structure (equivalent to class) that will be used, and then the declaration of the function. When this is all over, we will implement these functions in the. cpp file, but not the same place to say:

1. The structure declared here is used to store the information of the device;

2. Declared function outside the structure, in order to be compatible with C to use extern "C";

3. The declared function is generally divided into, the function of the entrance (equivalent to the main function), the device creation function, the device's unloading 3 parts.

Let's take a look at the example in the author's book: ( remarks, the last few lines are the two examples I Iker against the author. )


#001/**************************************************************
#002 * File name: Driver.h
#003 * Author: sail
#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   &NBSP; above is precompiled processing: the header files required for NT drivers are imported, are compatible with the C + + language, and some macros define

#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 isStatementCreate a function for a device#036 VOID helloddkunload (in Pdriver_object pdriverobject);//Here is
Statement an unload-driven function
#037 NTSTATUS helloddkdispatchroutine (in Pdevice_object pdevobj,
#038 in Pirp pirp);//Here is a function that declares a default dispatch
#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 also be very clear, do not repeat!


Reference:

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

A detailed description of the Windows driver Development technology

Getting Started with Windows drivers (ii) code structure

Related Article

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.