我想写一个tdi两端通信的程序,客户端用的普通socket,服务端则是tdi 建立基本的连接后,用函数sendtocontroler()发送和receivefromcontroller()接受。sendtocontroler()没有问题,就是receivefromcontroler()出错。
NTSTATUS receivefromcontroler( )
{
PDEVICE_OBJECT devObj;
KEVENT receiveevent;
PIRP irp;
PMDL mdl;
IO_STATUS_BLOCK iosb;
NTSTATUS status;
devObj = IoGetRelatedDeviceObject(connectionFileObject);
KeInitializeEvent(&receiveevent, NotificationEvent, FALSE);
irp = TdiBuildInternalDeviceControlIrp(TDI_RECEIVE, devObj, connectionFileObject, &receiveevent, &iosb);
if (irp == NULL)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
if (len)
{
mdl = IoAllocateMdl((void*) buf, len, FALSE, FALSE, NULL);
if (mdl == NULL)
{
IoFreeIrp(irp);
return STATUS_INSUFFICIENT_RESOURCES;
}
__try
{
MmProbeAndLockPages(mdl, KernelMode, IoReadAccess);
status = STATUS_SUCCESS;
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
IoFreeMdl(mdl);
IoFreeIrp(irp);
status = STATUS_INVALID_USER_BUFFER;
}
if (!NT_SUCCESS(status))
{
return status;
}
}
TdiBuildReceive(irp, devObj, connectionFileObject, NULL, NULL, len ,mdl , flags, len);
IoSetCompletionRoutine(irp,TDICompletionRoutine,&receiveevent,TRUE.TRUE,TRUE);
status = IoCallDriver(devObj, irp);
if (status == STATUS_PENDING)
{
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
status = iosb.Status;
}
return NT_SUCCESS(status) ;
memcpy(getcommand,mdl ,strlen(mdl ));
}
外面定义 char getcommand[256];
接受一个命令没有问题,我在主函数中创建了一个线程,在其中用while(true)
{receivefromcontroler();},当不启动客户端只启动服务端时就会蓝屏,当和客户端建立连接然后
客户端推出时,也会蓝屏,但是不用while循环就不会这样,不知道为什么,困扰了好久,请求各位大侠帮忙
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!