共用方式為


Compile a Kernel mode driver in Visual Studio with full intellisense

To compile a Kernel mode driver in VS 2005 or similar Visual Studio versions with intellisense, following steps can be useful. I thought this is a 'well known stuff' but I was asked recently by some of my customers a couple of times, so thought of documenting the same although obviously not supported.  

Nothing much but include the correct headers dir in the VC++ Directory. Very straight forward!

Please note the fact that this for compiling and intellisense not for Building.

Again, before steps,

My DDK is installed at

C:\WINDDK\3790_1218

Following code I complied ( never ever build it and load it into your kernel ) from air, just with the help of intellisense.

#define _X86_

#include <wdm.h>

NTSTATUS DriverEntry ( PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pRegistryPath )

{

PKIRQL pkirql = 0;

IoAcquireCancelSpinLock( pkirql );

}

With following warning ( we are not bothered to remove it )

------ Build started: Project: TestDirvCompile, Configuration: Debug Win32 ------

Compiling...

testdrv.c

c:\program files\microsoft visual studio 8\vc\platformsdk\include\basetsd.h(36) : warning C4005: 'POINTER_64' : macro redefinition

c:\winddk\3790_1218\inc\wxp\ntdef.h(137) : see previous definition of 'POINTER_64'

d:\myprojects\driverdev\mytest\anandtestsln\testdirvcompile\testdrv.c(11) : warning C4716: 'DriverEntry' : must return a value

Build log was saved at "file://d:\myProjects\DriverDev\mytest\anandtestsln\TestDirvCompile\Debug\BuildLog.htm"

TestDirvCompile - 0 error(s), 2 warning(s)

========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

intellisense

Being said that following are the steps.

1. Make sure that in your Tools > options, the required DDK include directories are given as in the following screen shot ( red rectangle). Or similar. If so. You are done!

DirVCPP

2. Make a C++ console application and try to compile some driver code by adding a C file, also test if the intellisense is working.

3. Also take out all the unnecessary Preprocess definitions and pre complied headers.

image

4. If intellisense is not working, close visual studio,  delete the big .ncb files in the solutions folder and restart visual studio.

Note

Tweaking the linker is a bit more involved also I don't recommend the same or even using the obj file you got from the above explained method. Please use DDK build for building your real binaries. The method we discussed is only for development effort leverage.

If you are looking for more automation and sophistication do something like

https://www.osronline.com/article.cfm?article=43