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

📄 init.cpp

📁 这是一个用PLX9052PCI控制芯片桥接PCI的示范程序.
💻 CPP
字号:
/******************************************************************************
 * * File Name:
 * *      Init.cpp
 * * Description:
 * *      This file initializes the necessary system resources for the Can Pci card device.
 * * Revision History:
 * *      02-28-02 : PCI9052Demo 1.00
 ******************************************************************************/

#include "PCI9052Demo.h"

UNICODE_STRING ServiceRegistryPath;		//The 


/******************************************************************************
 *
 * Function   :  DriverEntry
 *
 * Description:  Entry point for the driver.
 *
 ******************************************************************************/
#pragma code_seg("INIT") // start INIT section
extern "C"				
NTSTATUS DriverEntry( IN PDRIVER_OBJECT pDriverObject,
					  IN PUNICODE_STRING pRegistryPath)
{												//DriverEntry
    NTSTATUS status = STATUS_SUCCESS;
#if DBG
	DebugPrintInit("PCI9052Demo checked");	//DebugPrint初始化
#else
	DebugPrintInit("PCI9052Demo free");
#endif
	DebugPrint("DriverEntry Start.");

	DebugPrint("RegistryPath is %T",pRegistryPath);

    // Determine OS version through WDM version information
    if (IoIsWdmVersionAvailable(0x01, 0x10) == FALSE)
    {				//Determine OS version
        if (IoIsWdmVersionAvailable(0x01, 0x00) == TRUE)
        {			//
            DebugPrint("PCI9052Demo: OS supports WDM 1.0 (Windows 98)");
        }
        else
		{
            DebugPrint("PCI9052Demo: WARNING - OS does not support WDM 1.0");
		}
	}
    else
	{
        DebugPrint("PCI9052Demo: OS supports WDM 1.10 (Windows 2000 or above)");
	}				//Determine OS version

    // Save the name of the service key
	ServiceRegistryPath.Buffer = (PWSTR) ExAllocatePool(PagedPool, pRegistryPath->Length + sizeof(WCHAR));
	if (!ServiceRegistryPath.Buffer)
	{
		DebugPrint("PCI9052Demo - Unable to allocate %d bytes for copy of service key name.", pRegistryPath->Length + sizeof(WCHAR));
		return STATUS_INSUFFICIENT_RESOURCES;
	}

	ServiceRegistryPath.MaximumLength = pRegistryPath->Length + sizeof(WCHAR);
	RtlCopyUnicodeString(&ServiceRegistryPath, pRegistryPath);

    // Fill in the appropriate dispatch handlers
	pDriverObject->DriverExtension->AddDevice           = AddDevice;
    pDriverObject->DriverUnload                         = DriverUnload;

    pDriverObject->MajorFunction[IRP_MJ_CREATE]         = DispatchCreate;
    pDriverObject->MajorFunction[IRP_MJ_CLOSE]          = DispatchClose;

    pDriverObject->MajorFunction[IRP_MJ_READ]           = DispatchRead;
    pDriverObject->MajorFunction[IRP_MJ_WRITE]          = DispatchWrite;
	pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DispatchIoControl;

	pDriverObject->DriverStartIo						= StartIo;
	pDriverObject->MajorFunction[IRP_MJ_CLEANUP]        = DispatchCleanup;
    
    pDriverObject->MajorFunction[IRP_MJ_PNP]            = DispatchPnp;
    pDriverObject->MajorFunction[IRP_MJ_POWER]          = DispatchPower;

    pDriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = DispatchSystemControl;
    

	DebugPrint("DriverEntry End.");

    return status;
}												//DriverEntry
#pragma code_seg()	// end INIT section

/******************************************************************************
 *
 * Function   :  DriverUnload
 *
 * Description:  Unload the driver.
 *
 ******************************************************************************/
#pragma code_seg("PAGE") // start PAGE section
VOID DriverUnload( IN PDRIVER_OBJECT pDriverObject)
{												// DriverUnload
	PAGED_CODE();
	DebugPrint("DriverUnload Start.");
	RtlFreeUnicodeString(&ServiceRegistryPath);
	DebugPrint("DriverUnload End.");

	//Close DebugPrint.
	DebugPrintClose();	//注意一定要有
}												// DriverUnload
#pragma code_seg()	// end PAGE section

⌨️ 快捷键说明

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