-
-
[求助]CreateFileW失败 GetLastError错误代码2
-
发表于:
2016-2-14 13:10
6350
-
[求助]CreateFileW失败 GetLastError错误代码2
驱动的代码
#include<ntddk.h>
#include<Strsafe.h>
PDEVICE_OBJECT device_object ;
NTSTATUS cwkDispatch(PDEVICE_OBJECT dev, PIRP irp)
{
irp->IoStatus.Information = 0;
IoCompleteRequest(irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
VOID DriverUnload(PDRIVER_OBJECT driver_object)
{
UNICODE_STRING usLinkName;
RtlInitUnicodeString(&usLinkName, L"\\??\\wdfabifbuadfba");
IoDeleteSymbolicLink(&usLinkName);
IoDeleteDevice(device_object);
}
NTSTATUS DriverEntry(PDRIVER_OBJECT driver_object, PUNICODE_STRING reg_part)
{
driver_object->DriverUnload = DriverUnload;
UNICODE_STRING str;
RtlInitUnicodeString(&str, L"\\Device\\DeviceName");
IoCreateDevice(driver_object,0,&str, FILE_DEVICE_UNKNOWN,FILE_DEVICE_SECURE_OPEN,TRUE, &device_object);
UNICODE_STRING usLinkName;
RtlInitUnicodeString(&usLinkName, L"\\??\\wdfabifbuadfba");
IoCreateSymbolicLink(&str, &usLinkName);
for (int i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; ++i)
{
driver_object->MajorFunction[i] = cwkDispatch;
}
return STATUS_SUCCESS;
}
应用代码
hFile= CreateFileW(L"\\\\.\\wdfabifbuadfba",
GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
NULL);
IoCreateSymbolicLink第二个参数传入应该是\??\还是\DosDevices\
谢谢各位
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!