1

正如标题所示,我在使用以下代码时遇到了问题:

EvtDeviceIoWrite(
   IN WDFQUEUE  Queue,
   IN WDFREQUEST  Request,
   IN size_t Length
) {
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
attributes.ParentObject = WdfIoQueueGetDevice(Queue);
status = WdfRequestCreate(&attributes, WdfDeviceGetIoTarget(WdfIoQueueGetDevice(Queue)), &newRequest);  
if (!NT_SUCCESS(status)) {
    KdPrint(("Serial:  failed 0x%x\n", status));
    WdfRequestComplete(Request, status);
    return;
}
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
attributes.ParentObject = newRequest;
status = WdfMemoryCreate(&attributes, NonPagedPool, 'MyPl', 10, &newmem, &newbuf);
if (!NT_SUCCESS(status)) {
    KdPrint(("Serial:  failed 0x%x\n", status));
    WdfRequestComplete(Request, status);
    return;
}

WDF_REQUEST_SEND_OPTIONS_INIT(&options,
    WDF_REQUEST_SEND_OPTION_SEND_AND_FORGET);
ret = WdfRequestSend(newRequest, WdfDeviceGetIoTarget(WdfIoQueueGetDevice(Queue)), &options);
}
if (ret == FALSE) {
    status = WdfRequestGetStatus(newRequest);
    KdPrint(("WdfRequestSend failed: 0x%x\n", status));
    WdfRequestComplete(Request, status);
}

我无法将 newRequest 发送到堆栈中... ret 值为“FALSE”,状态为 STATUS_INVALID_DEVICE_STATE。如何使设备处于正确的状态?

正如链接所示,我做的一切都是正确的。总而言之,我无法将请求发送到本地 IO 堆栈,目标 IO 处于不正确的状态,我不知道如何让它工作?

4

1 回答 1

0
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
attributes.ParentObject = WdfIoQueueGetDevice(Queue);
status = WdfRequestCreate(&attributes, WdfDeviceGetIoTarget(WdfIoQueueGetDevice(Queue)), &newRequest);  
if (!NT_SUCCESS(status)) {
    KdPrint(("Serial:  failed 0x%x\n", status));
    WdfRequestComplete(Request, status);
    return;
}
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
attributes.ParentObject = newRequest;
status = WdfMemoryCreate(&attributes, NonPagedPool, 'MyPl', 10, &newMem, &newBuf);
if (!NT_SUCCESS(status)) {
    KdPrint(("Serial:  failed 0x%x\n", status));
    WdfRequestComplete(Request, status);
    return;
}
/*Proessing request */


/*End Processing request */
WdfRequestFormatRequestUsingCurrentType(newRequest);
WdfIoTargetFormatRequestForWrite(WdfDeviceGetIoTarget(WdfIoQueueGetDevice(Queue)), newRequest, newMem, NULL , NULL);
ret = WdfRequestSend(newRequest, WdfDeviceGetIoTarget(WdfIoQueueGetDevice(Queue)), NULL);

if (ret == FALSE) {
    status = WdfRequestGetStatus(newRequest);
    KdPrint(("WdfRequestSend failed: 0x%x\n", status));

}
WdfRequestComplete(Request, status);

这是实现它的方法。

于 2017-02-09T22:54:24.897 回答