Fixed setting the controller name for the RAWINPUT driver
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c
index 0e1ac01..fbe9a78 100644
--- a/src/joystick/windows/SDL_rawinputjoystick.c
+++ b/src/joystick/windows/SDL_rawinputjoystick.c
@@ -270,8 +270,8 @@ RAWINPUT_AddDevice(HANDLE hDevice)
RID_DEVICE_INFO rdi;
UINT rdi_size = sizeof(rdi);
char dev_name[128];
- const char *name;
UINT name_size = SDL_arraysize(dev_name);
+ const char *name;
SDL_RAWINPUT_Device *curr, *last;
SDL_assert(!RAWINPUT_DeviceFromHandle(hDevice));
@@ -313,18 +313,46 @@ RAWINPUT_AddDevice(HANDLE hDevice)
device->guid.data[15] = 0;
}
- if (!device->name) {
- size_t name_size = (6 + 1 + 6 + 1);
- CHECK(device->name = SDL_callocStructs(char, name_size));
- SDL_snprintf(device->name, name_size, "0x%.4x/0x%.4x", device->vendor_id, device->product_id);
- }
-
CHECK(device->driver = RAWINPUT_GetDeviceDriver(device));
name = device->driver->GetDeviceName(device->vendor_id, device->product_id);
if (name) {
- SDL_free(device->name);
device->name = SDL_strdup(name);
+ } else {
+ char *manufacturer_string = NULL;
+ char *product_string = NULL;
+ HMODULE hHID;
+
+ hHID = LoadLibrary( TEXT( "hid.dll" ) );
+ if (hHID) {
+ typedef BOOLEAN (WINAPI * HidD_GetStringFunc)(HANDLE HidDeviceObject, PVOID Buffer, ULONG BufferLength);
+ HidD_GetStringFunc GetManufacturerString = (HidD_GetStringFunc)GetProcAddress(hHID, "HidD_GetManufacturerString");
+ HidD_GetStringFunc GetProductString = (HidD_GetStringFunc)GetProcAddress(hHID, "HidD_GetProductString");
+ if (GetManufacturerString && GetProductString) {
+ HANDLE hFile = CreateFileA(dev_name, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
+ if (hFile != INVALID_HANDLE_VALUE) {
+ WCHAR string[128];
+
+ if (GetManufacturerString(hFile, string, sizeof(string))) {
+ manufacturer_string = WIN_StringToUTF8(string);
+ }
+ if (GetProductString(hFile, string, sizeof(string))) {
+ product_string = WIN_StringToUTF8(string);
+ }
+ CloseHandle(hFile);
+ }
+ }
+ FreeLibrary(hHID);
+ }
+
+ device->name = SDL_CreateJoystickName(device->vendor_id, device->product_id, manufacturer_string, product_string);
+
+ if (manufacturer_string) {
+ SDL_free(manufacturer_string);
+ }
+ if (product_string) {
+ SDL_free(product_string);
+ }
}
#ifdef DEBUG_RAWINPUT