新闻  |   论坛  |   博客  |   在线研讨会
USB鼠标的上层过滤型驱动程序
yanqin | 2009-04-16 22:29:28    阅读:9709   发布文章

AddDevice例程内容如下:

NTSTATUS VA_AddDevice
(
IN PDRIVER_OBJECT driverObj,
IN PDEVICE_OBJECT physicalDevObj

)
{
NTSTATUS status;
PDEVICE_OBJECT filterDevObj = NULL;

PAGED_CODE();

DBGOUT(("VA_AddDevice: 驱动对象=%ph, 物理设备对象=%ph", driverObj, physicalDevObj));

status = IoCreateDevice(
driverObj,
sizeof(struct DEVICE_EXTENSION),
NULL, // name for this device
FILE_DEVICE_MOUSE,
0, // device characteristics
FALSE, // not exclusive
&filterDevObj); // our device object

if ( NT_SUCCESS(status) ){
struct DEVICE_EXTENSION *devExt;

ASSERT( filterDevObj );

/*
* Initialize device extension for new device object
*/
devExt = ( struct DEVICE_EXTENSION * )filterDevObj->DeviceExtension;
RtlZeroMemory( devExt, sizeof(struct DEVICE_EXTENSION) );
devExt->signature = DEVICE_EXTENSION_SIGNATURE;
devExt->state = STATE_INITIALIZED;
devExt->filterDevObj = filterDevObj;
devExt->physicalDevObj = physicalDevObj;



devExt->pendingActionCount = 0;
KeInitializeEvent( &devExt->removeEvent, NotificationEvent, FALSE );
#ifdef HANDLE_DEVICE_USAGE
KeInitializeEvent(&devExt->deviceUsageNotificationEvent, SynchronizationEvent, TRUE);
#endif // HANDLE_DEVICE_USAGE

/*
* Attach the new device object to the top of the device stack.
*/
devExt->topDevObj = IoAttachDeviceToDeviceStack(filterDevObj, physicalDevObj);

ASSERT(devExt->topDevObj);
DBGOUT(("创建的过滤设备对象: %ph 挂接到设备对象堆栈: %ph.", filterDevObj, devExt->topDevObj));


//
// As a filter driver, we do not want to change the power or I/O
// behavior of the driver stack in any way. Recall that a filter
// driver should "appear" the same (almost) as the underlying device.
// Therefore we must copy some bits from the device object _directly_
// below us in the device stack (notice: DON‘T copy from the PDO!)
//


/* Various I/O-related flags which should be maintained */
/* (copy from lower device object) */
filterDevObj->Flags |= DO_BUFFERED_IO;
filterDevObj->Flags |= (devExt->topDevObj->Flags &
(DO_POWER_INRUSH | DO_POWER_PAGABLE ));

#ifdef HANDLE_DEVICE_USAGE

if ((devExt->topDevObj->Flags & DO_POWER_PAGABLE)){
}else{
DBGOUT(( "LOCKing some driver code (non-pageable) (b/c init conditions)" ));
devExt->initUnlockHandle = MmLockPagableCodeSection( VA_Power ); // some func that‘s inside the code section that we want to lock
ASSERT( NULL != devExt->initUnlockHandle );
}
devExt->initialFlags = filterDevObj->Flags & ~DO_DEVICE_INITIALIZING;
#endif // HANDLE_DEVICE_USAGE

filterDevObj->Flags &= ~DO_DEVICE_INITIALIZING;
RegistryAccessSample(devExt, devExt->physicalDevObj);
}

ASSERT(NT_SUCCESS(status));
return status;
}

用INF内容如下:
;***************************************************
;Zt_Usb_Mouse_Filter Driver‘s Inf file *
;name: ztmouse.inf *
;Date: 4/20/2005 *
;Composer: ting_Zhang *
;version 1.00.0.0 *
;***************************************************



;=========The "[Version]" begin================>>
[Version]
Signature="$Windows NT$"
SignOS=Windows 2000
Provider=%ProviderName%
Class=Mouse
ClassGUID={4D36E96F-E325-11CE-BFC1-08002BE10318}
DriverVer=04/20/2005,1.0.0.0
;<<=========The "[Version]" end==================


[DestinationDirs]
DefaultDestDir = 12


[Manufacturer]
%USBDBE%=USBDBEINS

[USBDBEINS]
%HID.DeviceDesc% = yyz,HID\VID_ba13&PID_b100

;HID\VID_046D&PID_C50B&Mi_01&Col01
;===================================
; Win2000 Installation sections
;===================================
[yyz.NT]
Include = msmouse.inf
Needs = HID_Mouse_Inst.NT
CopyFiles = yyz.CopyFiles


[yyz.CopyFiles]
yyx.sys




[yyz.NT.Services]
Addservice = yyx,0x00000002, yyz_Service_Inst
Include=msmouse.inf
Needs=HID_Mouse_Inst.NT.Services



[yyz.NT.HW]
AddReg = yyz_HW_AddReg
Include=msmouse.inf
Needs=HID_Mouse_Inst.NT.HW


[yyz_Service_Inst]
DisplayName = %HID.DeviceDesc%
ServiceType = 1
StartType = 3
ErrorControl = 1
LoadOrderGroup = Pointer Port
ServiceBinary = %12%\yyx.sys





[yyz_HW_AddReg]
;HKR,,"LowerFilters",0x00010000,"yyx"
HKR,,"UpperFilters",0x00010000,"yyx"



[SourceDisksNames]
1 = %DiskId1%

[SourceDisksFiles]
yyx.sys = 1





;=================the "[strings]" begin================>>
[strings]
USBDBE = "YongRui Electronics Co.,Ltd"
HID.ClassName = "Human Input Devices (HID)"
HID.DeviceDesc = "USB Mouse Fliter"
HID.DefaultDevice = "HID Default Device"

REG_SZ = 0x00000000
REG_MULTI_SZ = 0x00010000
REG_EXPAND_SZ = 0x00020000
REG_BINARY = 0x00000001
REG_DWORD = 0x00010001
;SERVICEROOT = "System\CurrentControlSet\Services"

DiskId1 = "Mouse Fliter Installation Disk #1 "
ProviderName = "YongRui Develop Department"


;<<================the "[strings]" end====================







*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
推荐文章
最近访客