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

📄 vwrite.cpp

📁 WDM的驱动程序实例,可供自学开发WDM者参考,其是在VC和COMPUWARE下的.
💻 CPP
字号:
// Vwrite.cpp
//
// Generated by DriverWizard version DriverStudio 2.7.0 (Build 554)
// Requires Compuware's DriverWorks classes
//

#define VDW_MAIN
#include <vdw.h>
#include "..\vinterface.h"
#include "vwrite.h"
#include "vwritdev.h"

#pragma hdrstop("vwrite.pch")

// Generated by DriverWizard version DriverStudio 2.7.0 (Build 554)

// Set a default 32-bit tag value to be stored with each heap block
// allocated by operator new. Use BoundsChecker to view the memory pool.
// This value can be overridden using the global function SetPoolTag().
POOLTAG DefaultPoolTag('irwV');

// Create the global driver trace object
// TODO:	Use KDebugOnlyTrace if you want trace messages
//			to appear only in debug builds.  Use KTrace if
//			you want trace messages to always appear.	
KDebugOnlyTrace t("Vwrite");

/////////////////////////////////////////////////////////////////////
// Begin INIT section
#pragma code_seg("INIT")

DECLARE_DRIVER_CLASS(Vwrite, NULL)

/////////////////////////////////////////////////////////////////////
//  Vwrite::DriverEntry
//
//	Routine Description:
//		This is the first entry point called by the system when the
//		driver is loaded.
// 
//	Parameters:
//		RegistryPath - String used to find driver parameters in the
//			registry.  To locate Vwrite look for:
//			HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Vwrite
//
//	Return Value:
//		NTSTATUS - Return STATUS_SUCCESS if no errors are encountered.
//			Any other indicates to the system that an error has occured.
//
//	Comments:
//

NTSTATUS Vwrite::DriverEntry(PUNICODE_STRING RegistryPath)
{
	t << "In DriverEntry Compiled at " __TIME__ " on " __DATE__ "\n";

	m_Unit = 0;

	return STATUS_SUCCESS;
	UNREFERENCED_PARAMETER(RegistryPath);
}

// End INIT section
/////////////////////////////////////////////////////////////////////
#pragma code_seg()

/////////////////////////////////////////////////////////////////////
//  Vwrite::AddDevice
//
//	Routine Description:
//		Called when the system detects a device for which this
//		driver is responsible.
//
//	Parameters:
//		Pdo - Physical Device Object. This is a pointer to a system device
//			object that represents the physical device.
//
//	Return Value:
//		NTSTATUS - Success or failure code.
//
//	Comments:
//		This function creates the Functional Device Object, or FDO. The FDO
//		enables this driver to handle requests for the physical device. 
//

NTSTATUS Vwrite::AddDevice(PDEVICE_OBJECT Pdo)
{
	t << "AddDevice called\n";

	VWriteDevice* pDevice = new (
			static_cast<PCWSTR>(KUnitizedName(L"VwriteDevice", m_Unit)),
			FILE_DEVICE_UNKNOWN,
			NULL,
			0,
			DO_BUFFERED_IO | DO_POWER_PAGABLE
			)
		VWriteDevice(Pdo, m_Unit);

	NTSTATUS status;

	if ( pDevice  )
	{
		status = pDevice->ConstructorStatus();

		if ( NT_SUCCESS(status) )
		{
			m_Unit++;

			pDevice->ReportNewDevicePowerState(PowerDeviceD0);
		}
		else
		{
			t << "Error constructing device VWriteDevice " << m_Unit << " status " << (ULONG)status << EOL;
			delete pDevice;
		}
	}
	else
	{
		t << "Error creating device VWriteDevice " << m_Unit << EOL;
	    status = STATUS_INSUFFICIENT_RESOURCES;
	}

	return status;
}

⌨️ 快捷键说明

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