这些天真的很忙,没有时间写博,今天下午刚完成了一小部分内容,想把从写驱动开始到现在的感想都写出来,共同借鉴。下面我来讲一下windows XP 下vs2008与WDK搭配编译驱动的环境设置,网上也有些,但是都会有些错误。
新建一个win32consonle的空项目
1.打开项目属性设置
2.打开c/c++选项,选择Gengeral 在Addditional Include Directories中添加 C:/WinDDK/6001.18002 /inc/api;C:/WinDDK/6001.18002/inc/crt;C:/WinDDK/6001.18002/inc/ddk
当然C:/WinDDK是我自己的安装WDK的目录。
3. 在Debug Information Format选项中,选择 Program Database for Edit & Continue (/ZI)
4.Waring Level ,选择Level 3 (/W3)
5.选择optimization 在optimization选项中,选择Disabled (/Od)
6.在Preprocessor选项中,添加DEBUG;_WINDOWS;_X86_;_WIN32_WINNT=_WIN32_WINNT_WINXP;DBG;STD_CALL
7.选择Code Generation ,在Enable Minimal Rebuild选项中 ,选择Yes (/Gm)
8 .在Smaller Type Check选项中,选择No
9. 在Buffer Security Check 选项中,选择No (/GS-)
10.选择Advanced 在Calling Convertion选项中,选择__stdcall (/Gz)
11.在Complie As 选项中,选择你所用语言的编译器类型。
12 打开Linker
13.在Out Put File选项中,改为$(OutDir)/$(ProjectName).sys
14.在Show Process选项中,可以选择Display All Progress Messages (/VERBOSE),这样在编译时会列出详细编译信息。但也可不选
15.在Additonal Library Directories中,添加C:/WinDDK/6001.18002/lib/crt/i386;C:/WinDDK/6001.18002/lib/wxp/i386
16.打开Input ,在Additional Dependencies中添加Wdm.lib ntoskrnl.lib int64.lib libcntpr.lib,同时把下面的选项的勾打掉
libcntpr.lib 可以不加,但是如果在驱动中程序中用到浮点类型的数据时就要加上这个库,否则会出现连接错误, error LNK2001: unresolved external symbol __fltused
17.选择Mainfest File ,在Generate Mainfest 选项中选择 yes
18.选择Debuging,在Generate Debug Info选项中选择 Yes (/DEBUG)
19.进入System 在SubSystem选项中选择 Native (/SUBSYSTEM:NATIVE)
20.进入Optimization ,在Reference选项中选择Eliminate Unreferenced Data (/OPT:REF)
21.在Enable COMDAT Floding,选项中选择Remove Redundant COMDATs (/OPT:ICF)
22.进入Advanced 在Entry Point 中写DriverEntry
23.在Set Checksum选项中,选择Yes (/RELEASE)
24.BaseAddress,填写0x10000
25.在Randomized Base Address中选择Disable Image Randomization (/DYNAMICBASE:NO)
26.在Fixed Base Address中选择Generate a relocation section (/FIXED:NO)
27.在DEP中选择Default
28.Target Machine 选择MachineX86 (/MACHINE:X86)
这样就OK了,欢迎拍砖和指正,同时也欢迎在一起讨论!
如果转载请注明出处