Device Capabilities

Before you begin asking for input from a device, you need to know something about its capabilities. Does the joystick have a point-of-view hat? Is the mouse currently attached to the user's computer?

DIDEVCAPS  DIMouseCaps;
HRESULT    hr; 
BOOLEAN    WheelAvailable; 

DIMouseCaps.dwSize = sizeof(DIDEVCAPS); 
hr = lpdiMouse->GetCapabilities(&DIMouseCaps); 
WheelAvailable = ((DIMouseCaps.dwFlags & DIDC_ATTACHED) 
        && (DIMouseCaps.dwAxes > 2)); 

Another way to check for a button or axis is to call IDirectInputDevice8::GetObjectInfo for that object. If the call returns DIERR_OBJECTNOTFOUND, the object is not present. The following code determines whether there is a z-axis, even if it is not the third axis:

DIDEVICEOBJECTINSTANCE  didoi; 

didoi.dwSize = sizeof(DIDEVICEOBJECTINSTANCE); 
hr = lpdiMouse->GetObjectInfo(&didoi, DIMOFS_Z, DIPH_BYOFFSET); 
    WheelAvailable = SUCCEEDED(hr);