在网上找到的方法一般是用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;
}
我现在不知道怎么跟这样的驱动程序通讯啊,大虾们帮帮忙啊。
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;
}
我现在不知道怎么跟这样的驱动程序通讯啊,大虾们帮帮忙啊。
解决方案 »
- vc 6.0 移植2005 出现警告!如何解决?
- MoveWindow问题? 急急!
- VC/MFC SMTP邮件代理-为什么在收件信箱里发件人地址是undisclosed-recipients: ;
- 怎样让Static控件显示多行信息?
- ++++++++200分就是用来接的+++++++++++领工资了,试用期结束了,明年回来签正式合同!幸福一下子,呵呵
- 如果在A.CPP中调用B.CPP中的方法
- 关于CSOCKET的编程问题
- 改版以后,可用分怎么加啊〉〉〉〉〉
- VB转VC的问题
- 请问下:怎样做一个在系统进入桌面之前就启动的登录界面?
- 新手请教,ado数据库连不上
- socket多线程服务器中FD_SET怎么清理?
网上查了一下IoRegisterDeviceInterface这个函数,没有比较完整的实例,特别是没有应用程序中如何和调用了这个函数的驱动程序通讯的内容,请你详细介绍一下相关内容吧,拜托了。