Getting Started with Windows drivers (ii) code structure

Source: Internet
Author: User

Windows Driver Foundation. Reprint marked Source: http://blog.csdn.net/ikerpeng/article/details/38777641

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'll think it's a lot easier after you know it.

First, do the necessary preprocessing in a header file. Then define the device that will be used to extend the structure (equivalent to Class), and then the declaration of the function.

When this is all over, we implement these functions in the. cpp file. But not the same place to say:

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

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

3. Declared function is generally divided into, the function of the entrance (equivalent to the main function), the device creation function. Uninstall 3 parts of the device.

Let's take a look at the examples in the author's book: ( remarks, the last few lines are the two examples of my Iker comparison authors . )


#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   above is precompiled processing: Import the NT driver required header file. Compatible with the C + + language, and other 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, and you should also be very clear, and don't repeat them!


References:

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

The specific explanation of 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.