Determining Connected Joysticks Under Windows 95

Last reviewed: July 25, 1995
Article ID: Q133065
The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK)

SUMMARY

The 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 INFORMATION

Under 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
KBCategory: kbmm
KBSubcategory: MMJoy


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 25, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.