Click to Rate and Give Feedback
MSDN
MSDN Library
Windows Driver Kit
Reference
 WdfRequestRetrieveOutputBuffer
Windows Driver Kit: Kernel-Mode Driver Framework
WdfRequestRetrieveOutputBuffer

The WdfRequestRetrieveOutputBuffer method retrieves an I/O request's output buffer.

NTSTATUS
  WdfRequestRetrieveOutputBuffer(
    IN WDFREQUEST  Request,
    IN size_t  MinimumRequiredSize,
    OUT PVOID*  Buffer,
    OUT size_t*  Length
    );

Parameters

Request
A handle to a framework request object.
MinimumRequiredSize
The minimum buffer size, in bytes, that the driver needs to process the I/O request.
Buffer
A pointer to a location that receives the buffer's address.
Length
A pointer to a location that receives the buffer's size, in bytes. This parameter is optional and can be NULL.

Return Value

WdfRequestRetrieveOutputBuffer returns STATUS_SUCCESS if the operation succeeds. Otherwise, this method might return one of the following values:

STATUS_INVALID_PARAMETER
An input parameter is invalid.
STATUS_BUFFER_TOO_SMALL
The output buffer's length is zero, or the MinimumRequiredSize parameter specifies a buffer size that is larger than the buffer's actual size.
STATUS_INVALID_DEVICE_REQUEST
The request type is not valid or the request is using neither buffered nor direct I/O. For more information about supported methods for accessing data buffers, see the following Comments section.
STATUS_INTERNAL_ERROR
The request has already been completed.
STATUS_INSUFFICIENT_RESOURCES
There is insufficient memory.

This method might also return other NTSTATUS values.

A bug check occurs if the driver supplies an invalid object handle.

Comments

A request's output buffer receives information, such as data from a disk, that the driver provides to the originator of the request. Your driver can call WdfRequestRetrieveOutputBuffer to obtain the output buffer for a read request or a device I/O control request, but not for a write request (because write requests do not provide output data).

The WdfRequestRetrieveOutputBuffer method retrieves the output buffer for I/O requests that use the buffered I/O method or the direct I/O method for accessing data buffers. If the request's I/O control code is IRP_MJ_INTERNAL_DEVICE_CONTROL, or if the request came from another kernel-mode driver, WdfRequestRetrieveOutputBuffer also supports I/O requests that use neither buffered nor direct I/O.

If WdfRequestRetrieveInputBuffer returns STATUS_SUCCESS, the driver receives the address and, optionally, the size of the output buffer.

The driver can access the retrieved buffer until it completes the I/O request that the Request parameter represents.

Instead of calling WdfRequestRetrieveOutputBuffer, the driver can call WdfRequestRetrieveOutputMemory, which creates a framework memory object that represents the buffer.

For more information about WdfRequestRetrieveOutputBuffer, see Accessing Data Buffers in Framework-Based Drivers.

Example

The following code example is part of an EvtIoDeviceControl callback function. This example obtains a USB device's configuration descriptor and places the descriptor in the I/O request's output buffer.

VOID
MyEvtIoDeviceControl(
    IN WDFQUEUE  Queue,
    IN WDFREQUEST  Request,
    IN size_t  OutputBufferLength,
    IN size_t  InputBufferLength,
    IN ULONG  IoControlCode    
    )
{
    WDFDEVICE  device;
    PDEVICE_CONTEXT  pDevContext;
    size_t  bytesReturned = 0;
    NTSTATUS  status;

    device = WdfIoQueueGetDevice(Queue);
    //
    // GetDeviceContext is a driver-defined function 
    // to retrieve device object context space.
    //
    pDevContext = GetDeviceContext(device);

    switch(IoControlCode) {

      case IOCTL_OSRUSBFX2_GET_CONFIG_DESCRIPTOR: {
        
        PUSB_CONFIGURATION_DESCRIPTOR  configurationDescriptor = NULL;
        USHORT  requiredSize;

        //
        // First, get the size of the USB configuration descriptor.
        //
        status = WdfUsbTargetDeviceRetrieveConfigDescriptor(
                                                pDevContext->UsbDevice,
                                                NULL,
                                                &requiredSize
                                                );
        if (status != STATUS_BUFFER_TOO_SMALL) {
            break;
        }

        //
        // Get the buffer. Make sure the buffer is big
        // enough to hold the configuration descriptor.
        //
        status = WdfRequestRetrieveOutputBuffer(
                                                Request, 
                                                (size_t)requiredSize,
                                                &configurationDescriptor,
                                                NULL
                                                );
        if(!NT_SUCCESS(status)){
            break;
        }
        //
        // Now get the config descriptor.
        //
        status = WdfUsbTargetDeviceRetrieveConfigDescriptor(
                                                pDevContext->UsbDevice,
                                                configurationDescriptor,
                                                &requiredSize
                                                );
        if (!NT_SUCCESS(status)) {
            break;
        }

        bytesReturned = requiredSize;
      }
        break;

    (Other case statements removed.)

    default:
        status = STATUS_INVALID_DEVICE_REQUEST;
        break;
    }
    //
    // Complete the request.
    //
    WdfRequestCompleteWithInformation(
                                      Request,
                                      status,
                                      bytesReturned
                                      );
    return;
}

Requirements

Versions: The WdfRequestRetrieveOutputBuffer method is available in version 1.0 and later versions of KMDF.

IRQL: <=DISPATCH_LEVEL

Headers: Declared in wdfrequest.h. Include wdf.h.

See Also

WdfRequestRetrieveInputBuffer, WdfRequestRetrieveOutputMemory


Send feedback on this topic
Built on October 01, 2009
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker