Determining Connected Joysticks Under Windows 95Last reviewed: July 25, 1995Article ID: Q133065 |
The information in this article applies to:
SUMMARYThe joystick API joyGetNumDevs() behaves differently on Windows 95 than it does in other implementations, so a different technique, involving joyGetPosEx(), is required to determine the number of joysticks available during game play. This article provides the code for a function called JoysticksConnected() that demonstrates how to determine the number of connected joysticks.
MORE INFORMATIONUnder Windows 95, the joyGetNumDevs() API returns: 0 if no joystick drivers have been installed or 16 (the highest possible number of connected joysticks) in all other cases. This behavior is by design. To determine the actual number of joysticks installed, use the joyGetPosEx() API. The design for Windows 95 joystick drivers calls for the driver to support two independent joystick input devices. Therefore, during driver installation, two registry keys are created, and initialized. The keys correspond to joystick 0 and joystick 1, respectively. If no joystick support is available (no drivers), joyGetNumDevs() returns 0. When joyGetNumDevs() returns a non-zero value, joyGetPosEx() returns JOYERR_NOERRROR or JOYERR_PARMS (defined in the file MMSYSTEM.H). You can examine the return values and determine the number of joysticks connected as shown below. NOTE: when linking, WINMM.LIB must be from the Win32 SDK:
int JoysticksConnected( ) { // determine number of joysticks installed in Windows 95 JOYINFOEX info; // extended information int njoyId = 0; // first joystick int nConnected = 0; // goal - number of joysticks connected MMRESULT dwResult; // examine return values // Loop through all possible joystick IDs until we get the error // JOYERR_PARMS. Count the number of times we get JOYERR_NOERROR // indicating an installed joystick driver with a joystick currently // attached to the port. while ((dwResult = joyGetPosEx(njoyId++,&info)) != JOYERR_PARMS) if (dwResult == JOYERR_NOERROR) ++nConnected; // the count of connected joysticks return nConnected; // return the count of joysticks found } // JoysticksConnected |
Additional reference words: 4.00 JOYERR connect kbinf
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |