源码:张栗炜虚拟键盘设备驱动
下载地址:http://www.pudn.com/downloads229/sourcecode/windows/vxd/detail1077750.html (yyxhhx 2014年提供)
今天调试了虚拟键盘的源码,发现几个问题。在这里不贴全部代码了,有兴趣的可以去下载,
编译环境是VC6.0,DDK版本是NTDDK,
通讯方式是:DeviceControl的缓冲区
直接上源码:
#include "VKeyFdo.h"
#include "..\inc\vkIoctl.h"
extern "C"
{
#include "hidport.h"
}
/
#pragma code_seg("INIT") // start INIT section
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath)
{
// Export other driver entry points...
DriverObject->DriverExtension->AddDevice = AddDevice;
DriverObject->MajorFunction[IRP_MJ_CREATE ] = Create;
DriverObject->MajorFunction[IRP_MJ_CLOSE ] = Close;
DriverObject->MajorFunction[IRP_MJ_PNP ] = Pnp;
DriverObject->MajorFunction[IRP_MJ_POWER ] = Power;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL ] = DeviceControl;
DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = InternalControl;
DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL ] = SystemControl;
extern PDEVICE_OBJECT FunctionDevice;
NTSTATUS status = STATUS_SUCCESS;
UNICODE_STRING deviceNameUnicodeString;
RtlInitUnicodeString(&deviceNameUnicodeString, NT_DEVICE_NAME);
status = IoCreateDevice(DriverObject,
0,
&deviceNameUnicodeString,
FILE_DEVICE_UNKNOWN,
0,
false,
&FunctionDevice);
if (!NT_SUCCESS(status))
{
return status;
}
UNICODE_STRING deviceLinkUnicodeString;
RtlInitUnicodeString(&deviceLinkUnicodeString, DOS_DEVICE_NAME);
status = IoCreateSymbolicLink(&deviceLinkUnicodeString,
&deviceNameUnicodeString);
if (!NT_SUCCESS(status))
{
if (FunctionDevice)
{
IoDeleteDevice(FunctionDevice);
return status;
}
}
// Set fdo flags appropriately
FunctionDevice->Flags |= DO_BUFFERED_IO | DO_POWER_PAGABLE;
FunctionDevice->Flags &= ~DO_DEVICE_INITIALIZING;
return STATUS_SUCCESS;
}
#pragma code_seg() // end INIT section
/
/
#pragma code_seg("PAGE") // start PAGE section
VOID Unload(IN PDRIVER_OBJECT DriverObject)
{
}
//
#pragma code_seg() // end PAGE section
不足之处:
1、wdm的设备连接符创建不在DrvierEntry
2、参数传递应该放在扩展设备处,过多的全局变量导致了多余的异常处理