Microsoft DirectX 9.0

Step 1: Creating the DirectInput Object

The first step in setting up the Microsoft?DirectInput?system is to create a single DirectInput object as overall manager. This is done with a call to the DirectInput8Create function.

// HINSTANCE  g_hinst; // initialized earlier
HRESULT         hr; 

hr = DirectInput8Create(g_hinst, DIRECTINPUT_VERSION, 
        IID_IDirectInput8, (void**)&g_lpDI, NULL); 
if FAILED(hr) 
    // DirectInput not available; take appropriate action 

The first parameter for DirectInput8Create is the instance handle to the application or dynamic-link library (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 determines which interface is returned. Most applications obtain the most recent version, by passing IID_IDirectInput8.

The fourth parameter is the address of a variable that is initialized with a valid interface pointer if the call succeeds.

The last parameter specifies the address of the controlling object's IUnknown interface for use in Component Object Model (COM) aggregation. Because most applications do not use aggregation, the value of this parameter is usually NULL.

After creating a single DirectInput object as overall manager, go to Step 2: Creating the DirectInput Keyboard Device.

© 2002 Microsoft Corporation. All rights reserved.