qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

驱动程序测试问题

为什么我的测试程序测试不成功?
  测试程序的CreateFile的返回值-1, GetLastError 错误码是123(文件名、目录名或卷标语法不正确。)
  我的驱动程序加载后用winObj是可以查看到FirstDevice的 ,测试程序运行时就是失败 ???
  代码:
  驱动程序:
#include "ntddk.h"
NTSTATUS CreateDevice(PDRIVER_OBJECT pDriverObject);
NTSTATUS CreateComplateRoutine(PDEVICE_OBJECT pDeviceObj, PIRP pIrp);
NTSTATUS ReadComplateRoutine(PDEVICE_OBJECT pDeviceObj, PIRP pIrp);
NTSTATUS WriteComplateRoutine(PDEVICE_OBJECT pDeviceObj, PIRP pIrp);
NTSTATUS CloseComplateRoutine(PDEVICE_OBJECT pDeviceObj, PIRP pIrp);
VOID MyDriverUnoad(PDRIVER_OBJECT pDriverObject);
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject,PUNICODE_STRING pRegistryPath)
{
NTSTATUS status;
status = CreateDevice(pDriverObject);
KdPrint(("CreateDevice."));
if (!NT_SUCCESS(status))
{
KdPrint(("Create device faild."));
}
else
{
KdPrint(("Create device success."));
KdPrint(("%wZ", pRegistryPath));
}
pDriverObject->MajorFunction[IRP_MJ_CREATE] = CreateComplateRoutine;
pDriverObject->MajorFunction[IRP_MJ_READ] = ReadComplateRoutine;
pDriverObject->MajorFunction[IRP_MJ_WRITE] = WriteComplateRoutine;
pDriverObject->MajorFunction[IRP_MJ_CLOSE] = CloseComplateRoutine;
pDriverObject->DriverUnload = MyDriverUnoad;
return STATUS_SUCCESS;
}
NTSTATUS CreateDevice(PDRIVER_OBJECT pDriverObject)
{
NTSTATUS status;
PDEVICE_OBJECT pDevObj;
UNICODE_STRING usDevName;
UNICODE_STRING usSymName;
RtlInitUnicodeString(&usDevName, L"\\Device\\FirstDevice");
RtlInitUnicodeString(&usSymName, L"\\??\\FirstDevice");;
status = IoCreateDevice(pDriverObject,
0,
&usDevName,
FILE_DEVICE_UNKNOWN,
0,
TRUE,
&pDevObj);
pDevObj->Flags |= DO_BUFFERED_IO;
if (!NT_SUCCESS(status))
{
KdPrint(("IoCreateDevice faild."));
return status;
}
status = IoCreateSymbolicLink(&usSymName, &usDevName);
if (!NT_SUCCESS(status))
{
KdPrint(("IoCreateSymbolicLink faild."));
IoDeleteDevice(pDevObj);
return status;
}
return STATUS_SUCCESS;
}
NTSTATUS CreateComplateRoutine (PDEVICE_OBJECT pDeviceObj, PIRP pIrp)
{
NTSTATUS status;
status = STATUS_SUCCESS;
KdPrint(("Create"));
pIrp->IoStatus.Status = status;
pIrp->IoStatus.Information = 0;
IoCompleteRequest(pIrp, IO_NO_INCREMENT);
return status;
}
NTSTATUS ReadComplateRoutine (PDEVICE_OBJECT pDeviceObj, PIRP pIrp)
{
NTSTATUS status;
status = STATUS_SUCCESS;
return status;
}
NTSTATUS WriteComplateRoutine (PDEVICE_OBJECT pDeviceObj, PIRP pIrp)
{
NTSTATUS status;
status = STATUS_SUCCESS;
return status;
}
NTSTATUS CloseComplateRoutine (PDEVICE_OBJECT pDeviceObj, PIRP pIrp)
{
NTSTATUS status;
status = STATUS_SUCCESS;
return status;
}
VOID MyDriverUnoad(PDRIVER_OBJECT pDriverObject)
{
UNICODE_STRING usSymName;
RtlInitUnicodeString(&usSymName, L"\\??\\FirstDevice");
if (pDriverObject->DeviceObject != NULL)
{
IoDeleteSymbolicLink(&usSymName);
IoDeleteDevice(pDriverObject->DeviceObject);
KdPrint(("Delete device success!"));
}
}
 测试程序:
  代码:
void CTestMyFirstDriverDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
HANDLE hFile = CreateFile(L"\\??\\FirstDevice",
FILE_ALL_ACCESS,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
int err = GetLastError();
MessageBox(L"Create File error!");
}
CloseHandle(hFile);
return;
}

posted on 2014-01-24 16:13 顺其自然EVO 阅读(208) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 
<2014年1月>
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