从网上找了个驱动开发的例子按照其步骤不知道为什么编译不能成功,无法生成SYS文件
请大家帮忙看下!1.驱动程序源文件如下:
#ifndef __HELLOWORLD_C__
#define __HELLOWORLD_C__ #define DEBUGMSG #include <ntddk.h> #define DEVICE_HELLO_INDEX 0x860
#define START_HELLPWORLD CTL_CODE(FILE_DEVICE_UNKNOWN,DEVICE_HELLO_INDEX,METHOD_BUFFERED,FILE_ANY_ACCESS)
#define STOP_HELLPWORLD CTL_CODE(FILE_DEVICE_UNKNOWN,DEVICE_HELLO_INDEX+1,METHOD_BUFFERED,FILE_ANY_ACCESS) #define NT_DEVICE_NAME L"\\Device\\HelloWorld"
#define DOS_DEVICE_NAME L"\\DosDevices\\HelloWorld" NTSTATUS HelloWorldDispatch (IN PDEVICE_OBJECT DeviceObject,IN PIRP pIrp); VOID HelloWorldUnLoad (IN PDRIVER_OBJECT DriverObject);
NTSTATUS DriverEntry (IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath)
{
NTSTATUS ntStatus=STATUS_SUCCESS;
PDEVICE_OBJECT lpDeviceObject=NULL;
UNICODE_STRING DeviceNameString={0};
UNICODE_STRING DeviceLinkString={0};
#ifdef DEBUGMSG
DbgPrint("Starting DriverEntry()\n");
#endif RtlInitUnicodeString(&DeviceNameString,NT_DEVICE_NAME);
ntStatus=IoCreateDevice(DriverObject,0,&DeviceNameString,FILE_DEVICE_UNKNOWN,0,FALSE,&lpDeviceObject);
if (!NT_SUCCESS(ntStatus))
{
#ifdef DEBUGMSG
DbgPrint("IoCreateDevice() error reports 0x%08X\n",ntStatus);
#endif
return ntStatus;
} RtlInitUnicodeString(&DeviceLinkString,DOS_DEVICE_NAME);
ntStatus=IoCreateSymbolicLink(&DeviceLinkString,&DeviceNameString); if (!NT_SUCCESS(ntStatus))
{
#ifdef DEBUGMSG
DbgPrint("IoCreateSymbolicLink() error reports 0x%08X\n",ntStatus);
#endif
if (lpDeviceObject)
IoDeleteDevice(lpDeviceObject);
return ntStatus;
} DriverObject->MajorFunction[IRP_MJ_CREATE]=
DriverObject->MajorFunction[IRP_MJ_CLOSE]=
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL]=HelloWorldDispatch;
DriverObject->DriverUnload=HelloWorldUnLoad; return ntStatus;
} NTSTATUS HelloWorldDispatch (IN PDEVICE_OBJECT DeviceObject,IN PIRP pIrp)
{
NTSTATUS ntStatus=STATUS_SUCCESS;
PIO_STACK_LOCATION IrpStack=NULL;
ULONG IoControlCodes=0;
pIrp->IoStatus.Status=STATUS_SUCCESS;
pIrp->IoStatus.Information=0; #ifdef DEBUGMSG
DbgPrint("Starting HelloWorldDispatch()\n");
#endif IrpStack=IoGetCurrentIrpStackLocation(pIrp); switch (IrpStack->MajorFunction)
{
case IRP_MJ_CREATE:
#ifdef DEBUGMSG
DbgPrint("IRP_MJ_CREATE\n");
#endif
break; case IRP_MJ_CLOSE:
#ifdef DEBUGMSG
DbgPrint("IRP_MJ_CLOSE\n");
#endif
break; case IRP_MJ_DEVICE_CONTROL: #ifdef DEBUGMSG
DbgPrint("IRP_MJ_DEVICE_CONTROL\n");
#endif
IoControlCodes=IrpStack->Parameters.DeviceIoControl.IoControlCode; switch (IoControlCodes)
{
case START_HELLPWORLD:
DbgPrint("Starting \"Hello World\"\n");
break; case STOP_HELLPWORLD:
DbgPrint("Stoping \"Hello World\"\n");
break; default:
pIrp->IoStatus.Status=STATUS_INVALID_PARAMETER;
break;
} break; default:
break;
} ntStatus=pIrp->IoStatus.Status;
IoCompleteRequest(pIrp,IO_NO_INCREMENT); return ntStatus;
} VOID HelloWorldUnLoad (IN PDRIVER_OBJECT DriverObject)
{
UNICODE_STRING DeviceLinkString={0};
PDEVICE_OBJECT DeviceObjectTemp1=NULL;
PDEVICE_OBJECT DeviceObjectTemp2=NULL; #ifdef DEBUGMSG
DbgPrint("Starting HelloWorldUnLoad()\n");
#endif RtlInitUnicodeString(&DeviceLinkString,DOS_DEVICE_NAME); if (DeviceLinkString.Buffer)
IoDeleteSymbolicLink(&DeviceLinkString); if (DriverObject)
{
DeviceObjectTemp1=DriverObject->DeviceObject; while (DeviceObjectTemp1)
{
DeviceObjectTemp2=DeviceObjectTemp1;
DeviceObjectTemp1=DeviceObjectTemp1->NextDevice;
IoDeleteDevice(DeviceObjectTemp2);
}
}
} #endif
2.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 3.SOURCE文件如下:
TARGETNAME=HelloWorld
TARGETTYPE=DRIVER
TARGETPATH=objSOURCES=HelloWorld.c 我的NTDDK装在D:\Program Files\NTDDK下进入「开始」菜单\程序\Development Kits\Windows 2000 DDK,
使用Free Build Environment。
New or updated MSVC detected. Updating DDK environment....Setting environment for using Microsoft Visual C++ tools.
Starting dirs creation...Completed.
D:\PROGRA~1\NTDDK>E:
E:\>CD HelloWorld
E:\HelloWorld>build
BUILD: Object root set to: ==> objfre
BUILD: /i switch ignored
BUILD: Compile and Link for i386
BUILD: Loading D:\PROGRA~1\NTDDK\build.dat...
BUILD: Computing Include file dependencies:
BUILD: Saving D:\PROGRA~1\NTDDK\build.dat...
BUILD: Done执行完后并没有生成SYS文件,不知道什么地方出错了,请大虾指教!
请大家帮忙看下!1.驱动程序源文件如下:
#ifndef __HELLOWORLD_C__
#define __HELLOWORLD_C__ #define DEBUGMSG #include <ntddk.h> #define DEVICE_HELLO_INDEX 0x860
#define START_HELLPWORLD CTL_CODE(FILE_DEVICE_UNKNOWN,DEVICE_HELLO_INDEX,METHOD_BUFFERED,FILE_ANY_ACCESS)
#define STOP_HELLPWORLD CTL_CODE(FILE_DEVICE_UNKNOWN,DEVICE_HELLO_INDEX+1,METHOD_BUFFERED,FILE_ANY_ACCESS) #define NT_DEVICE_NAME L"\\Device\\HelloWorld"
#define DOS_DEVICE_NAME L"\\DosDevices\\HelloWorld" NTSTATUS HelloWorldDispatch (IN PDEVICE_OBJECT DeviceObject,IN PIRP pIrp); VOID HelloWorldUnLoad (IN PDRIVER_OBJECT DriverObject);
NTSTATUS DriverEntry (IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath)
{
NTSTATUS ntStatus=STATUS_SUCCESS;
PDEVICE_OBJECT lpDeviceObject=NULL;
UNICODE_STRING DeviceNameString={0};
UNICODE_STRING DeviceLinkString={0};
#ifdef DEBUGMSG
DbgPrint("Starting DriverEntry()\n");
#endif RtlInitUnicodeString(&DeviceNameString,NT_DEVICE_NAME);
ntStatus=IoCreateDevice(DriverObject,0,&DeviceNameString,FILE_DEVICE_UNKNOWN,0,FALSE,&lpDeviceObject);
if (!NT_SUCCESS(ntStatus))
{
#ifdef DEBUGMSG
DbgPrint("IoCreateDevice() error reports 0x%08X\n",ntStatus);
#endif
return ntStatus;
} RtlInitUnicodeString(&DeviceLinkString,DOS_DEVICE_NAME);
ntStatus=IoCreateSymbolicLink(&DeviceLinkString,&DeviceNameString); if (!NT_SUCCESS(ntStatus))
{
#ifdef DEBUGMSG
DbgPrint("IoCreateSymbolicLink() error reports 0x%08X\n",ntStatus);
#endif
if (lpDeviceObject)
IoDeleteDevice(lpDeviceObject);
return ntStatus;
} DriverObject->MajorFunction[IRP_MJ_CREATE]=
DriverObject->MajorFunction[IRP_MJ_CLOSE]=
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL]=HelloWorldDispatch;
DriverObject->DriverUnload=HelloWorldUnLoad; return ntStatus;
} NTSTATUS HelloWorldDispatch (IN PDEVICE_OBJECT DeviceObject,IN PIRP pIrp)
{
NTSTATUS ntStatus=STATUS_SUCCESS;
PIO_STACK_LOCATION IrpStack=NULL;
ULONG IoControlCodes=0;
pIrp->IoStatus.Status=STATUS_SUCCESS;
pIrp->IoStatus.Information=0; #ifdef DEBUGMSG
DbgPrint("Starting HelloWorldDispatch()\n");
#endif IrpStack=IoGetCurrentIrpStackLocation(pIrp); switch (IrpStack->MajorFunction)
{
case IRP_MJ_CREATE:
#ifdef DEBUGMSG
DbgPrint("IRP_MJ_CREATE\n");
#endif
break; case IRP_MJ_CLOSE:
#ifdef DEBUGMSG
DbgPrint("IRP_MJ_CLOSE\n");
#endif
break; case IRP_MJ_DEVICE_CONTROL: #ifdef DEBUGMSG
DbgPrint("IRP_MJ_DEVICE_CONTROL\n");
#endif
IoControlCodes=IrpStack->Parameters.DeviceIoControl.IoControlCode; switch (IoControlCodes)
{
case START_HELLPWORLD:
DbgPrint("Starting \"Hello World\"\n");
break; case STOP_HELLPWORLD:
DbgPrint("Stoping \"Hello World\"\n");
break; default:
pIrp->IoStatus.Status=STATUS_INVALID_PARAMETER;
break;
} break; default:
break;
} ntStatus=pIrp->IoStatus.Status;
IoCompleteRequest(pIrp,IO_NO_INCREMENT); return ntStatus;
} VOID HelloWorldUnLoad (IN PDRIVER_OBJECT DriverObject)
{
UNICODE_STRING DeviceLinkString={0};
PDEVICE_OBJECT DeviceObjectTemp1=NULL;
PDEVICE_OBJECT DeviceObjectTemp2=NULL; #ifdef DEBUGMSG
DbgPrint("Starting HelloWorldUnLoad()\n");
#endif RtlInitUnicodeString(&DeviceLinkString,DOS_DEVICE_NAME); if (DeviceLinkString.Buffer)
IoDeleteSymbolicLink(&DeviceLinkString); if (DriverObject)
{
DeviceObjectTemp1=DriverObject->DeviceObject; while (DeviceObjectTemp1)
{
DeviceObjectTemp2=DeviceObjectTemp1;
DeviceObjectTemp1=DeviceObjectTemp1->NextDevice;
IoDeleteDevice(DeviceObjectTemp2);
}
}
} #endif
2.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 3.SOURCE文件如下:
TARGETNAME=HelloWorld
TARGETTYPE=DRIVER
TARGETPATH=objSOURCES=HelloWorld.c 我的NTDDK装在D:\Program Files\NTDDK下进入「开始」菜单\程序\Development Kits\Windows 2000 DDK,
使用Free Build Environment。
New or updated MSVC detected. Updating DDK environment....Setting environment for using Microsoft Visual C++ tools.
Starting dirs creation...Completed.
D:\PROGRA~1\NTDDK>E:
E:\>CD HelloWorld
E:\HelloWorld>build
BUILD: Object root set to: ==> objfre
BUILD: /i switch ignored
BUILD: Compile and Link for i386
BUILD: Loading D:\PROGRA~1\NTDDK\build.dat...
BUILD: Computing Include file dependencies:
BUILD: Saving D:\PROGRA~1\NTDDK\build.dat...
BUILD: Done执行完后并没有生成SYS文件,不知道什么地方出错了,请大虾指教!
TARGETNAME=HelloWorld
TARGETTYPE=DRIVER
TARGETPATH=objSOURCES=HelloWorld.c
TARGETTYPE=DRIVER
TARGETPATH=objSOURCES=HelloWorld.c
保存的文件名应该是sources不是source