| DirectX SDK | 
The IDirectInputDevice7::GetDeviceData method retrieves buffered data from the device.
HRESULT GetDeviceData( DWORD cbObjectData, LPDIDEVICEOBJECTDATA rgdod, LPDWORD pdwInOut, DWORD dwFlags );
If the method succeeds, the return value is DI_OK or DI_BUFFEROVERFLOW.
If the method fails, the return value can be one of the following error values:
| DIERR_INPUTLOST | 
| DIERR_INVALIDPARAM | 
| DIERR_NOTACQUIRED | 
| DIERR_NOTBUFFERED | 
| DIERR_NOTINITIALIZED | 
Before device data can be obtained, you must set the data format by using the IDirectInputDevice7::SetDataFormat method, set the buffer size with the IDirectInputDevice7::SetProperty method, and acquire the device by using the IDirectInputDevice7::Acquire method.
The following code example reads up to ten buffered data elements, removing them from the device buffer as they are read.
DIDEVICEOBJECTDATA rgdod[10]; 
DWORD dwItems = 10; 
hres = IDirectInputDevice7_GetDeviceData( 
    pdid, 
    sizeof(DIDEVICEOBJECTDATA), 
    rgdod, 
    &dwItems, 
    0); 
if (SUCCEEDED(hres)) { 
    // dwItems = number of elements read (could be zero)
    if (hres == DI_BUFFEROVERFLOW) { 
    // Buffer had overflowed. 
    } 
} 
Your application can flush the buffer and retrieve the number of flushed items by specifying NULL for the rgdod parameter and a pointer to a variable containing INFINITE for the pdwInOut parameter. The following code example illustrates how this can be done:
dwItems = INFINITE; 
hres = IDirectInputDevice7_GetDeviceData( 
            pdid, 
            sizeof(DIDEVICEOBJECTDATA), 
            NULL, 
            &dwItems, 
            0); 
if (SUCCEEDED(hres)) { 
    // Buffer successfully flushed 
    // dwItems = number of elements flushed 
    if (hres == DI_BUFFEROVERFLOW) { 
        // Buffer had overflowed. 
    } 
} 
Your application can query for the number of elements in the device buffer by setting the rgdod parameter to NULL, setting pdwInOut to INFINITE and setting dwFlags to DIGDD_PEEK. The following code example illustrates how this can be done:
dwItems = INFINITE; 
hres = IDirectInputDevice7_GetDeviceData( 
            pdid, 
            sizeof(DIDEVICEOBJECTDATA), 
            NULL, 
            &dwItems, 
            DIGDD_PEEK); 
if (SUCCEEDED(hres)) { 
    // dwItems = number of elements in buffer 
    if (hres == DI_BUFFEROVERFLOW) { 
        // Buffer overflow occurred; not all data 
        // was successfully captured. 
    } 
} 
To query about whether a buffer overflow has occurred, set the rgdod parameter to NULL and the pdwInOut parameter to 0. The following code example illustrates how this can be done:
dwItems = 0; 
hres = IDirectInputDevice7_GetDeviceData( 
            pdid, 
            sizeof(DIDEVICEOBJECTDATA), 
            NULL, 
            &dwItems, 
            0); 
if (hres == DI_BUFFEROVERFLOW) { 
    // Buffer overflow occurred 
} 
  Windows NT/2000: Requires Windows 2000.
  Windows 95/98: Requires Windows 95 or later. Available as a redistributable for Windows 95.
  Header: Declared in dinput.h.
  Import Library: Use dinput.lib.