原贴地址:http://wo.115.com/?ct=detail&id=24749&bid=4111223
1、安装VS2010,安装WDK 7.0(DDK);
2、新建VC++->Empty Project
3、打开Configuration Manager 并新建一个名称为“ dirver ”的Solution Configuration 并将“dirver” 设为Active Solution Configuration .
4、打开View-> property Manager。
5、在"dirver" solution configuration 上点击右键,选择Add new property Sheet。取名为“dirverProperty”. 并对他进下以下设置。
5.1. C/C++ - General - Debug Information Format = Program Database (/Zi)
5.2. C/C++ - Preprocessor - Preprocessor Definitions = _X86_ [add also DBG for Debug config]
【WIN32;_DEBUG;_X86_;i386;STD_CALL;CONDITION_HANDLING;WIN32_LEAN_AND_MEAN;NT_UP;SRVDBG;DBG;_IDWBUILD;_WIN32_WINNT=0x0400;% (PreprocessorDefinitions)】
5.3. C/C++ - Code Generation - Enable C++ Exceptions = No
5.4. C/C++ - Code Generation - Basic Runtime Checks = Default
5.5. C/C++ - Code Generation - Buffer Security Check = No (/GS-)
5.6. C/C++ - Advanced - Calling Convention = __stdcall (/Gz)
5.7. C/C++ - Advanced - Compile As = Compile as C Code (/TC) [if you are going to use plain C]
5.8. Linker - General - Output File = $(OutDir)/$(ProjectName).sys
5.9. Linker - General - Enable Incremental Linking = Default
5.10. Linker - Input - Additional Dependencies = ntoskrnl.lib hal.lib $(NOINHERIT) [add here needed libs here e.g. ntoskrnl.lib hal.lib]
【不知道上面是不是笔误,应该为:ntoskrnl.lib;hal.lib;%(AdditionalDependencies)】
5.11. Linker - Input - Ignore All Default Libraries = Yes (/NODEFAULTLIB)
5.12. Linker - Manifest File - Generate Manifest = No
5.13. Linker - System - SubSystem = Native (/SUBSYSTEM:NATIVE)
5.14. Linker - System - Driver = Driver (/DRIVER)
5.15. Linker - Advanced - Entry Point = DriverEntry
5.16. Linker - Advanced - Base Address = 0x10000
5.17. Linker - Advanced - Randomized Base Address = Disable (/DYNAMICBASE:NO)
【这个也是错误的:应该置空】
5.18. Linker - Advanced - Data Execution Prevention (DEP) = Disable (/NXCOMPAT:NO)
【这个也是错误的:应该置空】
6. Config VC++ Directories
6.1 Open Open up property manager by clicking on Menu View->Property Manager.
6.2 Expand the project node and then the Configuration|Platform nodes, you will see "Microsoft.cpp..users" file for each Configuration|Platform. These are the files
for the global settings, similar to the old tools/Options/VC++ Directories.
6.3 Multi-Select "Microsoft.cpp..users", right click and bring up the property page window
6.4 In the property page window, click on "VC++ Directories" (for example) in the left pane, add new paths for the directories such as "Include Directories". separated by
semicolons
(eg:Include Directories config As:
$(ddkroot)/INC
$(ddkroot)/INC/WNET
$(ddkroot)/INC/DDK/WNET
Library Directories config As:
$(ddkroot)/LIB/WNET/I386
)
6.5 Make sure to save the settings before shutting down Visual Studio.
6.6 Re-launch Visual Studio and the new settings will be in effect.
6.7 Note: If you would like to only change the settings for one project, you can right click on the project and bring up the property page. Change the settings for “VC++
Directories”, these settings will be persisted to the project file.
七. OK. Have done. Now you can test it with simple code, e.g.:
#include "ntddk.h"
NTSTATUS
DriverEntry(PDRIVER_OBJECT DriverObject,PUNICODE_STRING RegistryPath)
{
return STATUS_UNSUCCESSFUL;
}
特别说明:
1.
Visual Studio 2010 在智能设备开发方面只支持Windows Phone OS 7.0。如果你要为Windows CE 5.0和Windows Mobile 6.5开发应用程序,请安装Visual Studio 2008。
2.
做驱动开发时,SDK的版本要和WDK的版本一致,即Win7 WDK要配Win7 SDK,否则会出现编译错误。VS2010里集成了Windows SDK 7.0A。
3.
如果出现类似如下编译错误,解决方法是:拷贝C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/include/sal.h,然后覆盖掉C:/WinDDK/7600.16385.1/inc/api/sal.h。
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/crtdefs.h(550): error C2143: syntax error : missing ')' before 'const'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/crtdefs.h(550): error C2143: syntax error : missing '{' before 'const'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/crtdefs.h(550): error C2059: syntax error : ','
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/crtdefs.h(550): error C2059: syntax error : ')'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/excpt.h(56): error C2143: syntax error : missing ')' before 'type'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/excpt.h(56): error C2085: '_ExceptionRecord' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/excpt.h(57): error C2143: syntax error : missing ';' before 'type'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/excpt.h(57): error C2085: '_EstablisherFrame' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/excpt.h(58): error C2085: '_Inout_' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/excpt.h(58): error C2143: syntax error : missing ';' before 'type'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/excpt.h(58): error C2085: '_ContextRecord' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/excpt.h(59): error C2085: '_Inout_' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/excpt.h(59): error C2143: syntax error : missing ';' before 'type'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/excpt.h(60): error C2059: syntax error : ')'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/excpt.h(60): error C2085: '_DispatcherContext' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/excpt.h(104): error C2082: redefinition of formal parameter '_exception_code'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/excpt.h(105): error C2082: redefinition of formal parameter '_exception_info'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/excpt.h(106): error C2082: redefinition of formal parameter '_abnormal_termination'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(92): error C2061: syntax error : identifier '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(93): error C2054: expected '(' to follow '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(93): error C2143: syntax error : missing ')' before 'type'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(93): error C2085: '_isctype_l' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(93): error C2143: syntax error : missing ';' before 'type'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(93): error C2085: '_C' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(93): error C2085: '_In_' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(93): error C2143: syntax error : missing ';' before 'type'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(93): error C2085: '_Type' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(93): error C2085: '_In_opt_' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(93): error C2146: syntax error : missing ',' before identifier '_locale_t'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(93): error C2146: syntax error : missing ',' before identifier '_Locale'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(93): error C2059: syntax error : ')'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(94): error C2061: syntax error : identifier '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(95): error C2086: 'int _Check_return_' : redefinition
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(93) : see declaration of '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(95): error C2054: expected '(' to follow '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(95): error C2143: syntax error : missing ')' before 'type'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(95): error C2085: '_isalpha_l' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(95): error C2143: syntax error : missing ';' before 'type'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(95): error C2085: '_C' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(95): error C2085: '_In_opt_' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(95): error C2146: syntax error : missing ',' before identifier '_locale_t'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(95): error C2146: syntax error : missing ',' before identifier '_Locale'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(95): error C2059: syntax error : ')'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(96): error C2061: syntax error : identifier '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(97): error C2086: 'int _Check_return_' : redefinition
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(93) : see declaration of '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(97): error C2054: expected '(' to follow '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(97): error C2143: syntax error : missing ')' before 'type'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(97): error C2085: '_isupper_l' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(97): error C2143: syntax error : missing ';' before 'type'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(97): error C2085: '_C' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(97): error C2085: '_In_opt_' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(97): error C2146: syntax error : missing ',' before identifier '_locale_t'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(97): error C2146: syntax error : missing ',' before identifier '_Locale'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(97): error C2059: syntax error : ')'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(98): error C2061: syntax error : identifier '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(99): error C2086: 'int _Check_return_' : redefinition
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(93) : see declaration of '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(99): error C2054: expected '(' to follow '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(99): error C2143: syntax error : missing ')' before 'type'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(99): error C2085: '_islower_l' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(99): error C2143: syntax error : missing ';' before 'type'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(99): error C2085: '_C' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(99): error C2085: '_In_opt_' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(99): error C2146: syntax error : missing ',' before identifier '_locale_t'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(99): error C2146: syntax error : missing ',' before identifier '_Locale'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(99): error C2059: syntax error : ')'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(100): error C2061: syntax error : identifier '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(101): error C2086: 'int _Check_return_' : redefinition
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(93) : see declaration of '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(101): error C2054: expected '(' to follow '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(101): error C2143: syntax error : missing ')' before 'type'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(101): error C2085: '_isdigit_l' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(101): error C2143: syntax error : missing ';' before 'type'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(101): error C2085: '_C' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(101): error C2085: '_In_opt_' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(101): error C2146: syntax error : missing ',' before identifier '_locale_t'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(101): error C2146: syntax error : missing ',' before identifier '_Locale'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(101): error C2059: syntax error : ')'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(102): error C2061: syntax error : identifier '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(103): error C2086: 'int _Check_return_' : redefinition
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(93) : see declaration of '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(103): error C2054: expected '(' to follow '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(103): error C2143: syntax error : missing ')' before 'type'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(103): error C2085: '_isxdigit_l' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(103): error C2143: syntax error : missing ';' before 'type'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(103): error C2085: '_C' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(103): error C2085: '_In_opt_' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(103): error C2146: syntax error : missing ',' before identifier '_locale_t'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(103): error C2146: syntax error : missing ',' before identifier '_Locale'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(103): error C2059: syntax error : ')'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(104): error C2061: syntax error : identifier '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(105): error C2086: 'int _Check_return_' : redefinition
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(93) : see declaration of '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(105): error C2054: expected '(' to follow '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(105): error C2143: syntax error : missing ')' before 'type'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(105): error C2085: '_isspace_l' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(105): error C2143: syntax error : missing ';' before 'type'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(105): error C2085: '_C' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(105): error C2085: '_In_opt_' : not in formal parameter list
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(105): error C2146: syntax error : missing ',' before identifier '_locale_t'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(105): error C2146: syntax error : missing ',' before identifier '_Locale'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(105): error C2059: syntax error : ')'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(106): error C2061: syntax error : identifier '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(107): error C2086: 'int _Check_return_' : redefinition
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(93) : see declaration of '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(107): error C2054: expected '(' to follow '_Check_return_'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(107): error C2143: syntax error : missing ')' before 'type'
C:/Program Files/Microsoft Visual Studio 10.0/VC/include/ctype.h(107): fatal error C1003: error count exceeds 100; stopping compilation
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
补充:
vs2010配置驱动开发基本上按照如上所说就差不多了,
第一,但是这样配置出来的,在windbg联机调试时,是打不开源文件的,
我找了一晚上,网上也没有明说的,但是后来对比vs2010编译出来的和直接用winddk checked模式编译出来的sys,发现vs2010的sys中缺少pdb信息,从而无法定位源文件,所以在自定义的属性中,链接器(linked)————>调试(debug)中生成调试信息选择是(/debug)就可以了
第二,这样子生成会出现error MSB3191: 无法创建目录“E:/driver/code/Config/serialfilter/ E:/driver/code/Config/driver”。不支持给定路径的格式。
这个不知道是我个人问题还是普遍问题,如果出现这个问题,在链接器(linked)————>常规(general)——>输出文件仔细看会发现 $(OutDir)/$(ProjectName).sys前面有个空格,删掉就好了。
第三,生成exe问题,
E:/软件/系统辅助/MSBuild/Microsoft.Cpp/v4.0/Microsoft.CppBuild.targets(990,5): warning MSB8012: TargetPath(E:/driver/code/Config/driver/serialfilter.exe) 与 Linker 的 OutputFile 属性值(E:/driver/code/Config/driver/serialfilter.sys)不匹配。这可能导致项目生成不正确。若要更正此问题,请确保 $(OutDir)、$(TargetName) 和 $(TargetExt) 属性值与 %(Link.OutputFile) 中指定的值匹配。
1>E:/软件/系统辅助/MSBuild/Microsoft.Cpp/v4.0/Microsoft.CppBuild.targets(991,5): warning MSB8012: TargetExt(.exe) 与 Linker 的 OutputFile 属性值(.sys)不匹配。这可能导致项目生成不正确。若要更正此问题,请确保 $(OutDir)、$(TargetName) 和 $(TargetExt) 属性值与 %(Link.OutputFile) 中指定的值匹配。
1>LINK : warning LNK4075: 忽略“/INCREMENTAL”(由于“/RELEASE”规范)
解决修改通用——>常规——>目标文件扩展名.sys