WDK+Visual Studio 2008配置编译驱动

Introduction 

As it is known, Microsoft officially doesn't support integration of DDK with Visual Studio (any version). So we can use the Visual Studio editor (or any other text editor) for developing the source codes of a driver, but for compiling we should use the DDK build utility. Of course it is not very convenient because we must always switch between editor and console window, but the worst thing is that the developer must spend a lot of time to find lines with errors in the editor.

Background 

There are several ways to compile drivers with Visual Studio. You can find most of them in the nice Mark Roddy article, Windows Driver Build Methods and Tools .

Mark offers some third party utilities. That's good, but I will show a more handy way (IMHO): how to configure and use Visual Studio for compiling drivers. 

Have Fun

  1. Setup Visual Studio 2008.

  2. Setup DDK (WDK).

  3. Add to VS paths DDK include files, libs and bins.

  4. Create new empty "Win32 project" and add source file (i.e. HelloWorld.c ).

  5. Configure project properties (All Configurations):

    1. C\C++ - General - Debug Information Format = Program Database (/Zi )
    2. C\C++ - Preprocessor - Preprocessor Definitions = _X86_ [add also DBG for Debug config]
    3. C\C++ - Code Generation - Enable C++ Exceptions = No
    4. C\C++ - Code Generation - Basic Runtime Checks = Default
    5. C\C++ - Code Generation - Buffer Security Check = No (/GS -)
    6. C\C++ - Advanced - Calling Convention = __stdcall (/Gz )
    7. C\C++ - Advanced - Compile As = Compile as C Code (/TC) [if you are going to use plain C]
    8. Linker - General - Output File = $(OutDir)\$(ProjectName).sys
    9. Linker - General - Enable Incremental Linking = Default
    10. Linker - Input - Additional Dependencies = ntoskrnl.lib hal.lib $(NOINHERIT) [add needed libs here e.g. ntoskrnl.lib hal.lib ]
    11. Linker - Input - Ignore All Default Libraries = Yes (/NODEFAULTLIB )
    12. Linker - Manifest File - Generate Manifest = No
    13. Linker - System - SubSystem = Native (/SUBSYSTEM:NATIVE )
    14. Linker - System - Driver = Driver (/DRIVER )
    15. Linker - Advanced - Entry Point = DriverEntry
    16. Linker - Advanced - Base Address = 0x10000
    17. Linker - Advanced - Randomized Base Address = Disable (/DYNAMICBASE:NO )
    18. Linker - Advanced - Data Execution Prevention (DEP) = Disable (/NXCOMPAT:NO )
  6. OK. Done. Now you can test it with simple code, e.g.:

  7. #include "ntddk.h"
    
    NTSTATUS
    DriverEntry(PDRIVER_OBJECT DriverObject,PUNICODE_STRING
    RegistryPath)
    {
    return STATUS_UNSUCCESSFUL;
    }

    About the Author

    Andrey Sergienko
  8. From:  http://www.codeproject.com/KB/winsdk/vs2008_and_drivers.aspx

找到一个中文版的:

 

1、现在要让Visual Studio 2008 能够编译驱动 程序,步骤如下:

(1) 打开VS2008 ,单 击工具 ——>选项 ;在选项的列表栏选择项目和解决方案 ——>C++目录 ;在左侧的显示以下内容的项目 中 先选择包含文件 ,并在下面新建D:\WinDDK \6001.18002\inc\api和D:\WinDDK\6001.18002\inc\ddk两个路径(注意:D:\请替换成你WDK的安装目录 );然后再在显示以下内容的项目 中选择库文件,在下面添加D:\WinDDK\6001.18002\lib \wxp\i386(注意:D:\请替换成你WDK的安装目录 )。

(2) 接下来是每次创建项目都需要做的。先创建一个项目,在项目生成后点击项 目 ——>(项目名)属性 ,点击配置管理器 ,并在配置管理器 中 新建一个名为Free的配置(新建时从Release复制配置);之后在属性页的右侧选择配置属性 ——>C/C++ ——>高级 ,调用约定改为 __stdcall(/Gz);再在属性页的右侧选择配置属性 ——>链接器 ,在常规 中把输出文件 改 为$(OutDir)\$(ProjectName).sys,在清单 文件 中把启用用户账户控制(UAC) 改为 否(这就是VS2008 中新增加的特性),在优化 中将链接时间代码生成 改 为默认值,在高级 中将随机地址 改为默认值(这也是VS2008 中 新增加的特性),最后在命令行 中输入:

ntoskrnl.lib
/base:"0x10000"
/entry:"DriverEntry"
/subsystem:native
/nologo
/stack:0x400000,0x1000
/incremental:no
/nodefaultlib

 

原文来自: http://flyxxtt.blogbus.com/logs/42680411.html

你可能感兴趣的:(C++,c,配置管理,项目管理,C#)