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

📄 regsample.cpp

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

#define VDW_MAIN
#include <vdw.h>
#include "RegSample.h"
#include "RegSampleDevice.h"

#pragma hdrstop("RegSample.pch")

// Generated by DriverWizard version DriverStudio 2.6.0 (Build 336)

// 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('SgeR');

// 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.	
KTrace t("RegSample");

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

DECLARE_DRIVER_CLASS(RegSample, NULL)

/////////////////////////////////////////////////////////////////////
//  RegSample::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 RegSample look for:
//			HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\RegSample
//
//	Return Value:
//		NTSTATUS - Return STATUS_SUCCESS if no errors are encountered.
//			Any other indicates to the system that an error has occured.
//
//	Comments:
//

NTSTATUS RegSample::DriverEntry(PUNICODE_STRING RegistryPath)
{
	KRegistryKey Params(RegistryPath, L"Parameters");
	t << "RegistryPath:" << RegistryPath << "\n";
	if ( NT_SUCCESS(Params.LastError()) )
	{
		// Load driver data members from the registry
		LoadRegistryParameters(Params);
	}
	m_Unit = 0;

	return STATUS_SUCCESS;
}


/////////////////////////////////////////////////////////////////////
//  RegSample::LoadRegistryParameters
//
//	Routine Description:
//		Load driver data members from the registry.
// 
//	Parameters:
//		Params - Open registry key pointing to "Parameters"
//
//	Return Value:
//		None
//			
//	Comments:
//		Member variables are updated with values read from registry.
//
//		The parameters are found as values under the "Parameters" key,	
//		HKLM\SYSTEM\CurrentControlSet\Services\RegSample\Parameters\...
//

void RegSample::LoadRegistryParameters(KRegistryKey &Params)
{
	ULONG	RegLength;

	m_RegDword = 0x123456;
	Params.QueryValue(L"RegDword", &m_RegDword);
	t << "RegDword:" << m_RegDword << "\n";

	m_RegString = L"WDM";
	RegLength = 0;
	Params.QueryValue(L"RegString", m_RegString, RegLength, NonPagedPool);
	t << "RegString:" << m_RegString << "\n";
	// Setting RegLength to 0 indicates a new block should be allocated.	// TODO: If RegLength is returned > 0, a new block was allocated	// and should be deleted when no longer needed.	if (RegLength != 0)
		delete m_RegString;

	m_RegBoolean = TRUE;
	Params.QueryValue(L"RegBoolean", &m_RegBoolean);
	t << "RegBoolean:" << m_RegBoolean << "\n";

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

/////////////////////////////////////////////////////////////////////
//  RegSample::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 RegSample::AddDevice(PDEVICE_OBJECT Pdo)
{

    // Create the device object. Note that we used a form of "placement" new,
	// that is a member operator of KDevice.  This form will use storage
	// allocated by the system in the device object's device to store our
	// class instance.
	RegSampleDevice * pDevice = new (
			static_cast<PCWSTR>(KUnitizedName(L"RegSampleDevice", m_Unit)),
			FILE_DEVICE_UNKNOWN,
			NULL,
			0,
			DO_DIRECT_IO
			)
		RegSampleDevice(Pdo, m_Unit);

	if (pDevice == NULL)
	{
	    return STATUS_INSUFFICIENT_RESOURCES;
	}

	NTSTATUS status = pDevice->ConstructorStatus();

	if ( !NT_SUCCESS(status) )
	{
		delete pDevice;
	}
	else
	{
		m_Unit++;
	}

	return status;
}

⌨️ 快捷键说明

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