-
Notifications
You must be signed in to change notification settings - Fork 116
bugfix: deviceName garbled in Windows #34 #86
Conversation
WideCharToMultiByte(CP_UTF8, 0, &wstr_tmp[0], (int)wstr_tmp.size(), &str_utf8[0], str_size, NULL, NULL); | ||
|
||
return str_utf8; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you get this code from somewhere like StackOverflow? Let's link it for reference like the following at the top of this function
// via https://stackoverflow.com/q/25410284/796832
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, i wrote it myself, it easy for me, i wrote is before. sometimes i need change the code page from 'gbk' to 'utf8'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a bit too much magic here for me to be comfortable. Just seems like something could be exploitable here with all of this reference and byte copying stuff.
Would definitely prefer a standard approach to tackle this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -89,6 +89,7 @@ _SetupDiGetDeviceRegistryProperty DllSetupDiGetDeviceRegistryProperty; | |||
* Local Helper Functions protoypes | |||
**********************************/ | |||
void UpdateDevice(PDEV_BROADCAST_DEVICEINTERFACE pDevInf, WPARAM wParam, DeviceState_t state); | |||
std::string Utf8Encode(const std::string &str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is std::string
still available after #84 is merged?
Also any of the string stuff we are doing below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, 'std::string' is the c++ standard,mean string with namespace std,
#84 problem is the 'ATL' is not the standard library.
@nononoone Can you give a before after results when you use |
before:
after:
|
V4.3.0 encountered the same bug, I hope to be able to merge this code in the new version,please |
//System default code page to wide character | ||
int wstr_size = MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0); | ||
std::wstring wstr_tmp(wstr_size, 0); | ||
MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, &wstr_tmp[0], wstr_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this is pretty similar to https://stackoverflow.com/a/6693107/796832 so seems good enough to me
//Wide character to Utf8 | ||
int str_size = WideCharToMultiByte(CP_UTF8, 0, &wstr_tmp[0], (int)wstr_tmp.size(), NULL, 0, NULL, NULL); | ||
std::string str_utf8(str_size, 0); | ||
WideCharToMultiByte(CP_UTF8, 0, &wstr_tmp[0], (int)wstr_tmp.size(), &str_utf8[0], str_size, NULL, NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems pretty similar to WideCharToMultiByte so seems good enough to me
Sorry for the delay @nononoone 🥶 This is now shipped in Thanks for the fix ❤️ |
Fix #34
Fix deviceName garbled in Windows