|Microsoft DirectX 9.0|
If you are not using Action Mapping, setting the data format for a device is an essential step before you can acquire and begin using the device. This is true even if you do not intend to retrieve immediate (state) data from the device. Microsoft?DirectInput?uses the data format in many methods to identify particular device objects.
The IDirectInputDevice8::SetDataFormat method tells DirectInput what device objects will be used and how the data will be arranged.
The examples in the reference for the DIDATAFORMAT and DIOBJECTDATAFORMAT structures show how to set up custom data formats for nonstandard devices. Fortunately, this step is not necessary for the joystick, keyboard, and mouse. DirectInput provides five global variables, c_dfDIJoystick, c_dfDIJoystick2, c_dfDIKeyboard, c_dfDIMouse, and c_dfDIMouse2, which can be passed in to IDirectInputDevice8::SetDataFormat to create a standard data format for these devices.
In the following code example, lpdiMouse is an initialized pointer to a DirectInputDevice object: