Getting the Driver Capabilities
[The feature associated with this page, Joysticks, is a legacy feature. It has been superseded by Windows.Gaming.Input Namespace. Windows.Gaming.Input Namespace has been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use Windows.Gaming.Input Namespace instead of Joysticks, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]
The following example uses joyGetNumDevs and joyGetPos to determine whether the joystick services are available and if a joystick is attached to one of the ports.
JOYINFO joyinfo;
UINT wNumDevs, wDeviceID;
BOOL bDev1Attached, bDev2Attached;
if((wNumDevs = joyGetNumDevs()) == 0)
return ERR_NODRIVER;
bDev1Attached = joyGetPos(JOYSTICKID1,&joyinfo) != JOYERR_UNPLUGGED;
bDev2Attached = wNumDevs == 2 && joyGetPos(JOYSTICKID2,&joyinfo) !=
JOYERR_UNPLUGGED;
if(bDev1Attached || bDev2Attached) // decide which joystick to use
wDeviceID = bDev1Attached ? JOYSTICKID1 : JOYSTICKID2;
else
return ERR_NODEVICE;