IOCTL 驱动程序系统缓冲区始终为空



我有一个简单的结构,我想传递给我的驱动程序。这是结构:

typedef struct readStruct
{
...
} ReadStruct, *pRreadStruct;

这是我的用户模式应用程序:

DWORD dwReturn;
readStruct reader{ ... };
WriteFile(hDriver, (LPCVOID)&reader, sizeof(ReadStruct), &dwReturn, NULL);

这是我的驱动程序代码,它总是将 NULL 返回给 readStruct。我做错了什么?

PIO_STACK_LOCATION pIoStackIrp = NULL;
pRreadStruct readStruct;
pIoStackIrp = IoGetCurrentIrpStackLocation(Irp);
DbgPrintEx(0, 0, "WriteBufferedIOn");
if (pIoStackIrp)
{
readStruct = (pRreadStruct)Irp->AssociatedIrp.SystemBuffer;
if (readStruct)
{
// this is the place I never get into
if (readStruct->ReadSize)
{
ReadMemOutputClient(readStruct);
}
}
}

DO_BUFFERED_IO标志应该在DeviceObject->Flags的DriverEntry中设置。

感谢用户@RbMm指出这一点。

相关内容