Set the source file for compiling the kernel lib driver and application layer dll

Source: Internet
Author: User

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

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.