|
windows 平台下的一个简单驱动 求sources文件写法
[复制链接]
[code]//////////////////////////////////////////////////
// DriverDemo.cpp????
//---------------------------DriverDemo.cpp????--------------------------------------//
extern "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;
DbgPrint(" DriverDemo: DriverEntry... \n");
// ???????÷??????????
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)
{
DbgPrint(" DriverDemo: DriverUnload... \n");
// ????·???????????
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)
{
DbgPrint(" DriverDemo: DispatchCreateClose... \n");
pIrp->IoStatus.Status = STATUS_SUCCESS;
// ?ê???????ó
IoCompleteRequest(pIrp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
文件名字为DriverDemo.cpp,求这个CPP文件的sources文件写法
|
|