WdfMemoryGetBuffer function (wdfmemory.h)

[Applies to KMDF and UMDF]

The WdfMemoryGetBuffer method returns a pointer to the buffer that is associated with a specified memory object.

Syntax

PVOID WdfMemoryGetBuffer(
  [in]            WDFMEMORY Memory,
  [out, optional] size_t    *BufferSize
);

Parameters

[in] Memory

A handle to a framework memory object.

[out, optional] BufferSize

A pointer to a location that receives the size, in bytes, of the memory buffer. This parameter is optional and can be NULL.

Return value

WdfMemoryGetBuffer returns a pointer to the memory buffer.

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

Remarks

For more information about framework memory objects, see Using Memory Buffers.

WdfMemoryGetBuffer can be called at any IRQL.

Examples

The following code example is based on the EvtUsbTargetPipeReadComplete callback function in the kmdf_fx2 sample driver. The example obtains the buffer that is associated with the memory object that the callback function receives. The example copies data from the buffer into device object context space that the driver has defined.

VOID
OsrFxEvtUsbInterruptPipeReadComplete(
    WDFUSBPIPE  Pipe,
    WDFMEMORY  Buffer,
    size_t  NumBytesTransferred,
    WDFCONTEXT  Context
    )
{
    PUCHAR  switchState = NULL;
    WDFDEVICE  device;
    PDEVICE_CONTEXT  pDeviceContext = Context;

    device = WdfObjectContextGetObject(pDeviceContext);
    switchState = WdfMemoryGetBuffer(Buffer, NULL);
    pDeviceContext->CurrentSwitchState = *switchState;
}

Requirements

Requirement Value
Target Platform Universal
Minimum KMDF version 1.0
Minimum UMDF version 2.0
Header wdfmemory.h (include Wdf.h)
Library Wdf01000.sys (KMDF); WUDFx02000.dll (UMDF)
IRQL Any level
DDI compliance rules DriverCreate(kmdf), MemAfterReqCompletedIntIoctlA(kmdf), MemAfterReqCompletedIoctlA(kmdf), MemAfterReqCompletedReadA(kmdf), MemAfterReqCompletedWriteA(kmdf)

See also

WdfMemoryCreate

WdfMemoryCreatePreallocated

WdfObjectContextGetObject