IOCTL驱动程序SystemBuffer始终为NULL

时间:2017-08-20 10:13:02

标签: c++ windows struct driver ioctl

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

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

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

DWORD dwReturn;
readStruct reader{ ... };

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

这是我的驱动程序代码,它总是向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);
        }
    }
}

1 个答案:

答案 0 :(得分:0)

应在 DeviceObject->标志中的DriverEntry中设置

DO_BUFFERED_IO 标志。

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