为什么找不到驱动的句柄啊,救命啊~~~~
驱动代码:
#include <ntddk.h>
void MyDriverUnload(PDRIVER_OBJECT pDriverObject);
NTSTATUS CreateMyDevice(PDRIVER_OBJECT pDriverObject);
#define INITCODE code_seg("INIT")
#define PAGECODE code_seg("PAGE")
#pragma INITCODE
extern "C"
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject,PUNICODE_STRING pRegistryPath)
{
pDriverObject->DriverUnload=MyDriverUnload;
CreateMyDevice(pDriverObject);
return STATUS_SUCCESS;
}
#pragma PAGECODE
void MyDriverUnload(PDRIVER_OBJECT pDriverObject)
{
PDEVICE_OBJECT pDev;
UNICODE_STRING symbolicName;
RtlInitUnicodeString(&symbolicName,L"\\??\\BigAss");
IoDeleteSymbolicLink(&symbolicName);
pDev=pDriverObject->DeviceObject;
IoDeleteDevice(pDev);
}
NTSTATUS CreateMyDevice(PDRIVER_OBJECT pDriverObject)
{
NTSTATUS status;
PDEVICE_OBJECT pDevObj;
UNICODE_STRING devName;
UNICODE_STRING symbolicName;
RtlInitUnicodeString(&devName,L"\\Device\\ShitDriver");
status=IoCreateDevice(pDriverObject,0,&devName,FILE_DEVICE_UNKNOWN,0,TRUE,&pDevObj);
if (!NT_SUCCESS(status))
{
return status;
}
RtlInitUnicodeString(&symbolicName,L"\\??\\BigAss");
status=IoCreateSymbolicLink(&symbolicName,&devName);
if (!NT_SUCCESS(status))
{
IoDeleteDevice(pDevObj);
return status;
}
return STATUS_SUCCESS;
}
WIN32 控制台程序代码:
#include "stdafx.h"
#include <windows.h>
int main(int argc, char* argv[])
{
HANDLE hDevice;
hDevice=CreateFile("\\\\.\\BigAss",GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if (hDevice == INVALID_HANDLE_VALUE)
{
printf("获取驱动句柄失败: %s with Win32 error code: %d\n","MyDriver", GetLastError() );
getchar();
return -1;
}
printf("start\n",hDevice);
getchar();
return 0;
}
驱动加载后,控制台程序显示的是“获取驱动句柄失败:MyDriver with Win32 error code: 1”,想破头也想不出哪错了,高手救命啊~~~!!!