www.pudn.com > driver.zip > Initiate.c


/****************************************************************************** 
 * * File Name: 
 * *      Initiate.c 
 * * Description: 
 * *      This file initializes the necessary system resources for the Silicon Image 3124A Pci card device. 
 * * Revision History: 
 * *      10-11-07 : Sil3124 1.00 
 ******************************************************************************/ 
 
#include "Sil3124.h" 
UNICODE_STRING ServiceRegistryPath; //save registry information 
 
/****************************************************************************** 
 * 
 * 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("Sil3124 checked");	//DebugPrint init 
    #else 
	DebugPrintInit("Sil3124 free"); 
    #endif 
	DebugPrint("DriverEntry Start.."); 
 
	DebugPrint("RegistryPath is %T",pRegistryPath); 
 
 // Save the name of the service key 
	ServiceRegistryPath.Buffer = (PWSTR) ExAllocatePool(PagedPool, pRegistryPath->Length + sizeof(WCHAR)); 
	if (!ServiceRegistryPath.Buffer) 
	{ 
		DebugPrint("Sil3124 - 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_PNP]            = DispatchPnp;  
	pDriverObject->MajorFunction[IRP_MJ_WRITE]          = DispatchWrite; 
    pDriverObject->MajorFunction[IRP_MJ_POWER]          = DispatchPower; 
	pDriverObject->DriverStartIo						= StartIo; 
    pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DispatchIoControl; 
 
    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();                         //close connection to DebugPrint Driver 
}												// DriverUnload 
#pragma code_seg()	// end PAGE section