阅读:1472回复:2
【求助】关于驱动程序和应用程序通讯。。。
在网上找到的方法一般是用DeviceIoControl、ReadFile、WriteFile等,但是用这些方法的前提是先调用CreateFile,这个函数的第一个参数是一个SymbolicLink(例如:"\\\\.\\TestSample"),这个SymbolicLink一般是在驱动程序中调用IoCreateSymbolicLink创建的,这样的驱动程序一般有类似如下入口例程:
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath) { PFILE_OBJECT pLowerFileObject=NULL; UNICODE_STRING DeviceName; UNICODE_STRING DosDeviceName; UNICODE_STRING Name; PDEVICE_OBJECT pLowerDeviceObject=NULL; PDEVICE_OBJECT pDeviceObject=NULL; NTSTATUS Status; DriverObject->DriverUnload=DriverUnload; DriverObject->MajorFunction[IRP_MJ_READ] = TestSampleRead; DriverObject->MajorFunction[IRP_MJ_WRITE] = TestSampleWrite; DriverObject->MajorFunction[IRP_MJ_CREATE] = TestSampleCreate; DriverObject->MajorFunction[IRP_MJ_CLOSE] = TestSampleClose; DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = TestSampleDeviceControl; RtlInitUnicodeString(&DeviceName,gDeviceName); RtlInitUnicodeString(&DosDeviceName,gDosDeviceName); IoCreateDevice(DriverObject,0,&DeviceName,FILE_DEVICE_UNKNOWN,0,FALSE,&pDeviceObject); pDeviceObject->Flags|=DO_BUFFERED_IO; Status = IoCreateSymbolicLink(&DosDeviceName,&DeviceName); if(Status) DbgPrint("IoCreateSymbolicLink Return %0x\n",Status); KeInitializeSpinLock(&gSpinLock); RtlInitUnicodeString(&Name,gKeventName); pMsgKEvent = IoCreateSynchronizationEvent(&Name,&hMsgEvent); Status = ObReferenceObjectByHandle(hMsgEvent,EVENT_ALL_ACCESS,*ExEventObjectType,KernelMode,(PVOID*)&gKeventObject,NULL); if(!NT_SUCCESS(Status)) { DbgPrint("SDbgMsg : ObReferenceObjectByHandle\n"); } else { DbgPrint("gKeventObject = %x pMsgKEvent=%x\n",gKeventObject,pMsgKEvent); } if(gKeventObject) KeClearEvent(gKeventObject); if(pMsgKEvent) KeResetEvent(pMsgKEvent); return 0; } 我现在碰到一个这样的驱动程序,它的入口例程如下: ULONG DriverEntry ( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath ) { HW_INITIALIZATION_DATA HwInitData; ULONG ReturnValue; RtlZeroMemory(&HwInitData, sizeof(HwInitData)); HwInitData.HwInitializationDataSize = sizeof(HwInitData); // // Set the Adapter entry points for the driver // HwInitData.HwInterrupt = NULL; // HwInterrupt; HwInitData.HwReceivePacket = AdapterReceivePacket; HwInitData.HwCancelPacket = AdapterCancelPacket; HwInitData.HwRequestTimeoutHandler = AdapterTimeoutPacket; HwInitData.DeviceExtensionSize = sizeof(HW_DEVICE_EXTENSION); HwInitData.PerRequestExtensionSize = sizeof(SRB_EXTENSION); HwInitData.FilterInstanceExtensionSize = 0; HwInitData.PerStreamExtensionSize = sizeof(STREAMEX); HwInitData.BusMasterDMA = FALSE; HwInitData.Dma24BitAddresses = FALSE; HwInitData.BufferAlignment = 3; HwInitData.DmaBufferSize = 0; // Don't rely on the stream class using raised IRQL to synchronize // execution. This single paramter most affects the overall structure // of the driver. HwInitData.TurnOffSynchronization = TRUE; ReturnValue = StreamClassRegisterAdapter(DriverObject, RegistryPath, &HwInitData); return ReturnValue; } 我现在不知道怎么跟这样的驱动程序通讯啊,大虾们帮帮忙啊。 |
|
沙发#
发布于:2007-08-03 09:50
关注
|
|
板凳#
发布于:2007-08-04 14:55
我顶
|
|