📄 charfilterdevice.cpp
字号:
// CharFilterDevice.cpp
// Implementation of CharFilterDevice device class
//
// Generated by DriverWizard version DriverStudio 3.1.0 (Build 1722)
// Requires Compuware's DriverWorks classes
//
#include <vdw.h>
#include <Kwdmfltr.cpp>
#include "CharFilterDevice.h"
#include "..\CharSampleioctl.h"
////////////////////////////////////////////////////////////////////////
// CharFilterDevice::CharFilterDevice
//
// Routine Description:
// This is the constructor for the Filter Device Object.
// It is derived from KWdmFilterDevice, which builds in automatic
// dispatching of subfunctions of IRP_MJ_POWER and IRP_MJ_PNP to
// virtual member functions.
//
// Parameters:
// Pdo - Physical Device Object - this is a pointer to a system
// device object that represents the physical device.
//
// Unit - Unit number. This is a number to append to the device's
// base device name to form the Logical Device Object's name
//
// Return Value:
// None
//
// Comments:
// The object being constructed contains a data member (m_Lower) of type
// KPnpLowerDevice. By initializing it, the driver binds the Filter
// Device Object to the device stack.
//
CharFilterDevice::CharFilterDevice(PDEVICE_OBJECT Pdo, ULONG Unit) :
KWdmFilterDevice(Pdo, NULL)
{
// Check constructor status
if ( !NT_SUCCESS(m_ConstructorStatus) )
{
return;
}
// Remember our unit number
m_Unit = Unit;
// Initialize the lower device
m_Lower.Initialize(this, Pdo);
// Attach the filter
NTSTATUS status = AttachFilter(&m_Lower);
// Check the status
if ( !NT_SUCCESS(status) )
{
m_ConstructorStatus = status;
return;
}
// Initialize the Filter Power Policy settings
SetFilterPowerPolicy();
// Initialize the Filter PnP Policy settings
SetFilterPnpPolicy();
}
NTSTATUS CharFilterDevice::DeviceControl(KIrp I)
{
switch (I.IoctlCode())
{
case CHARSAMPLE_IOCTL_800:
{
READ_COMPLETION_INFO* pCompInfo =
new (NonPagedPool) READ_COMPLETION_INFO;
//创建一个READ_COMPLETION_INFO结构对象
if ( pCompInfo == NULL )
{
return STATUS_INSUFFICIENT_RESOURCES;
}
RtlZeroMemory(pCompInfo,sizeof(READ_COMPLETION_INFO));//清0处理
//设置结构对象中的参数,同CharFilter中的完全一样
pCompInfo->m_pClass = this;
pCompInfo->nin=I.IoctlInputBufferSize();
pCompInfo->cin=new (NonPagedPool) CHAR[pCompInfo->nin];
if ( pCompInfo->cin == NULL )
{
delete pCompInfo;
return STATUS_INSUFFICIENT_RESOURCES;
}
pCompInfo->nout=I.IoctlOutputBufferSize();
pCompInfo->cout=new (NonPagedPool) CHAR[pCompInfo->nout];
if ( pCompInfo->cout == NULL )
{
delete pCompInfo->cin;
delete pCompInfo;
return STATUS_INSUFFICIENT_RESOURCES;
}
strncpy(pCompInfo->cin,(PCHAR)I.IoctlBuffer(),pCompInfo->nin);
I.FileObject()->FsContext = pCompInfo;
//将该结构对象地址指针放在I.FileObject()->FsContext中
return PassThrough(I, LinkTo(IrpCompletionRoutine), this);
}
default:
// Unrecognized IOCTL request
return PassThrough(I);
}
}
NTSTATUS CharFilterDevice::IrpCompletionRoutine(KIrp I)
{
READ_COMPLETION_INFO* pCompInfo =
(READ_COMPLETION_INFO*)I.FileObject()->FsContext;
if ( pCompInfo == NULL ) return I.Status();
//构造一个结构对象,地址指向DeviceControl中创建的结构对象
//IrpCompletionRoutine处理,同CharFilter中的完全一样
strncpy(pCompInfo->cout,(PCHAR)I.IoctlBuffer(),2);
pCompInfo->cout += 2;
pCompInfo->nin -= 1;
if (pCompInfo->nin == 0)
{
pCompInfo->cout -= pCompInfo->nout;
strncpy((PCHAR)I.IoctlBuffer(),pCompInfo->cout,pCompInfo->nout);
I.Information() = pCompInfo->nout;
if (pCompInfo->cout) delete pCompInfo->cout;
pCompInfo->cin -= (pCompInfo->nout - 2)/2;
if (pCompInfo->cin) delete pCompInfo->cin;
if (pCompInfo) delete pCompInfo;
I.FileObject()->FsContext = NULL;
return I.Status();
}
else
{
pCompInfo->cin++;
strncpy((PCHAR)I.IoctlBuffer(),pCompInfo->cin,1);
PassThrough(I, LinkTo(IrpCompletionRoutine), this);
return STATUS_MORE_PROCESSING_REQUIRED;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -