[Plib-devel] Re: WIN32 USB joystick name problem - possible fix [was: Joystick documentation problem
Brought to you by:
sjbaker
|
From: Sebastian U. <ud...@ha...> - 2002-09-07 23:11:31
|
On Sat, 07 Sep 2002, jul...@bt... (Julian Foad) wrote: > Date: Sat, 07 Sep 2002 16:42:44 +0100 > To: pli...@li... > From: jul...@bt... (Julian Foad) > Reply-To: pli...@li... > Subject: [Plib-devel] Re: WIN32 USB joystick name problem - possible fix > [was: Joystick documentation problem] [...] > Bingo! Thank you for finding this. It works under CygWin, so I hope it > will work under all versions of Windows, both under CygWin and natively > (MSVC). > > I believe there are combinations of Windows version and joystick type > for which the existing method works. A big question for people to > investigate is: does this new method report the same name? All I know is that not only people with USB joysticks were affected by the problem of szPname containing "Microsoft PC-joystick driver" string or localized version. I had a friend of mine testing the stuff, and for him the old method did not return the actual name of his Microsoft Sidewinder Precision Pro, attached to the Soundcard's gameport ! > For my joystick it gives "Saitek Cyborg 3D Stick USB" which isn't the > same as the (Linux?) name in > $FG_BASE/Input/Joysticks/Saitek/Cyborg-Gold-3d-USB.xml: <name>SAITEK > CYBORG 3D USB</name> but it is easy to add both names. Maybe my > joystick is a slightly different model, or maybe this is still not _the_ > name obtained from the hardware. This difference is a little worrying, > but it is still infinitely better than the plain default driver name > that we were getting. Well, it is the job of you flightgear guys to find out which joysticks show up under which names under different operating systems and to adjust your database accordingly. As you said, getting *something* is still better than the default driver name. > Patch attached. Perhaps you would check it in so that people can try it > out and decide whether it's good enough. I corrected the > max-name-length handling in the example code that you sent (from > Microsoft?), but otherwise left it as it is. I checked a slightly modified version of the stuff into CVS. By the way: I copied the code as seen on MSDN into my mail - and the wrong max-name-length was not the only strange thing I found in it now that I had a closer look onto the code. For example, the third argument to the RegQueryValueEx () is a "unsigned char *" (LPBYTE) pointer. At the top of the function, the programmer defines an array of unsigned chars (UCHAR) called "szOEMKey". Now, when calling RegQueryValueEx (), whoever wrote the MSDN document takes the address of the array, thus gets a "unsigned char **" pointer which he casts back into an "unsigned char *" (LPBYTE) pointer in order to pass it to the function. unsigned char szOEMKey[256]; /* ... */ RegQueryValueEx ( /* ... */ (unsigned char *) &szOEMKey /* ... */ ) ; The same thing is done another time in the function. What the heck is the idea behind this ? I hard a hard time thinking if there could be a good reason to take address of the array of unsigned chars (unsigned char **) and cast it back into a pointer-to-unsigned-char (unsigned char *), but I could not find one. That brings up a scary idea: Perhaps the Microsoft employee had not too much knowledge about pointers and arrays in C, just saw that the function requires a pointer as it third argument and hence took the address of the array. Of course, the compiler complained about the programmer passing "unsigned char **" to a function expecting "unsigned char *", and in good-old Microsoft fashion he placed a cast to make the compiler shut up .. - Sebastian |