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

📄 startiochardevice.cpp

📁 windows 驱动程序开发相关资料与代码 让你深刻知晓windows 开发的魅力所在!
💻 CPP
字号:
// StartIoCharDevice.cpp
// Implementation of StartIoCharDevice device class
//
// Generated by DriverWizard version DriverStudio 2.6.0 (Build 336)
// Requires Compuware's DriverWorks classes
//

#pragma warning(disable:4065) // Allow switch statement with no cases
		  
#include <vdw.h>
#include "..\StartIoCharDeviceinterface.h"

#include "StartIoChar.h"
#include "StartIoCharDevice.h"
#include "..\StartIoCharioctl.h"

#pragma hdrstop("StartIoChar.pch")


GUID StartIoCharDevice_Guid = StartIoCharDevice_CLASS_GUID;

StartIoCharDevice::StartIoCharDevice(PDEVICE_OBJECT Pdo, ULONG Unit) :
	KPnpDevice(Pdo, &StartIoCharDevice_Guid)
{

	// 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);

    // 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.

}

StartIoCharDevice::~StartIoCharDevice()
{
}

NTSTATUS StartIoCharDevice::DefaultPnp(KIrp I) 
{
	I.ForceReuseOfCurrentStackLocationInCalldown();
	return m_Lower.PnpCall(this, I);
}

NTSTATUS StartIoCharDevice::DefaultPower(KIrp I) 
{
	I.IndicatePowerIrpProcessed();
	I.CopyParametersDown();
	return m_Lower.PnpPowerCall(this, I);
}

NTSTATUS StartIoCharDevice::SystemControl(KIrp I) 
{
	I.ForceReuseOfCurrentStackLocationInCalldown();
	return m_Lower.PnpCall(this, I);
}

NTSTATUS StartIoCharDevice::OnStartDevice(KIrp I)
{
	return STATUS_SUCCESS;
}

NTSTATUS StartIoCharDevice::OnStopDevice(KIrp I)
{
	return STATUS_SUCCESS;
}

NTSTATUS StartIoCharDevice::OnRemoveDevice(KIrp I)
{
	return STATUS_SUCCESS;
}

NTSTATUS StartIoCharDevice::Create(KIrp I)
{
	NTSTATUS status;

	status = I.PnpComplete(this, STATUS_SUCCESS, IO_NO_INCREMENT);

	return status;
}

NTSTATUS StartIoCharDevice::Close(KIrp I)
{
	NTSTATUS status;

	status = I.PnpComplete(this, STATUS_SUCCESS, IO_NO_INCREMENT);

    return status;
}

NTSTATUS StartIoCharDevice::CleanUp(KIrp I)
{
// TODO:	Insert your code to respond to the CLEANUP message.
//			This code cleans up the single Wizard created queue.  If you
//			have created additional queues,	or have any outstanding Irps
//			stored in some other fashion in your driver, you should clean
//			these up as well for the file object specified in the cleanup Irp.

	m_DriverManagedQueue.PnpCleanUp(this, I.FileObject());
	return I.PnpComplete(this, STATUS_SUCCESS);
}

NTSTATUS StartIoCharDevice::DeviceControl(KIrp I) 
{
	NTSTATUS status;
	switch (I.IoctlCode())
	{
		case STARTIOCHAR_IOCTL_800:
		{
			char n=*(CHAR *)I.IoctlBuffer();
			if ((n < '0') || (n > '9'))	// If (Request is invalid)
			{
				// Invalid parameter in the Read request
				I.Information() = 0;
				return I.PnpComplete(this, STATUS_INVALID_PARAMETER);
			}

			// Always ok to read 0 elements.
			if (I.IoctlInputBufferSize() == 0)
			{
				I.Information() = 0;
				return I.PnpComplete(this, STATUS_SUCCESS);
			}

			// Queue the IRP for processing in StartIO
			// The read function is performed in SerialRead
			return m_DriverManagedQueue.QueueIrp(I);
		}
		default:
			// Unrecognized IOCTL request
			status = STATUS_INVALID_PARAMETER;
			break;
	}

	return I.PnpComplete(this, status);
}

VOID StartIoCharDevice_DriverManagedQueue::StartIo(KIrp I)
{

	// The KDriverManagedQueueEx class gives us the Irp in a non-cancelable state
	// (cancel routine set to NULL) so we can process it without having to worry
	// about clearing the cancel routine first, as is the case with system queuing,
	// or the legacy class KDriverManagedQueue. You may want to set a different cancel
	// routine here, or at other points during the processing of this Irp.

	// Find the device class so we can call the serialized
	// routines in the device class.  The handlers can be
	// moved to the DriverManagedQueue class if it is more
	// convenient.
	StartIoCharDevice *pDev = (StartIoCharDevice *) KDevicePTR(I.DeviceObject());

	// Start processing request.

	// Switch on the IRP's function:
	switch (I.MajorFunction())
	{
		case IRP_MJ_DEVICE_CONTROL:
			switch (I.IoctlCode())
			{
				case STARTIOCHAR_IOCTL_800:
					pDev->SerialDeviceControl(I);
					break;
				default:
					// We queued a request that shouldn't have been queued
					// (should never get here)
					ASSERT(FALSE);
					I.Status() = STATUS_INVALID_PARAMETER;
					PnpNextIrp(I);
					break;
			}
			break;

		default:
			// Error - unexpected IRP received
			// NextIrp completes this IRP and starts processing
			// for the next IRP in the queue.
			ASSERT(FALSE);
			I.Status() = STATUS_INVALID_PARAMETER;
			PnpNextIrp(I);
			break;
	}
}

void StartIoCharDevice::SerialDeviceControl(KIrp I) 
{
	CHAR n,c[]="零一二三四五六七八九";
	n=*(CHAR *)I.IoctlBuffer();
	n -= '0';
	strncpy((PCHAR)I.IoctlBuffer(),&c[n*2],2);
	I.Information() = 2;
	I.Status() = STATUS_SUCCESS;
	m_DriverManagedQueue.PnpNextIrp(I);
}

⌨️ 快捷键说明

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