一个WDM驱动开发框架
下面是我起初学习WDM的时候的一个驱动开发框架。分享之。。。。。#include "DriverWDM.h"#pragma INITCODE
extern "C" NTSTATUS DriverEntry(IN PDRIVER_OBJECT pDriverObject,IN PUNICODE_STRING RegistryPath)
{
NTSTATUS status;
KdPrint(("enter DriverEntry\n"));
pDriverObject->DriverExtension->AddDevice = HelloWDMAddDevice;
pDriverObject->MajorFunction = HelloWDMPnp;
pDriverObject->MajorFunction =
pDriverObject->MajorFunction =
pDriverObject->MajorFunction = HelloDDKDispatchRoutine;
}
NTSTATUS HelloWDMAddDevice(IN PDRIVER_OBJECT pDriverObject,IN PDEVICE_OBJECT pPhysicalDeviceObject)
{
PAGED_CODE();
KdPrint(("Enter HelloWDMAddDevice\n"));
UNICODE_STRING devName; //设备名字
NTSTATUS status ;
PDEVICE_OBJECT fdo; //功能设备对象
PDEVICE_EXTENSION pdx; //设备扩展
RtlInitUnicodeString(&devName,L"\\Device\\MyWDMDevice");
status = IoCreateDevice(pDriverObject,sizeof(DEVICE_EXTENSION),&(UNICODE_STRING)devName,FILE_DEVICE_UNKNOWN,0,false,&fdo);
//判断是否成功创建设备
if(!NT_SUCCESS(status))
{
return status;
}
//得到设备扩展,然后填充它
pdx = (PDEVICE_EXTENSION)fdo->DeviceExtension;
pdx->fdo = fdo;
UNICODE_STRING symLinkName;
RtlInitUnicodeString(&symLinkName,L"\\DosDevices\\HelloWDM");
status = IoCreateSymbolicLink(&symLinkName,&devName);
//如果创建符号连接失败。则进行相应的删除操作
if (!NT_SUCCESS(status))
{
//再一次创建符号连接
IoDeleteSymbolicLink(&symLinkName);
status = IoCreateSymbolicLink(&symLinkName,&devName);
if(!NTSTATUS(status))
{
return status;
}
}
//在设备扩展中记录设备的符号名字和设备名字
pdx->ustrSymLinkName = symLinkName;
pdx->ustrDeviceName = devName;
//设置设备标志
fdo->Flags |= DO_BUFFERED_IO | DO_POWER_PAGABLE;
fdo->Flags &= ~DO_DEVICE_INITIALIZING;
KdPrint(("leave HelloWDMDevice\n"));
return STATUS_SUCCESS;
}
页:
[1]