阅读:1599回复:6
怎样在自己的驱动中调用其它的驱动
我现在作一个的2000的并口的驱动,现在只能在系统的提供的驱动上开发,我要闻的问题就是怎样向系统的驱动的设备发送
IRP_MJ_INTERNAL_DEVICE_CONTROL的IO请求.是不是要将自己的驱动设备挂载底层系统驱动设备栈的上面,然后向底层驱动设备传送IRP, 能不能不需要挂在系统驱动的上面,直接系统驱动设备发送内部控制的IRP? 谢了先.^_^ dazzy在吗? |
|
最新喜欢:stoney... |
沙发#
发布于:2002-02-06 20:07
可以,但是你要知道这个驱动程序提供的设备对象名称,然后取得这个设备对象,还有就是要知道这些控制代码的意义和作用
|
|
板凳#
发布于:2002-02-07 14:57
在驱动程序栈的中间层做文章,是可以的
|
|
地板#
发布于:2002-02-07 15:01
我不很详细的知道你对并口进行的哪一种操作:简单的端口读写还是其他的,我认为借助于windows的并口驱动你可以很好的完成你的任务。前面我已经说得比较明白了。在此,我贴上一段代码,对你可能会有帮助的。
//isr service BOOLEAN ParPort_IsrRoutine(IN struct _KINTERRUPT *Interrupt, IN PVOID ServiceContext) { DbgPrint(\"In Isr!\\n\"); return TRUE; } //call lower driver NTSTATUS ParPort_CallLowerDriver( IN ULONG IoControlcode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, OUT PVOID OutputBuffer, IN ULONG OutputBufferLength ) { NTSTATUS status = STATUS_SUCCESS; IO_STATUS_BLOCK IoStatusBlock; KEVENT Event; PIRP Irp = NULL; KIRQL oldIrql; KeInitializeEvent(&Event, NotificationEvent, FALSE); Irp = IoBuildDeviceIoControlRequest( IoControlcode, DeviceObject, InputBuffer, InputBufferLength, OutputBuffer, OutputBufferLength, TRUE, &Event, &IoStatusBlock ); if(Irp == NULL) { status = STATUS_INSUFFICIENT_RESOURCES; }else { status = IoCallDriver(DeviceObject, Irp); if(NT_SUCCESS(status)) { LARGE_INTEGER TimeOut; TimeOut.QuadPart = -5,000,000; status = KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, &TimeOut); if(status == STATUS_TIMEOUT) { KeRaiseIrql(APC_LEVEL, &oldIrql); if(!KeReadStateEvent(&Event)) { IoCancelIrp(Irp); } KeLowerIrql(oldIrql); KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL); } } } return status; } //并口初始化代码 ParPort_Initialize( PPAR_PORT_DEVICE_EXTENSION DevEx ) { UNICODE_STRING uniParallelPortName; NTSTATUS status = STATUS_SUCCESS; PUCHAR EPPPort; PARALLEL_INTERRUPT_SERVICE_ROUTINE ServiceRoutine, OutputServiceRoutine; RtlInitUnicodeString(&uniParallelPortName, ParallelPortName); if(DevExt->DeviceInitialized) { status = STATUS_UNSUCCESSFUL; } else { status = IoGetDeviceObjectPointer(&uniParallelPortName, FILE_ALL_ACCESS, &DevExt->FielObject, &DevExt->DeviceObject); if(NT_SUCCESS(status)) { status = ParPort_CallLowerDriver( IOCTL_INTERNAL_GET_PARALLEL_PORT_INFO, DevExt->DeviceObject, NULL, 0, &DevExt->ParallelPortInfo, sizeof(PARALLEL_PORT_INFORMATION) ); if(status == STATUS_SUCCESS) { status = ParPort_CallLowerDriver( IOCTL_INTERNAL_GET_PARALLEL_PNP_INFO, DevExt->DeviceObject, NULL, 0, &DevExt->ParallelPnpInfo, sizeof(PARALLEL_PNP_INFORMATION) ); if(status != STATUS_SUCCESS) { EPPPort = DevExt->ParallelPortInfo.Controller + 0x400; DevExt->PNPConfiged = FALSE; DevExt->EPPModePort = EPPPort; } else { DevExt->PNPConfiged = TRUE; EPPPort = DevExt->ParallelPnpInfo.EcpController; if(EPPPort == NULL || DevExt->ParallelPnpInfo.SpanOfEcpController < 3) { EPPPort = NULL; } } DevExt->EPPModePort = EPPPort; status = ParPort_CallLowerDriver( IOCTL_INTERNAL_PARALLEL_PORT_ALLOCATE, DevExt->DeviceObject, NULL, 0, NULL, 0 ); if(status == STATUS_TIMEOUT) { status = STATUS_UNSUCCESSFUL; } else if(status == STATUS_SUCCESS) { DevExt->ControllerPort = DevExt->ParallelPortInfo.Controller; DevExt->SpanOfController = DevExt->ParallelPortInfo.SpanOfController; if(DevExt->ParallelPortInfo.SpanOfController < 8) { DevExt->SpanOfController = 8; } RtlZeroMemory(&ServiceRoutine, sizeof(PARALLEL_INTERRUPT_SERVICE_ROUTINE)); ServiceRoutine.InterruptServiceRoutine = (PKSERVICE_ROUTINE)ParPort_IsrRoutine; ServiceRoutine.InterruptServiceContext = (PVOID)DevExt; status = ParPort_CallLowerDriver( IOCTL_INTERNAL_PARALLEL_CONNECT_INTERRUPT, DevExt->DeviceObject, &ServiceRoutine, sizeof(PARALLEL_INTERRUPT_SERVICE_ROUTINE), &OutputServiceRoutine, sizeof(PARALLEL_INTERRUPT_SERVICE_ROUTINE) ); if(status == STATUS_SUCCESS) { DevExt->InterruptConnected = TRUE; } DevExt->DeviceInitialized = TRUE; } else { DevExt->ParallelPortInfo.FreePort = NULL; status = STATUS_SUCCESS; } } } } return status; 在初始化时,取得了端口地址,你可以调用WRITE_PORT_UCHAR和READ_PORT_UCHAR对此端口进行读写,在中断例程例假如你的处理代码。更详细的信息请参考ddk. 要利用windows并口驱动,你最好看一看ddk中关于并口的源码。 |
|
地下室#
发布于:2002-02-25 18:20
哪里有详细的并口操作ddk源代码?
想做一个虚拟驱动,简单向并口读写数据,不知道该怎么做? 有没有打下帮忙? |
|
|
5楼#
发布于:2002-03-17 18:25
我也按上面的做了,是在Create里调用上面的代码,结果是win32函数CreateFile就通不过,不知道为什么,进入那句语句后就再没出来。这是什么原因?
|
|
6楼#
发布于:2002-03-18 20:49
我再把它放在StartDevice之中,结果是windows不能启动该驱动程序。真的是没有办法了。谁帮帮我吧
|
|