我用的是windows xp系统和winXP DDK
1 原始环境
三个文件(如放在d:/test目录中):makefile(无后缀名)、Source(无后缀名)、test.c。
makefile内容:
#
# DO NOT EDIT THIS FILE!!! Edit ./sources. if you want to add a new source
# file to this component. This file merely indirects to the real make file
# that is shared by all the driver components of the Windows NT DDK
#
!INCLUDE $(NTMAKEENV)/makefile.def
Sources内容:
TARGETNAME=usbdriver
TARGETTYPE=DRIVER
DRIVERTYPE=WDM
TARGETPATH=obj
INCLUDES=$(BASEDIR)/inc;
SOURCES=test.c
BROWSER_INFO = 1
test.c内容:
#include <wdm.h>
NTSTATUS DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
);
VOID Unload(
IN PDRIVER_OBJECT DriverObject
);
#pragma code_seg("INIT")
NTSTATUS DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
)
{
PDEVICE_OBJECT pDeviceObject = NULL;
NTSTATUS Status = IoCreateDevice(
DriverObject,
0,
NULL,
FILE_DEVICE_UNKNOWN,
0,
FALSE,
&pDeviceObject
);
if ( NT_SUCCESS(Status) )
{
DriverObject->DriverUnload= Unload;
}
return Status;
}
#pragma code_seg()
VOID Unload(
IN PDRIVER_OBJECT DriverObject
)
{
IoDeleteDevice(DriverObject->DeviceObject);
}
选择“开始”菜单,“程序”,“Development Kits”,"Windows DDK 2600","Build Environments","Win XP Checked Build Environment"
进入cmd窗口后输入"d:",回车,"cd d:/test",回车,"build -b -w -cef",OK!,test/objchk/i386目录下已生成test.sys,如有错,查看buildchk.log文件。
2 VC环境
打开VC,新建一Makefile工程放在d:/test目录下(在new对话框的project页中选Makefile,直接点finish生成),选择菜单"project","settings",参数如下:
Settings For: "Win32 Debug"
Build Command Line: MakeDrvr
Rebuild All Options: -nmake /a
Output filename: test.sys
Browse info file name: objchk/i386/test.bsc
同样将makefile,sources和test.c三个文件加入或新建添加到工程中
在d:/test目录下新建一文件
@echo off
call c:/WINDDK/2600/bin/setenv.bat c:/WINDDK/2600 chk
d: (说明:这是你源程序所在驱动器名)
cd d:/test (说明:这是你源程序所在目录名)
build -b -w -cef
将文件中两处c:/WINDDK/2600改成你安装DDK目录
好了,在VC中build你的工程,compile不可用!
----------------------------------------------------------
如你的源程序文件有多个,则需更改sources文件
SOURCES=file1.c file2.c file3.cpp test.rc
头文件无需加入
如你的源程序还含有子目录(子目录中有需要编译的源程序文件),还需加入dir文件,详细请查文档。
注意在你的驱动程序目录名中不能含有空格键,否则的话出错(如My Documents),在buildchk.log文件中有"'jvc' 不是内部或外部命令,也不是可运行的程序或批处理文件。"出错信息。