Step 2: Setting the Mouse Data Format

After retrieving an IDirectInputDevice pointer, your application must set the device's data format. For mouse devices, this is a very simple task. Call the IDirectInputDevice::SetDataFormat method, specifying the data format provided for your convenience by DirectInput in the c_dfDIMouse global variable.

The following code attempts to set the device's data format. If the call fails, an error message is displayed and FALSE is returned.

hr = g_pMouse->SetDataFormat(&c_dfDIMouse);

if (FAILED(hr)) {
    Complain(hwnd, hr, "SetDataFormat(SysMouse, dfDIMouse)");
    return FALSE;
}