From a87bd8197cffb572d35f6efa2d75a4a9d35e0c71 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Wed, 31 Jul 2024 22:41:28 -0500 Subject: [PATCH] Fix wstring to string conversion warning in EVGAMouseController.cpp --- .../EVGAMouseController.cpp | 31 +++++++++++-------- .../EVGAMouseController/EVGAMouseController.h | 1 - 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Controllers/EVGAUSBController/EVGAMouseController/EVGAMouseController.cpp b/Controllers/EVGAUSBController/EVGAMouseController/EVGAMouseController.cpp index ed1c0115..c8cc777d 100644 --- a/Controllers/EVGAUSBController/EVGAMouseController/EVGAMouseController.cpp +++ b/Controllers/EVGAUSBController/EVGAMouseController/EVGAMouseController.cpp @@ -15,6 +15,7 @@ #include #include "EVGAMouseController.h" #include "LogManager.h" +#include "StringUtils.h" #define HID_MAX_STR 255 #define EVGA_PERIPHERAL_LED_SOURCE_OF_TRUTH EVGA_PERIPHERAL_LED_LOGO @@ -51,20 +52,16 @@ EVGAMouseController::EVGAMouseController(hid_device* dev_handle, char *_path, in location = _path; this->connection_type = connection_type; - const int szTemp = HID_MAX_STR; - wchar_t tmpName[szTemp]; + /*---------------------------------------------------------*\ + | Get device name from HID manufacturer and product strings | + \*---------------------------------------------------------*/ + wchar_t name_string[HID_MAX_STR]; - hid_get_manufacturer_string(dev, tmpName, szTemp); - std::wstring wName = std::wstring(tmpName); - device_name = std::string(wName.begin(), wName.end()); + hid_get_manufacturer_string(dev, name_string, HID_MAX_STR); + device_name = StringUtils::wstring_to_string(name_string); - hid_get_product_string(dev, tmpName, szTemp); - wName = std::wstring(tmpName); - device_name.append(" ").append(std::string(wName.begin(), wName.end())); - - hid_get_indexed_string(dev, 2, tmpName, szTemp); - wName = std::wstring(tmpName); - serial = std::string(wName.begin(), wName.end()); + hid_get_product_string(dev, name_string, HID_MAX_STR); + device_name.append(" ").append(StringUtils::wstring_to_string(name_string)); led_states.resize(EVGA_PERIPHERAL_LED_COUNT); for(EVGAMouseControllerDeviceState &led_state : led_states) @@ -89,7 +86,15 @@ std::string EVGAMouseController::GetDeviceName() std::string EVGAMouseController::GetSerial() { - return serial; + wchar_t serial_string[HID_MAX_STR]; + int ret = hid_get_indexed_string(dev, 2, serial_string, HID_MAX_STR); + + if(ret != 0) + { + return(""); + } + + return(StringUtils::wstring_to_string(serial_string)); } std::string EVGAMouseController::GetLocation() diff --git a/Controllers/EVGAUSBController/EVGAMouseController/EVGAMouseController.h b/Controllers/EVGAUSBController/EVGAMouseController/EVGAMouseController.h index 1c1bdeb6..83b7d846 100644 --- a/Controllers/EVGAUSBController/EVGAMouseController/EVGAMouseController.h +++ b/Controllers/EVGAUSBController/EVGAMouseController/EVGAMouseController.h @@ -198,7 +198,6 @@ private: bool IsResponseNotReadyPacket(unsigned char *buffer); std::string device_name; - std::string serial; std::string location; hid_device* dev;