четверг, 25 октября 2007 г.

How To configure Visual Studio 2005 for compiling drivers

As you should be know microsoft officially doesn`t support integration DDK with Visual Studio. So you can use Visual Studio editor (or any other editor) for make sources, but for compiling you should use the DDK build utility. Of course it is not very conveniently because you must always switch between editor and console window, but most terrible that developer spend much time for find lines with error in editor.

There are several ways to compile drivers with visual studio. Most of them you can find in nice Mark Roddy article "Windows Driver Build Methods and Tools" here: http://www.wd-3.com/archive/HowBuild.htm

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


1. Setup Visual Studio 2005 (I guess it can be any other VS version)

2. Setup DDK (or WDK)

3. Add to VS pathes to DDK include files and libs.

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

5. Configure project properties (All Configurations)

5.1. C\C++ - General - Debug Information Format = Program Database (/Zi)
5.2. C\C++ - Preprocessor - Preprocessor Definitions = _X86_ [comment: add also DBG for Debug config]
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) [comment: of course 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) [comment: you should add

needed libs here e.g. ntoskrnl.lib hal.lib]
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

6. 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;
}


If you have founded some mistakes or misundestoods please let me know.

Good Luck guys.

Комментариев нет: