IOCTL 驱动程序 SystemBuffer 始终为 NULL

IOCTL Driver SystemBuffer always NULL

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

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

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

DWORD dwReturn;
readStruct reader{ ... };

WriteFile(hDriver, (LPCVOID)&reader, sizeof(ReadStruct), &dwReturn, NULL);

这是我的驱动程序代码,它总是 returns readStruct 为 NULL。我做错了什么?

PIO_STACK_LOCATION pIoStackIrp = NULL;
pRreadStruct readStruct;

pIoStackIrp = IoGetCurrentIrpStackLocation(Irp);

DbgPrintEx(0, 0, "WriteBufferedIO\n");

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 flag should be set in DriverEntry in DeviceObject->Flags.

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