IDirectInputDevice::GetDeviceState

The IDirectInputDevice::GetDeviceState method retrieves instantaneous data from the device.

HRESULT GetDeviceState(
  DWORD cbData,  
  LPVOID lpvData 
);
 

Parameters

cbData
Size of the buffer in the lpvData parameter, in bytes.
lpvData
Address of a structure that receives the current state of the device. The format of the data is established by a prior call to the IDirectInputDevice::SetDataFormat method.

Return Values

If the method succeeds, the return value is DI_OK.

If the method fails, the return value may be one of the following error values:

DIERR_INPUTLOST
DIERR_INVALIDPARAM
DIERR_NOTACQUIRED
DIERR_NOTINITIALIZED
E_PENDING

Remarks

Before device data can be obtained, set the cooperative level by using the IDirectInputDevice::SetCooperativeLevel method, then set the data format by using IDirectInputDevice::SetDataFormat, and acquire the device by using the IDirectInputDevice::Acquire method.

The four predefined data formats require corresponding device state structures according to the following table:

Data Format State Structure
c_dfDIMouse DIMOUSESTATE
c_dfDIKeyboard array of 256 bytes
c_dfDIJoystick DIJOYSTATE
c_dfDIJoystick2 DIJOYSTATE2

For example, if you passed the c_dfDIMouse format to the IDirectInputDevice::SetDataFormat method, you must pass a DIMOUSESTATE structure to the IDirectInputDevice::GetDeviceState method.

QuickInfo

  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.

See Also

IDirectInputDevice2::Poll, Polling and Events