|
关于windows 2003 sp1 DDK(Windows DDK 3790.1830)版本中DDK编译驱动程序的问题,使用编译环境是windows xp,各个文件如下:
1、sources文件:
TARGETNAME=Test
TARGETPATH=obj
TARGETTYPE=DRIVER
SOURCES=11DriverDemo.c
2、源文件11DriverDemo.c:
#include
// 自定义函数的声明
NTSTATUS DispatchCreateClose(PDEVICE_OBJECT pDevObj, PIRP pIrp);
void DriverUnload(PDRIVER_OBJECT pDriverObj);
// 驱动内部名称和符号连接名称
#define DEVICE_NAME L"\\Device\\devDriverDemo"
#define LINK_NAME L"\\??\\slDriverDemo"
// 驱动程序加载时调用DriverEntry例程
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObj, PUNICODE_STRING pRegistryString)
{
NTSTATUS status = STATUS_SUCCESS;
// 初始化各个派遣例程
pDriverObj->MajorFunction[IRP_MJ_CREATE] = DispatchCreateClose;
pDriverObj->MajorFunction[IRP_MJ_CLOSE] = DispatchCreateClose;
pDriverObj->DriverUnload = DriverUnload;
// 创建、初始化设备对象
// 设备名称
UNICODE_STRING ustrDevName;
RtlInitUnicodeString(&ustrDevName, DEVICE_NAME);
// 创建设备对象
PDEVICE_OBJECT pDevObj;
status = IoCreateDevice(pDriverObj,
0,
&ustrDevName,
FILE_DEVICE_UNKNOWN,
0,
FALSE,
&pDevObj);
if(!NT_SUCCESS(status))
{
return status;
}
// 创建符号连接名称
// 符号连接名称
UNICODE_STRING ustrLinkName;
RtlInitUnicodeString(&ustrLinkName, LINK_NAME);
// 创建关联
status = IoCreateSymbolicLink(&ustrLinkName, &ustrDevName);
if(!NT_SUCCESS(status))
{
IoDeleteDevice(pDevObj);
return status;
}
return STATUS_SUCCESS;
}
void DriverUnload(PDRIVER_OBJECT pDriverObj)
{
// 删除符号连接名称
UNICODE_STRING strLink;
RtlInitUnicodeString(&strLink, LINK_NAME);
IoDeleteSymbolicLink(&strLink);
// 删除设备对象
IoDeleteDevice(pDriverObj->DeviceObject);
}
// 处理IRP_MJ_CREATE、IRP_MJ_CLOSE功能代码
NTSTATUS DispatchCreateClose(PDEVICE_OBJECT pDevObj, PIRP pIrp)
{
pIrp->IoStatus.Status = STATUS_SUCCESS;
// 完成此请求
IoCompleteRequest(pIrp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
在Windows XP Checked Build Environment环境中编译命令为build -cZg,编译结果是
F:\PROGRA~1\WINDDK>e:
E:\>cd aboutprogram\coding\driver
E:\aboutprogram\coding\driver>build -cZg
BUILD: Adding /Y to COPYCMD so xcopy ops won't hang.
BUILD: Object root set to: ==> objchk_wxp_x86
BUILD: Compile and Link for i386
BUILD: Examining e:\aboutprogram\coding\driver directory for files to compile.
BUILD: Compiling (NoSync) e:\aboutprogram\coding\driver directory
Compiling - 11driverdemo.c for i386
errors in directory e:\aboutprogram\coding\driver
11driverdemo.c(31) : error C2275: 'UNICODE_STRING' : illegal use of this type as an expression
11driverdemo.c(31) : error C2146: syntax error : missing ';' before identifier 'ustrDevName'
11driverdemo.c(31) : error C2144: syntax error : '' should be preceded by ''
11driverdemo.c(31) : error C2144: syntax error : '' should be preceded by ''
11driverdemo.c(31) : error C2143: syntax error : missing ';' before 'identifier'
11driverdemo.c(31) : error C2065: 'ustrDevName' : undeclared identifier
11driverdemo.c(32) : error C4133: 'function' : incompatible types - from 'int *' to 'PUNICODE_STRING'
11driverdemo.c(34) : error C2275: 'PDEVICE_OBJECT' : illegal use of this type as an expression
11driverdemo.c(34) : error C2146: syntax error : missing ';' before identifier 'pDevObj'
11driverdemo.c(34) : error C2144: syntax error : '' should be preceded by ''
11driverdemo.c(34) : error C2144: syntax error : '' should be preceded by ''
11driverdemo.c(34) : error C2143: syntax error : missing ';' before 'identifier'
11driverdemo.c(34) : error C2065: 'pDevObj' : undeclared identifier
11driverdemo.c(37) : error C4133: 'function' : incompatible types - from 'int *' to 'PUNICODE_STRING'
11driverdemo.c(41) : error C4047: 'function' : 'PDEVICE_OBJECT * ' differs in levels of indirection from 'int *'
11driverdemo.c(49) : error C2275: 'UNICODE_STRING' : illegal use of this type as an expression
11driverdemo.c(49) : error C2146: syntax error : missing ';' before identifier 'ustrLinkName'
11driverdemo.c(49) : error C2144: syntax error : '' should be preceded by ''
11driverdemo.c(49) : error C2144: syntax error : '' should be preceded by ''
11driverdemo.c(49) : error C2143: syntax error : missing ';' before 'identifier'
11driverdemo.c(49) : error C2065: 'ustrLinkName' : undeclared identifier
11driverdemo.c(50) : error C4133: 'function' : incompatible types - from 'int *' to 'PUNICODE_STRING'
11driverdemo.c(52) : error C4133: 'function' : incompatible types - from 'int *' to 'PUNICODE_STRING'
11driverdemo.c(52) : error C4133: 'function' : incompatible types - from 'int *' to 'PUNICODE_STRING'
11driverdemo.c(55) : error C4047: 'function' : 'PDEVICE_OBJECT' differs in levels of indirection from 'int'
BUILD: Compile errors: not linking e:\aboutprogram\coding\driver directory
BUILD: Done
2 files compiled - 25 Errors
E:\aboutprogram\coding\driver>
请高手帮忙解决问题
|
|