comparison src/joystick/win32/SDL_mmjoystick.c @ 4051:209a3ef8a328 SDL-1.2

Fixed joystick name detection
author Sam Lantinga <slouken@libsdl.org>
date Thu, 12 Jul 2007 05:19:55 +0000
parents 36f155ec8133
children 96ce26f24b01
comparison
equal deleted inserted replaced
4050:ef815c44c662 4051:209a3ef8a328
74 /* 74 /*
75 see if there is a joystick for the current 75 see if there is a joystick for the current
76 index (1-16) listed in the registry 76 index (1-16) listed in the registry
77 */ 77 */
78 char *name = NULL; 78 char *name = NULL;
79 HKEY hTopKey;
79 HKEY hKey; 80 HKEY hKey;
80 DWORD regsize; 81 DWORD regsize;
81 LONG regresult; 82 LONG regresult;
82 unsigned char regkey[256]; 83 char regkey[256];
83 unsigned char regvalue[256]; 84 char regvalue[256];
84 unsigned char regname[256]; 85 char regname[256];
85 86
86 SDL_snprintf((char *) regkey, SDL_arraysize(regkey), "%s\\%s\\%s", 87 SDL_snprintf(regkey, SDL_arraysize(regkey), "%s\\%s\\%s",
87 REGSTR_PATH_JOYCONFIG, 88 REGSTR_PATH_JOYCONFIG, szRegKey, REGSTR_KEY_JOYCURR);
88 szRegKey, 89 hTopKey = HKEY_LOCAL_MACHINE;
89 REGSTR_KEY_JOYCURR); 90 regresult = RegOpenKeyExA(hTopKey, regkey, 0, KEY_READ, &hKey);
90 regresult = RegOpenKeyExA(HKEY_LOCAL_MACHINE, 91 if (regresult != ERROR_SUCCESS) {
91 (LPTSTR) &regkey, 0, KEY_READ, &hKey); 92 hTopKey = HKEY_CURRENT_USER;
92 if (regresult == ERROR_SUCCESS) 93 regresult = RegOpenKeyExA(hTopKey, regkey, 0, KEY_READ, &hKey);
93 { 94 }
94 /* 95 if (regresult != ERROR_SUCCESS) {
95 find the registry key name for the 96 return NULL;
96 joystick's properties 97 }
97 */ 98
98 regsize = sizeof(regname); 99 /* find the registry key name for the joystick's properties */
99 SDL_snprintf((char *) regvalue, SDL_arraysize(regvalue), 100 regsize = sizeof(regname);
100 "Joystick%d%s", index+1, 101 SDL_snprintf(regvalue, SDL_arraysize(regvalue), "Joystick%d%s", index+1, REGSTR_VAL_JOYOEMNAME);
101 REGSTR_VAL_JOYOEMNAME); 102 regresult = RegQueryValueExA(hKey, regvalue, 0, 0, (LPBYTE)regname, &regsize);
102 regresult = RegQueryValueExA(hKey, 103 RegCloseKey(hKey);
103 (char *) regvalue, 0, 0, (LPBYTE) &regname, 104
104 (LPDWORD) &regsize); 105 if (regresult != ERROR_SUCCESS) {
105 RegCloseKey(hKey); 106 return NULL;
106 if (regresult == ERROR_SUCCESS) 107 }
107 { 108
108 /* open that registry key */ 109 /* open that registry key */
109 SDL_snprintf((char *) regkey, SDL_arraysize(regkey), "%s\\%s", 110 SDL_snprintf(regkey, SDL_arraysize(regkey), "%s\\%s", REGSTR_PATH_JOYOEM, regname);
110 REGSTR_PATH_JOYOEM, regname); 111 regresult = RegOpenKeyExA(hTopKey, regkey, 0, KEY_READ, &hKey);
111 regresult = RegOpenKeyExA(HKEY_LOCAL_MACHINE, 112 if (regresult != ERROR_SUCCESS) {
112 (char *) regkey, 0, KEY_READ, &hKey); 113 return NULL;
113 if (regresult == ERROR_SUCCESS) 114 }
114 { 115
115 /* find the size for the OEM name text */ 116 /* find the size for the OEM name text */
116 regsize = sizeof(regvalue); 117 regsize = sizeof(regvalue);
117 regresult = 118 regresult = RegQueryValueExA(hKey, REGSTR_VAL_JOYOEMNAME, 0, 0, NULL, &regsize);
118 RegQueryValueExA(hKey, 119 if (regresult == ERROR_SUCCESS) {
119 REGSTR_VAL_JOYOEMNAME, 120 /* allocate enough memory for the OEM name text ... */
120 0, 0, NULL, 121 name = (char *) SDL_malloc(regsize);
121 (LPDWORD) &regsize); 122 if ( name ) {
122 if (regresult == ERROR_SUCCESS) 123 /* ... and read it from the registry */
123 { 124 regresult = RegQueryValueExA(hKey,
124 /* 125 REGSTR_VAL_JOYOEMNAME, 0, 0,
125 allocate enough memory 126 (LPBYTE) name, &regsize);
126 for the OEM name text ... 127 }
127 */ 128 }
128 name = (char *) SDL_malloc(regsize); 129 RegCloseKey(hKey);
129 /* ... and read it from the registry */ 130
130 regresult =
131 RegQueryValueExA(hKey,
132 REGSTR_VAL_JOYOEMNAME, 0, 0,
133 (LPBYTE) name,
134 (LPDWORD) &regsize);
135 RegCloseKey(hKey);
136 }
137 }
138 }
139 }
140 return(name); 131 return(name);
141 } 132 }
142 133
143 /* Function to scan the system for joysticks. 134 /* Function to scan the system for joysticks.
144 * This function should set SDL_numjoysticks to the number of available 135 * This function should set SDL_numjoysticks to the number of available