Microsoft DirectX 8.1 (C++)

Step 5: Gaining Access to the Joystick

After your application sets a joystick's behavior, it can acquire access to the device by calling the IDirectInputDevice8::Acquire method. The application must acquire the device before retrieving data from it. The Acquire method accepts no parameters.

The Joystick sample performs initial acquisition in the message loop as the application is activated. This loop also automatically reacquires the device whenever the application regains focus after having lost it. Acquisition is also performed if access to the joystick is lost or a DIERR_INPUTLOST error is returned when the application attempts to get input data. This is shown in the following code sample.

hr = g_pJoystick->Poll(); 
if (FAILED(hr)) 
{
    hr = g_pJoystick->Acquire();
    while(hr == DIERR_INPUTLOST) 
        hr = g_pJoystick->Acquire();
    return S_OK; 
}

Once your application can gain access to the joystick go to Step 6: Retrieving Data from the Joystick.