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

📄 comfilnt.cpp

📁 一个2000系统上的虚拟串口驱动程序
💻 CPP
字号:
// Comfilnt.cpp
//
// Generated by DriverWizard version DriverStudio 2.5.0 (Build 240)
// Requires Compuware's DriverWorks classes
//

#define VDW_MAIN
#include <vdw.h>
#include "function.h"
#include "Comfilnt.h"
#include "ComfilntDevice.h"

#pragma hdrstop("Comfilnt.pch")

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

// 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("Comfilnt");

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

DECLARE_DRIVER_CLASS(Comfilnt, NULL)

/////////////////////////////////////////////////////////////////////
//  Comfilnt::DriverEntry
// 
//	Routine Description:
//		This routine is called when the driver is loaded.
//
//	Parameters:
//		RegistryPath - String used to find driver parameters in the
//			registry.  To locate Comfilnt look for:
//			HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Comfilnt
//
//	Return Value:
//		NTSTATUS - Return STATUS_SUCCESS if no errors are encountered.
//			Any other indicates to the system that an error has occured.
//
//	Comments:
//		Usually, this is where any devices associated with
//		the driver are created.
//
//		The driver often reads the registry at DriverEntry in
//		order to setup various configurable parameters.
//		
//		DriverWorks makes it easy to use the registry to also
//		control what devices are present and should be created.
//

NTSTATUS Comfilnt::DriverEntry(PUNICODE_STRING RegistryPath)
{
	NTSTATUS status;			// Status of device creation

	t << "In DriverEntry Compiled at " __TIME__ " on " __DATE__ "\n";

	// Open the "Parameters" key under the driver
	KRegistryKey Params(RegistryPath, L"Parameters");
	if ( NT_SUCCESS(Params.LastError()) )
	{
#if DBG
		ULONG bBreakOnEntry = FALSE;
			// Read "BreakOnEntry" value from registry
		Params.QueryValue(L"BreakOnEntry", &bBreakOnEntry);
			// If requested, break into debugger
		if (bBreakOnEntry) DbgBreakPoint();

#endif
		// Load driver data members from the registry
		LoadRegistryParameters(Params);
	}

	int Unit;
	int i,n;

// TODO:	If you want multiple instances of this device,
//			edit the following code to create (using 'new') additional
//			instances of the class "ComfilntDevice".
//			For example, a serial driver with 6 ports would create 6
//			6 instances of the class, one for each port.
//
//			You can create a fixed number of devices by looping here,
//			or create an instance of KConfigurationQuery to scan the
//			registry to determine how many device to create.   
	Unit = 0;

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

	ComfilntDevice* pComfilntDevice[MAX_COM];
	for(i=0;i<MAX_COM/2;i++){
		m_RW[i].PipeA.Initialize(0x100,NonPagedPool);
		m_RW[i].PipeB.Initialize(0x100,NonPagedPool);
		m_RW[i].MaskA=(ULONG)0;
		m_RW[i].MaskB=(ULONG)0;
		m_RW[i].WriteCountA=(ULONG)0;
		m_RW[i].WriteCountB=(ULONG)0;
	}
	for( i=0;i<MAX_COM;i++){
		Unit=i+10;
		n=i/2;
	pComfilntDevice[i] = new (
			static_cast<PCWSTR>(KUnitizedName(L"ComfilntDevice", Unit)),
			FILE_DEVICE_UNKNOWN,
			static_cast<PCWSTR>(KUnitizedName(L"Com", Unit)), 
			0,
			DO_DIRECT_IO
			)
		ComfilntDevice(Unit,&m_RW[n]);

	t << "Unit= " << (ULONG) Unit <<EOL;
	t << "n=" << (ULONG)n << EOL;
	if (pComfilntDevice[i] == NULL)
	{
		t << "***Error constructing device " <<  (ULONG) Unit << EOL;
		return STATUS_INSUFFICIENT_RESOURCES;
	}
	status = pComfilntDevice[i]->ConstructorStatus();
	if (!NT_SUCCESS(status))
	{
		// Error returned from a constructor
		t << "Error creating device ComfilntDevice, status " << (ULONG) status << EOL;
		delete pComfilntDevice[i];
		return status;
	}
	}
	// If no errors returned during device construction, return success code.
	return STATUS_SUCCESS;
}

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

void Comfilnt::LoadRegistryParameters(KRegistryKey &Params)
{
	m_bBreakOnEntry = FALSE;	Params.QueryValue(L"BreakOnEntry", &m_bBreakOnEntry);	t << "m_bBreakOnEntry loaded from registry, resulting value: [" << m_bBreakOnEntry << "]\n";	m_comnum = 0x000a;	Params.QueryValue(L"comnum", &m_comnum);	t << "m_comnum loaded from registry, resulting value: [" << m_comnum << "]\n";
}



#pragma code_seg()

/////////////////////////////////////////////////////////////////////
//  Comfilnt::Unload
// 
//	Routine Description:
//		This routine is called when the driver is unloaded.
//
//	Parameters:
//		None
//
//	Return Value:
//		None
//
//	Comments:
//		Unload is responsible for releasing any system objects that
//		the driver has allocated. 
//
//		In general, this function must comprehensively ensure that
//		the driver is not unloaded while holding system objects,
//		including memory, or while there are pending events that
//		would cause the system to call the driver. This is best done
//		by deconstructing top level objects, which in turn release
//		objects for which they are responsible.
//
//		This function is called at PASSIVE_LEVEL.
//

VOID Comfilnt::Unload(VOID)
{
	t << "Unload called\n";
   // If you don't need to perform any functions
   // except to call the base class KDriver::Unload(),
   // then this entire routine may be safely deleted.

    // Call base class to delete all devices.
	KDriver::Unload();
}

⌨️ 快捷键说明

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