下面是驱动程序中的.几个函数:是关于串口(运用驱动监听串口数据)的
即不占用串口资源。
MHANDLE CSERMONDevice::TryConnectToSerialDevice(LPCTSTR Name)
{
CUString str((PWCHAR) Name);
PDEVICE_OBJECT pdo;
NTSTATUS RC=Attach(&str.m_String,FILE_ALL_ACCESS,&pdo);
if (RC==STATUS_SUCCESS)
return (MHANDLE) pdo->DeviceExtension;
else
return NULL;
}
NTSTATUS CSERMONDevice::IoControl(PIRP Irp)
{
PIO_STACK_LOCATION curIRPStack;
curIRPStack = IoGetCurrentIrpStackLocation(Irp);
switch (curIRPStack->Parameters.DeviceIoControl.IoControlCode)
{
case IOCTL_SERMON_STARTMONITOR:
{
MHANDLE mh=TryConnectToSerialDevice(
(LPCTSTR) Irp->AssociatedIrp.SystemBuffer);
if (mh)
{
*((MHANDLE *) Irp->AssociatedIrp.SystemBuffer)=mh;
Irp->IoStatus.Information = sizeof(MHANDLE);
Irp->IoStatus.Status = STATUS_SUCCESS;
} else
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
break;
}
case IOCTL_SERMON_STOPMONITOR:
{
if (curIRPStack->Parameters.DeviceIoControl.InputBufferLength
==sizeof(MHANDLE))
{
MHANDLE mh=*((MHANDLE *) Irp->AssociatedIrp.SystemBuffer);
CAttachedDevice *ptr=(CAttachedDevice *) mh;
if (ptr && ptr->CheckValid())
{
Irp->IoStatus.Status = STATUS_SUCCESS;
delete ptr;
} else
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
} else
Irp->IoStatus.Status = STATUS_INVALID_HANDLE;
Irp->IoStatus.Information = 0;
break;
}
case IOCTL_SERMON_GETINFOSIZE:
{
if (curIRPStack->Parameters.DeviceIoControl.
InputBufferLength==sizeof(MHANDLE))
{
MHANDLE mh=*((MHANDLE *)
Irp->AssociatedIrp.SystemBuffer);
CAttachedDevice *ptr=(CAttachedDevice *) mh;
if (ptr && ptr->CheckValid() &&
curIRPStack->Parameters.DeviceIoControl.
OutputBufferLength==sizeof(ULONG))
{
return ptr->GetNextSize(Irp);
} else
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
} else
Irp->IoStatus.Status = STATUS_INVALID_HANDLE;
Irp->IoStatus.Information = 0;
break;
}
case IOCTL_SERMON_GETINFO:
{
if (curIRPStack->Parameters.DeviceIoControl.
InputBufferLength==sizeof(MHANDLE))
{
MHANDLE mh=*((MHANDLE *) Irp->AssociatedIrp.
SystemBuffer);
CAttachedDevice *ptr=(CAttachedDevice *) mh;
if (ptr && ptr->CheckValid())
{
return ptr->GetNext(Irp);
} else
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
} else
Irp->IoStatus.Status = STATUS_INVALID_HANDLE;
Irp->IoStatus.Information = 0;
break;
}
default:
Irp->IoStatus.Status = STATUS_IO_DEVICE_ERROR;
Irp->IoStatus.Information = 0;
break;
}
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return(Irp->IoStatus.Status);
}
NTSTATUS CAttachedDevice::GetNextSize(PIRP Irp)
{
if (!io.IsEmpty())
{
LockExclusive();
IOReq *q=io.RemoveHead();
NTSTATUS ret=ProcessSize(Irp,q);
Unlock();
return ret;
} else
{
ExIRP *irp=new (NonPagedPool) ExIRP;
irp->Irp=Irp;
pending.New(irp);
Irp->IoStatus.Information=0;
Irp->IoStatus.Status=STATUS_PENDING;
IoMarkIrpPending(Irp);
return STATUS_PENDING;
}
}
NTSTATUS CAttachedDevice::GetNext(PIRP Irp)
{
LockExclusive();
if (!io.IsEmpty())
{
IOReq *q=io.RemoveHead();
Unlock();
return ProcessNext(Irp,q);
} else
{
ExIRP *irp=new (NonPagedPool) ExIRP;
irp->Irp=Irp;
pending.New(irp);
Irp->IoStatus.Information=0;
Irp->IoStatus.Status=STATUS_PENDING;
IoMarkIrpPending(Irp);
Unlock();
return STATUS_PENDING;
}
}
现在我想用DeviceIoControl调用驱动程序中的函数,并用文本记录下捕捉到的串口数据,
请问高手怎么调用???参数是怎样的?????
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课