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

📄 usbcounter.cpp

📁 WDM设备驱动程序开发(武安河)配套光盘实例源码。
💻 CPP
字号:
// USBCounter.cpp
//
// Generated by DriverWizard version DriverStudio 3.1.0 (Build 1722)
// Requires Compuware's DriverWorks classes
//

#define VDW_MAIN

#include <vdw.h>
#include <kusb.h>
#include "USBCounter.h"
#include "USBCounterDevice.h"

#pragma hdrstop("USBCounter.pch")

// Generated by DriverWizard version DriverStudio 3.1.0 (Build 1722)

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

KTrace t("USBCounter");

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

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

NTSTATUS USBCounter::DriverEntry(PUNICODE_STRING RegistryPath)
{
	t << "In DriverEntry\n";

	m_Unit = 0;
	return STATUS_SUCCESS;
}

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

/////////////////////////////////////////////////////////////////////
//  USBCounter::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 USBCounter::AddDevice(PDEVICE_OBJECT Pdo)
{
	t << "AddDevice called\n";

    // 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.
	USBCounterDevice * pDevice = new (
			NULL,
			FILE_DEVICE_UNKNOWN,
			NULL,
			0,
			DO_EXCLUSIVE | DO_DIRECT_IO // | DO_POWER_PAGABLE
			)
		USBCounterDevice(Pdo, m_Unit);

	if (pDevice == NULL)
	{
		t << "Error creating device USBCounterDevice"
			   << (ULONG) m_Unit << EOL;
	    return STATUS_INSUFFICIENT_RESOURCES;
	}

	NTSTATUS status = pDevice->ConstructorStatus();

	if ( !NT_SUCCESS(status) )
	{
		t << "Error constructing device USBCounterDevice"
		  << (ULONG) m_Unit << " status " << (ULONG) status << EOL;
		delete pDevice;
	}
	else
	{
		m_Unit++;
	}

	return status;
}

// EOF

⌨️ 快捷键说明

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