GetRawInputBuffer function (winuser.h)

Performs a buffered read of the raw input messages data found in the calling thread's message queue.


UINT GetRawInputBuffer(
  [out, optional] PRAWINPUT pData,
  [in, out]       PUINT     pcbSize,
  [in]            UINT      cbSizeHeader


[out, optional] pData


A pointer to a buffer of RAWINPUT structures that contain the raw input data. Buffer should be aligned on a pointer boundary, which is a DWORD on 32-bit architectures and a QWORD on 64-bit architectures.

If NULL, size of the first raw input message data (minimum required buffer), in bytes, is returned in *pcbSize.

[in, out] pcbSize


The size, in bytes, of the provided RAWINPUT buffer.

[in] cbSizeHeader

Type: UINT

The size, in bytes, of the RAWINPUTHEADER structure.

Return value

Type: UINT

If pData is NULL and the function is successful, the return value is zero. If pData is not NULL and the function is successful, the return value is the number of RAWINPUT structures written to pData.

If an error occurs, the return value is (UINT)-1. Call GetLastError for the error code.


When an application receives raw input, its message queue gets a WM_INPUT message and the queue status flag QS_RAWINPUT is set.

Using GetRawInputBuffer, the raw input data is read in the array of variable size RAWINPUT structures and corresponding WM_INPUT messages are removed from the calling thread's message queue. You can call this method several times with buffer that cannot fit all message's data until all raw input messages have been read.

The NEXTRAWINPUTBLOCK macro allows an application to traverse an array of RAWINPUT structures.

If all raw input messages have been successfully read from message queue then QS_RAWINPUT flag is cleared from the calling thread's message queue status.


WOW64: To get the correct size of the raw input buffer, do not use *pcbSize, use *pcbSize * 8 instead. To ensure GetRawInputBuffer behaves properly on WOW64, you must align the RAWINPUT structure by 8 bytes. The following code shows how to align RAWINPUT for WOW64.

internal struct RAWINPUT
    public RAWINPUTHEADER header;

    public RAWMOUSE mouse;

    public RAWKEYBOARD keyboard;

    public RAWHID hid;


Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header winuser.h (include Windows.h)
Library User32.lib
DLL User32.dll

See also






Raw Input


Raw Input Overview