⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdevice.cpp

📁 赠送两个学生毕业设计
💻 CPP
字号:
// testDevice.cpp
//
// Generated by DriverWizard 3.2.0 (Build 2485)
// Requires DDK and DriverWorks
// File created on 6/8/2007
//
// This source file contains the implementation of a subclass of KWdmFilterDevice.
// WDM filter drivers declare a subclass of KWdmFilterDevice and override member
// functions to filter requests (IRPs) from the system.  The default behavior
// of base class methods is to pass all IRPs thru to the lower driver.  Only
// override those IRP handlers to add custom processing for a particular IRP.
//

#include <vdw.h>
#include <Kwdmfltr.cpp>
#include "testDevice.h"

#pragma hdrstop("test.pch")

// Global driver trace object
// TODO:	Use KDebugOnlyTrace if you want trace messages
//			to appear only in checked builds.  Use KTrace if
//			you want trace messages to always appear.  Call
//			method SetOutputLevel to set the output threshold.
// TODO:	For any KIrp, to display the contents of the IRP
//			in a formatted way, use the KTrace << operator:
//				T << I;
extern KDebugOnlyTrace T;

///////////////////////////////////////////////////////////////////////////////////////////////////
//  testDevice::testDevice
//		This is the constructor for the class representing the Filter
//		Device Object, or FiDO.  It is derived from KWdmFilterDevice, which builds
//		in automatic dispatching of IRPs to virtual member functions.  The default
//		behavior of the base class virtual member functions (IRP handlers) is to
//		pass-thru all requests.  It is only necessary to override virtual member
//		functions to add custom processing to an IRP handler.
//		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.
//
//	Arguments:
//		IN	Pdo
//				Physical Device Object.  This is a pointer to a system
//				device object that represents the physical device.
//
//		IN	Unit
//				Unit number to append to the device's base device name 
//				to distinguish multiple units of this device type.
//
//	Return Value:
//		none
//
testDevice::testDevice(PDEVICE_OBJECT Pdo, ULONG Unit) :
	KWdmFilterDevice(Pdo, NULL),
	m_Unit(Unit)
{
	if (!NT_SUCCESS(m_ConstructorStatus))
	{
		T.Trace(TraceError, __FUNCTION__": Failed to create device testDevice"
			" unit number %d status %x\n", Unit, m_ConstructorStatus);
		ASSERT(FALSE);
		return;
	}

	// Initialize the lower device
	m_Lower.Initialize(this, Pdo);

	// Attach the filter
	m_ConstructorStatus = AttachFilter(&m_Lower); 

	// Check the status
	if ( !NT_SUCCESS(m_ConstructorStatus) )
	{
		T.Trace(TraceError, __FUNCTION__": Failed to attach filter device testDevice"
			" unit number %d status %x\n", Unit, m_ConstructorStatus);
		ASSERT(FALSE);
		return;
	}

	// Initialize the Filter Power Policy settings 
	SetFilterPowerPolicy();

	// Initialize the Filter PnP Policy settings 
	SetFilterPnpPolicy();
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  testDevice::~testDevice
//		This is the destructor for the class. 
//
//	Arguments:
//		none
//
//	Return Value:
//		none
//
testDevice::~testDevice()
{
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  testDevice::IrpCompletionRoutine
//		Completion Handler for IRPs
//		This routine is called when the lower driver completes the request
//
//	Arguments:
//		IN	I 
//			the IRP completed by lower driver
//
//	Return Value:
//		NTSTATUS 
//			Result returned from lower device
//
NTSTATUS testDevice::IrpCompletionRoutine(KIrp I)
{
	NTSTATUS status = I.Status();

	T.Trace(TraceInfo, __FUNCTION__" IRP %p, STATUS %x\n", I, status);

	// TODO: Add driver specific code to process the IRP that the lower 
	// device has completed.

	return status;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  testDevice::OnStartDevice
//		Handler for IRP_MJ_PNP subfcn IRP_MN_START_DEVICE. 
//		There is no required functionality here, other than to pass the IRP 
//		through to the lower device. However, the handler exercises some of  
//		the other functions of KPnpLowerDevice, and displays information to 
//		the debug console about the lower device that is filtered.
//
//	Arguments:
//		IN	I
//			the start device IRP
//
//	Return Value:
//		NTSTATUS
//
NTSTATUS testDevice::OnStartDevice(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);

	NTSTATUS status = STATUS_SUCCESS;

	// Retrieve some interesting information about the lower device
	// that is being filtered and display to the debug console

#define BUF_LEN 256
	USHORT buf[BUF_LEN];
	ULONG PropLen;

	m_Lower.GetDeviceDescription( buf, sizeof(buf), &PropLen );
	T.Trace(TraceInfo, "Device Description: |%s|\n", buf);

	m_Lower.GetPhysicalObjectName( buf, sizeof(buf), &PropLen );
	T.Trace(TraceInfo, "PDO Name: |%s|\n", buf);

	m_Lower.GetHardwareID( buf, sizeof(buf), &PropLen );
	T.Trace(TraceInfo, "Hardware ID: |%s|\n", buf);

	m_Lower.GetClassName( buf, sizeof(buf), &PropLen );
	T.Trace(TraceInfo, "Class Name: |%s|\n", buf);

	m_Lower.GetManufacturer( buf, sizeof(buf), &PropLen );
	T.Trace(TraceInfo, "Manufacturer: |%s|\n", buf);

	PCM_RESOURCE_LIST pcrl;
	m_Lower.GetBootConfiguration( FALSE, &pcrl, &PropLen ); 

	status = PassThrough(I);

	T.Trace(TraceInfo, __FUNCTION__"--.  IRP %p, STATUS %x\n", I, status);

	return status;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  testDevice::OnStopDevice
//		Handler for IRP_MJ_PNP subfcn IRP_MN_STOP_DEVICE. 
//
//	Arguments:
//		IN	I
//			the stop device IRP
//
//	Return Value:
//		NTSTATUS
//
NTSTATUS testDevice::OnStopDevice(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);

	// TODO: Add driver specific code to process the IRP prior to forwarding
	// to the lower device.  Call PassThrough() to send the IRP to the lower 
	// device.  Optionally, use the commented out code to use a completion 
	// routine to process the IRP after the lower device has completed it:
	//
	// NTSTATUS = PassThrough(I, LinkTo(IrpCompletionRoutine), this);

	// This implementation simply forwards the IRP to the lower device.
	NTSTATUS status = PassThrough(I);

	T.Trace(TraceInfo, __FUNCTION__"--.  IRP %p, STATUS %x\n", I, status);

	return status;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  testDevice::OnRemoveDevice
//		Handler for IRP_MJ_PNP subfcn IRP_MN_REMOVE_DEVICE. 
//
//	Arguments:
//		IN	I
//			the remove device IRP
//
//	Return Value:
//		NTSTATUS
//
NTSTATUS testDevice::OnRemoveDevice(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);

	// TODO: Add driver specific code to process the IRP prior to forwarding
	// to the lower device.  Call PassThrough() to send the IRP to the lower 
	// device.  Optionally, use the commented out code to use a completion 
	// routine to process the IRP after the lower device has completed it:
	//
	// NTSTATUS = PassThrough(I, LinkTo(IrpCompletionRoutine), this);

	// This implementation simply forwards the IRP to the lower device.
	NTSTATUS status = PassThrough(I);

	T.Trace(TraceInfo, __FUNCTION__"--.  IRP %p, STATUS %x\n", I, status);

	return status;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  testDevice::OnQueryRemoveDevice
//		Handler for IRP_MJ_PNP subfcn IRP_MN_QUERY_REMOVE_DEVICE. 
//
//	Arguments:
//		IN	I
//			the query remove device IRP
//
//	Return Value:
//		NTSTATUS
//
NTSTATUS testDevice::OnQueryRemoveDevice(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);

	// TODO: Add driver specific code to process the IRP prior to forwarding
	// to the lower device.  Call PassThrough() to send the IRP to the lower 
	// device.  Optionally, use the commented out code to use a completion 
	// routine to process the IRP after the lower device has completed it:
	//
	// NTSTATUS = PassThrough(I, LinkTo(IrpCompletionRoutine), this);

	// This implementation simply forwards the IRP to the lower device.
	NTSTATUS status = PassThrough(I);

	T.Trace(TraceInfo, __FUNCTION__"--.  IRP %p, STATUS %x\n", I, status);

	return status;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  testDevice::OnSurpriseRemoval
//		Handler for IRP_MJ_PNP subfcn IRP_MN_SURPRISE_REMOVAL. 
//
//	Arguments:
//		IN	I
//			the surprise remove device IRP
//
//	Return Value:
//		NTSTATUS
//
NTSTATUS testDevice::OnSurpriseRemoval(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);

	// TODO: Add driver specific code to process the IRP prior to forwarding
	// to the lower device.  Call PassThrough() to send the IRP to the lower 
	// device.  Optionally, use the commented out code to use a completion 
	// routine to process the IRP after the lower device has completed it:
	//
	// NTSTATUS = PassThrough(I, LinkTo(IrpCompletionRoutine), this);

	// This implementation simply forwards the IRP to the lower device.
	NTSTATUS status = PassThrough(I);

	T.Trace(TraceInfo, __FUNCTION__"--.  IRP %p, STATUS %x\n", I, status);

	return status;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  testDevice::OnCancelRemoveDevice
//		Handler for IRP_MJ_PNP subfcn IRP_MN_CANCEL_REMOVE_DEVICE. 
//
//	Arguments:
//		IN	I
//			the cancel remove device IRP
//
//	Return Value:
//		NTSTATUS
//
NTSTATUS testDevice::OnCancelRemoveDevice(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);

	// TODO: Add driver specific code to process the IRP prior to forwarding
	// to the lower device.  Call PassThrough() to send the IRP to the lower 
	// device.  Optionally, use the commented out code to use a completion 
	// routine to process the IRP after the lower device has completed it:
	//
	// NTSTATUS = PassThrough(I, LinkTo(IrpCompletionRoutine), this);

	// This implementation simply forwards the IRP to the lower device.
	NTSTATUS status = PassThrough(I);

	T.Trace(TraceInfo, __FUNCTION__"--.  IRP %p, STATUS %x\n", I, status);

	return status;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  testDevice::OnQueryStopDevice
//		Handler for IRP_MJ_PNP subfcn IRP_MN_QUERY_STOP_DEVICE. 
//
//	Arguments:
//		IN	I
//			the query stop device IRP
//
//	Return Value:
//		NTSTATUS
//
NTSTATUS testDevice::OnQueryStopDevice(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);

	// TODO: Add driver specific code to process the IRP prior to forwarding
	// to the lower device.  Call PassThrough() to send the IRP to the lower 
	// device.  Optionally, use the commented out code to use a completion 
	// routine to process the IRP after the lower device has completed it:
	//
	// NTSTATUS = PassThrough(I, LinkTo(IrpCompletionRoutine), this);

	// This implementation simply forwards the IRP to the lower device.
	NTSTATUS status = PassThrough(I);

	T.Trace(TraceInfo, __FUNCTION__"--.  IRP %p, STATUS %x\n", I, status);

	return status;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  testDevice::OnCancelStopDevice
//		Handler for IRP_MJ_PNP subfcn IRP_MN_CANCEL_STOP_DEVICE. 
//
//	Arguments:
//		IN	I
//			the cancel stop device IRP
//
//	Return Value:
//		NTSTATUS
//
NTSTATUS testDevice::OnCancelStopDevice(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);

	// TODO: Add driver specific code to process the IRP prior to forwarding
	// to the lower device.  Call PassThrough() to send the IRP to the lower 
	// device.  Optionally, use the commented out code to use a completion 
	// routine to process the IRP after the lower device has completed it:
	//
	// NTSTATUS = PassThrough(I, LinkTo(IrpCompletionRoutine), this);

	// This implementation simply forwards the IRP to the lower device.
	NTSTATUS status = PassThrough(I);

	T.Trace(TraceInfo, __FUNCTION__"--.  IRP %p, STATUS %x\n", I, status);

	return status;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -