Setting the data format for a device is an essential step before you can acquire and begin using the device. The IDirectInputDevice::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 structure and DIOBJECTDATAFORMAT structure will give you an idea of how to set up custom data formats for nonstandard devices. Fortunately, this step is not necessary for the joystick, keyboard, and mouse. DirectInput provides four global variables, c_dfDIJoystick, c_dfDIJoystick2, c_dfDIKeyboard, and c_dfDIMouse, which can be passed into SetDataFormat to create a standard data format for these devices.
Here is an example, where lpdiMouse is an initialized pointer to the mouse device object:
lpdiMouse->SetDataFormat(&c_dfDIMouse);
Note You cannot change the dwFlags member in the predefined DIDATAFORMAT global variables (for example, in order to change the property of an axis), because they are const variables. To change properties, use the IDirectInputDevice::SetProperty method after setting the data format but before acquiring the device.