Some strategic code, algorithm code, and
The code that is not related to the driver's internal API can be used at the application layer for testing,
To speed up writing,
This is obvious, and the application layer has its advantages in this regard.
How to implement this function.
Mainly writing two files
One is the sources file and the other is the Sample. def file.
1. sources File
KERNEL_BUILD = 1 # If You Want To compile it into a DLL, add the # sign before it.
TARGETNAME = Sample
DLLDEF = Sample. def # output function. def File
TARGETPATH = ../bin # file output directory (. sys file or. dll file)
TARGETPATHLIB = ../lib #. lib output directory
! Ifdef KERNEL_BUILD # If KERNEL_BUILD is defined, A. sys file is generated, which is equivalent to the kernel library.
TARGETTYPE = EXPORT_DRIVER
! Else # if not defined, A. dll is generated.
TARGETTYPE = DYNLINK # generate a dll
USE_MSVCRT = 1
DLLENTRY = _ DllMainCRTStartup # dll entry function
Primary des = $ (primary des); $ (DDK_INC_PATH); # directory of the H file
Primary des = $ (primary des); $ (SDK_INC_PATH );
TARGETLIBS = $ (TARGETLIBS) $ (SDK_LIB_PATH) \ kernel32.lib # LIB directory kernel32.lib gdi32.lib advapi32.lib
TARGETLIBS = $ (TARGETLIBS) $ (SDK_LIB_PATH) \ gdi32.lib
TARGETLIBS = $ (TARGETLIBS) $ (SDK_LIB_PATH) \ advapi32.lib
TARGETLIBS = $ (TARGETLIBS) $ (SDK_LIB_PATH) \ ntdll. lib
! Endif
Primary des = $ (primary des);.../../inc; # Your Own. h file directory
Primary des = $ (primary des);.../../inc/SampleOne; # Your Own. h file directory 2
Primary des = $ (primary des);.../../inc/SampleTwo; # My. h file directory 3
SOURCES = \
A. cpp \
B. cpp \
C. cpp \
D. cpp \
Ii. Sample. def File
NAME "Sample. sys" # if it is a kernel library, it is Sample. sys. If it is an application-layer dll, it is changed to Sample. dll.
EXPORTS
DllInitialize PRIVATE
DllUnload PRIVATE
AFunc
BBFunc
Iii. function library entry functions
# Include "ntddk. h"
Extern "C "{
NTSTATUS DriverEntry (PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pusRegPath );
Void DriverUnload (PDRIVER_OBJECT pDriverObject );
NTSTATUS DllInitialize (PUNICODE_STRING RegistryPath );
NTSTATUS DllUnload ();
};
Void DriverUnload (PDRIVER_OBJECT pDriverObject)
{
DllUnload ();
}
NTSTATUS DriverEntry (PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pusRegPath)
{
DllInitialize (pusRegPath );
PDriverObject-> DriverUnload = DriverUnload;
Return STATUS_SUCCESS;
}
NTSTATUS DllInitialize (PUNICODE_STRING RegistryPath)
{
Dbuplint ("Sample: DllInitialize (% wZ) \ n", RegistryPath );
Return STATUS_SUCCESS;
}
NTSTATUS DllUnload ()
{
Dbuplint ("Sample: DllUnload \ n ");
Return STATUS_SUCCESS;
}
// Note that
// In DDK, the default compiler is _ stdcall.
// The default value for compiling in VC is _ cdecel.
// Therefore, _ stdcall is explicitly added here to prevent compiler link errors.
ULONG _ stdcall TestFun (void)
{
Return 100;
}
Sample Code:
Http://download.csdn.net/source/2799981