- 里论外几
-
一、下载与安装WDK
下载安装后,假设安装路径为逗c:winddk地,接下来要设计环境变量,添加:BASEDIR,值为:逗c:winddk6001地。必须设置此环境变量,否则下面编译时会出问题。
二、Visual Studio的开发环境
笔者用的是Visual Studio 2005,所以就以此版本介绍,其他版本的类似。
首先新建项目,类型选择Visual C++->General中的逗Makefile Project地,这里的项目保存路径不要包括空格、中文等字符,否则会造成后面编译时的出错。
image
下一步,在Debug Configuration Settings中设置如下:
Build command line: ddk_build chk wxp
Clean commands: ddk_clean chk wxp
Rebuild command line: ddk_build chk wxp /a
Output: first.sys
如图:
image
下一步,在Release Configuration Settings中与Debug的一样,只是把逗chk地改为逗fre地即可,如下图:
image
接下来设置工程属性,在All Configurations中,Configuration Properties->NMake->Include Search Path中添加路径:
C:WinDDK6000incddk;C:WinDDK6000incapi
接下来添加源代码文件,举个例子:
first.c
#include <ntddk.h>
VOID DriverUnload(PDRIVER_OBJECT driver)
{
DbgPrint("Driver unloading... ");
}
NTSTATUS DriverEntry(PDRIVER_OBJECT driver, PUNICODE_STRING reg_path)
{
DbgPrint("Entered Driver Entry! ");
driver->DriverUnload = DriverUnload;
return STATUS_SUCCESS;
}
现在可以发现在VS中可以使用VS开发环境带来的强大功能,如查看PDRIVER_OBJECT的定义、查看某变量的成员函数(Ctrl+J)等等。
接下来要为编译作准备,添加以下这些文件:
makefile
!IF 0
Copyright (C) Microsoft Corporation, 1999 - 2002
Module Name:
makefile.
Notes:
DO NOT EDIT THIS FILE!!! Edit .sources. if you want to add a new source
file to this component. This file merely indirects to the real make file
that is shared by all the components of Windows NT (DDK)
!ENDIF
!INCLUDE $(NTMAKEENV)makefile.def
sources
TARGETNAME=first
TARGETTYPE=DRIVER
TARGETPATH=obj
SOURCES=first.c
ddk_build.bat
@echo on
@echo %1 is chk or fre %2 is WXP or W2K or WNET.
if "%4"=="/a" call ddk_clean %1 %2
pushd.
call %BASEDIR%insetenv.bat %BASEDIR% %1 %2
popd
@echo on
build
ddk_clean.bat
if exist Debug rd /s /q Debug
if exist Release rd /s /q Release
if exist obj%1_%2_x86 rd /s /q obj%1_%2_x86
现在,按F7就可以编译连接了。
以上就是搭建VS的内核开发环境过程。