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

📄 xunicdevice.cpp

📁 WDM驱动程序实例,用DriverStudio加vc
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// XunicDevice.cpp
//
// Generated by DriverWizard 3.2.0 (Build 2485)
// Requires DDK and DriverWorks
// File created on 2/8/2006
//
// This source file contains the implementation of a subclass of KDevice.
// WDM drivers implement a subclass of KPnpDevice and override member
// functions to handle requests (IRPs) from the system.
//

#include <vdw.h>
#include "XunicDriver.h"
#include "XunicDevice.h"
#include "..\\intrface.h"

#pragma hdrstop("Xunic.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.
extern KDebugOnlyTrace T;

///////////////////////////////////////////////////////////////////////////////////////////////////
//  XunicDevice::XunicDevice
//		This is the constructor for the class representing the Functional
//		Device Object, or FDO.  It is derived from KPnpDevice, which builds
//		in automatic dispatching of subfunctions of IRP_MJ_POWER and IRP_MJ_PNP
//		to virtual member functions.
//		The object being constructed contains a data member (m_Lower) of type
//		KPnpLowerDevice. By initializing it, the driver binds the FDO to the
//		PDO and creates an interface to the upper edge of the system class driver.
//
//	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
//
XunicDevice::XunicDevice(PDEVICE_OBJECT Pdo, ULONG Unit) :
	KPnpDevice(Pdo, &GUID_DEVINTERFACE_XUNIC)
{
	if (!NT_SUCCESS(m_ConstructorStatus))
	{
		T.Trace(TraceError, __FUNCTION__": Failed to create device XunicDevice"
			" unit number %d status %x\n", Unit, m_ConstructorStatus);
		ASSERT(FALSE);
		return;
	}

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

	// Inform the base class of the lower edge device object
	SetLowerDevice(&m_Lower);

	// Initialize the PnP Policy settings to the "standard" policy
	SetPnpPolicy();

	// TODO: Customize the PnP Policy for this device by setting
	//		 flags in m_Policies.

	// Initialize the Power Policy settings to the "standard" policy
	SetPowerPolicy();

	// TODO: Customize the Power Policy for this device by setting
	//		 flags in m_PowerPolicies.

}

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

///////////////////////////////////////////////////////////////////////////////////////////////////
//  XunicDevice::DefaultPnp
//		Default handler for IRP_MJ_PNP. 
//		This routine just passes the IRP through to the lower device. IRPs 
//		that correspond to any virtual members of KpnpDevice that handle 
//		minor functions of IRP_MJ_PNP and that are not overridden get 
//		passed to this routine.
//
//	Arguments:
//		IN	I
//			the plug and play IRP
//
//	Return Value:
//		NTSTATUS
//			Result returned from lower device
//
NTSTATUS XunicDevice::DefaultPnp(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);
	T << I; 

	I.ForceReuseOfCurrentStackLocationInCalldown();
	NTSTATUS status = m_Lower.PnpCall(this, I);

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

	return status;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  XunicDevice::DefaultPower
//		Default handler for IRP_MJ_POWER. 
//		This routine just passes the IRP through to the lower device. IRPs 
//		that correspond to any virtual members of KpnpDevice that handle 
//		minor functions of IRP_MJ_POWER and that are not overridden get 
//		passed to this routine.
//
//	Arguments:
//		IN	I
//			the power IRP
//
//	Return Value:
//		NTSTATUS
//			Result returned from lower device
//
NTSTATUS XunicDevice::DefaultPower(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);
	T << I; 

	I.IndicatePowerIrpProcessed();
	I.CopyParametersDown();
	NTSTATUS status = m_Lower.PnpPowerCall(this, I);

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

	return status;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  XunicDevice::SystemControl
