comparison src/joystick/win32/SDL_mmjoystick.c @ 1330:450721ad5436

It's now possible to build SDL without any C runtime at all on Windows, using Visual C++ 2005
author Sam Lantinga <slouken@libsdl.org>
date Mon, 06 Feb 2006 08:28:51 +0000
parents c9b51268668f
children 3692456e7b0f
comparison
equal deleted inserted replaced
1329:bc67bbf87818 1330:450721ad5436
20 slouken@libsdl.org 20 slouken@libsdl.org
21 */ 21 */
22 22
23 /* Win32 MultiMedia Joystick driver, contributed by Andrei de A. Formiga */ 23 /* Win32 MultiMedia Joystick driver, contributed by Andrei de A. Formiga */
24 24
25 #include <stdlib.h>
26 #include <stdio.h> /* For the definition of NULL */
27
28 #include "SDL_error.h" 25 #include "SDL_error.h"
26 #include "SDL_events.h"
29 #include "SDL_joystick.h" 27 #include "SDL_joystick.h"
28 #include "SDL_stdlib.h"
29 #include "SDL_string.h"
30 #include "SDL_sysjoystick.h" 30 #include "SDL_sysjoystick.h"
31 #include "SDL_joystick_c.h" 31 #include "SDL_joystick_c.h"
32 32
33 #include <windows.h> 33 #include "SDL_windows.h"
34 #include <mmsystem.h> 34 #include <mmsystem.h>
35 #include <regstr.h> 35 #include <regstr.h>
36 36
37 #define MAX_JOYSTICKS 16 37 #define MAX_JOYSTICKS 16
38 #define MAX_AXES 6 /* each joystick can have up to 6 axes */ 38 #define MAX_AXES 6 /* each joystick can have up to 6 axes */
80 LONG regresult; 80 LONG regresult;
81 unsigned char regkey[256]; 81 unsigned char regkey[256];
82 unsigned char regvalue[256]; 82 unsigned char regvalue[256];
83 unsigned char regname[256]; 83 unsigned char regname[256];
84 84
85 sprintf((char *) regkey, "%s\\%s\\%s", 85 snprintf((char *) regkey, SDL_arraysize(regkey), "%s\\%s\\%s",
86 REGSTR_PATH_JOYCONFIG, 86 REGSTR_PATH_JOYCONFIG,
87 szRegKey, 87 szRegKey,
88 REGSTR_KEY_JOYCURR); 88 REGSTR_KEY_JOYCURR);
89 regresult = RegOpenKeyExA(HKEY_LOCAL_MACHINE, 89 regresult = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
90 (LPTSTR) &regkey, 0, KEY_READ, &hKey); 90 (LPTSTR) &regkey, 0, KEY_READ, &hKey);
93 /* 93 /*
94 find the registry key name for the 94 find the registry key name for the
95 joystick's properties 95 joystick's properties
96 */ 96 */
97 regsize = sizeof(regname); 97 regsize = sizeof(regname);
98 sprintf((char *) regvalue, 98 snprintf((char *) regvalue, SDL_arraysize(regvalue),
99 "Joystick%d%s", index+1, 99 "Joystick%d%s", index+1,
100 REGSTR_VAL_JOYOEMNAME); 100 REGSTR_VAL_JOYOEMNAME);
101 regresult = RegQueryValueExA(hKey, 101 regresult = RegQueryValueExA(hKey,
102 (char *) regvalue, 0, 0, (LPBYTE) &regname, 102 (char *) regvalue, 0, 0, (LPBYTE) &regname,
103 (LPDWORD) &regsize); 103 (LPDWORD) &regsize);
104 RegCloseKey(hKey); 104 RegCloseKey(hKey);
105 if (regresult == ERROR_SUCCESS) 105 if (regresult == ERROR_SUCCESS)
106 { 106 {
107 /* open that registry key */ 107 /* open that registry key */
108 sprintf((char *) regkey, "%s\\%s", 108 snprintf((char *) regkey, SDL_arraysize(regkey), "%s\\%s",
109 REGSTR_PATH_JOYOEM, regname); 109 REGSTR_PATH_JOYOEM, regname);
110 regresult = RegOpenKeyExA(HKEY_LOCAL_MACHINE, 110 regresult = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
111 (char *) regkey, 0, KEY_READ, &hKey); 111 (char *) regkey, 0, KEY_READ, &hKey);
112 if (regresult == ERROR_SUCCESS) 112 if (regresult == ERROR_SUCCESS)
113 { 113 {
377 377
378 /* implementation functions */ 378 /* implementation functions */
379 void SetMMerror(char *function, int code) 379 void SetMMerror(char *function, int code)
380 { 380 {
381 static char *error; 381 static char *error;
382 static char errbuf[BUFSIZ]; 382 static char errbuf[1024];
383 383
384 errbuf[0] = 0; 384 errbuf[0] = 0;
385 switch (code) 385 switch (code)
386 { 386 {
387 case MMSYSERR_NODRIVER: 387 case MMSYSERR_NODRIVER:
404 case JOYERR_NOCANDO: 404 case JOYERR_NOCANDO:
405 error = "Can't capture joystick input"; 405 error = "Can't capture joystick input";
406 break; 406 break;
407 407
408 default: 408 default:
409 sprintf(errbuf, "%s: Unknown Multimedia system error: 0x%x", 409 snprintf(errbuf, SDL_arraysize(errbuf),
410 "%s: Unknown Multimedia system error: 0x%x",
410 function, code); 411 function, code);
411 break; 412 break;
412 } 413 }
413 414
414 if ( ! errbuf[0] ) { 415 if ( ! errbuf[0] ) {
415 sprintf(errbuf, "%s: %s", function, error); 416 snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error);
416 } 417 }
417 SDL_SetError("%s", errbuf); 418 SDL_SetError("%s", errbuf);
418 } 419 }