Step 1: Creating the DirectInput Object
The first step in setting up the DirectInput system is to create a single DirectInput object as overall manager. This is done with a call to the DirectInputCreate function.
// HINSTANCE hinst; // initialized earlier
HRESULT hr;
LPDIRECTINPUT g_lpdi;
hr = DirectInputCreate(hinst, DIRECTINPUT_VERSION, &g_lpdi, NULL);
if FAILED(hr)
{
// DirectInput not available; take appropriate action
}
The first parameter for DirectInputCreate is the instance handle to the application or DLL that is creating the object.
The second parameter tells the DirectInput object which version of the DirectInput system should be used. You can design your application to be compatible with earlier versions of DirectInput. For more information, see Designing for Previous Versions of DirectInput.
The third parameter is the address of a variable that will be initialized with a valid IDirectInput interface pointer if the call succeeds.
The last parameter specifies the address of the controlling object's IUnknown interface for use in COM aggregation. Most applications will not be using aggregation and so will pass NULL.