//		Default handler for IRP_MJ_SYSTEM_CONTROL. 
//		This routine just passes the IRP through to the next device since 
//		this driver is not a WMI provider.
//
//	Arguments:
//		IN	I
//			the system control (WMI) IRP
//
//	Return Value:
//		NTSTATUS
//			Result returned from lower device
//
NTSTATUS XunicDevice::SystemControl(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);
	T << I; 

	NTSTATUS status = STATUS_SUCCESS;

	I.ForceReuseOfCurrentStackLocationInCalldown();
	status = m_Lower.PnpCall(this, I);

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

	return status;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  XunicDevice::OnStartDevice
//		Handler for IRP_MJ_PNP subfcn IRP_MN_START_DEVICE. 
//		Initialize the hardware device. Typically, the driver initializes
//		physical resources here.  Call I.AllocatedResources() for a list
//		of the raw resources that the system has assigned to the device,
//		or I.TranslatedResources() for the translated resource list.
//
//	Arguments:
//		IN	I
//			the start device IRP
//
//	Return Value:
//		NTSTATUS
//
NTSTATUS XunicDevice::OnStartDevice(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);

	NTSTATUS status = STATUS_SUCCESS;

	I.Information() = 0;

	// Get the list of raw resources from the IRP
	PCM_RESOURCE_LIST pResListRaw = I.AllocatedResources();
	// Get the list of translated resources from the IRP
	PCM_RESOURCE_LIST pResListTranslated = I.TranslatedResources();

	// TODO: Add device-specific code to initialize/start your hardware device.
    // The base class will handle completion of the IRP

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

	return status;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  XunicDevice::OnStopDevice
//		Handler for IRP_MJ_PNP subfcn IRP_MN_STOP_DEVICE. 
//		The system calls this when the device is stopped.  Release any 
//		hardware resources in this routine.
//
//	Arguments:
//		IN	I
//			the stop device IRP
//
//	Return Value:
//		NTSTATUS
//
NTSTATUS XunicDevice::OnStopDevice(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);

	NTSTATUS status = STATUS_SUCCESS;

	// TODO: Add device-specific code to stop your hardware device.
    // The base class will handle completion of the IRP

	// Release the system resources
	Invalidate();

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

	// Can't fail this IRP
	return STATUS_SUCCESS;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  XunicDevice::OnRemoveDevice
//		Handler for IRP_MJ_PNP subfcn IRP_MN_REMOVE_DEVICE. 
//		The system calls this when the device is removed.
//		Our PnP policy will take care of 
//			(1) giving the IRP to the lower device
//			(2) detaching the PDO
//			(3) deleting the device object
//
//	Arguments:
//		IN	I
//			the remove device IRP
//
//	Return Value:
//		NTSTATUS
//
NTSTATUS XunicDevice::OnRemoveDevice(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);

	NTSTATUS status = STATUS_SUCCESS;

	// TODO: Add device-specific code to remove your hardware device.
    // The base class will handle completion of the IRP

	// Release the system resources
	Invalidate();

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

	// Can't fail this IRP
	return STATUS_SUCCESS;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  XunicDevice::OnDevicePowerUp
//		Handler for IRP_MJ_POWER subfcn IRP_MN_SET_POWER 
//		for a request to go to power on state from low power state
//		This function was called by the framework from the completion
//		routine of the IRP_MJ_POWER dispatch handler in KPnpDevice.
//		The bus driver has completed the IRP and this driver can now
//		access the hardware device.  
//		This routine runs at DISPATCH_LEVEL.
//
//	Arguments:
//		IN	I
//			the power IRP
//
//	Return Value:
//		NTSTATUS
//
NTSTATUS XunicDevice::OnDevicePowerUp(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);

	NTSTATUS status = STATUS_SUCCESS;

	// TODO: Add device-specific code to:
	//		 Restore any context to the hardware device that
	//		 was saved during the handling of a power down request.
	//		 See the OnDeviceSleep function.
	//		 Do NOT complete this IRP.
    //		 The base class will handle completion of the IRP

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

	return status;

⌨️ 快捷键说明

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