MadLittleMods / node-usb-detection

List USB devices in system and detect changes on them.
MIT License
371 stars 114 forks source link

Chinese(and other non-English) symbols are not displayed #176

Open ilyaryabchinski opened 1 year ago

ilyaryabchinski commented 1 year ago

Hi! Huge thanks for your work on this great library!

Recently, I've been playing around with it in my Electron Project and found out that non-English symbols are not displayed correctly. I've seen similar issue and the corresponding PR that fixes it, but it seems like it's still the case.

Expected: device manager

Actual behavior: usb-detection

My Setup: OS: Win10 Nodejs 16.10.0 usb-detection 4.14.1

How to reproduce:

  1. rename a device on your machine adding some non-English symbols as written in the article
  2. Try to detect devices using find method
ilyaryabchinski commented 1 year ago

Hi! I am trying to debug the issue and dive a bit deeper. I haven't touched C++ since my uni classes and don't have a production experience with it. But what I've found out so far is that the symbols get corrupted even before we call the Utf8Encode function. So my guess is that it could be something wrong with the DllSetupDiGetDeviceRegistryProperty function which is imported from the dll. Could you please help me to investigate further and fix this?

image image

Julusian commented 1 year ago

As far as I'm concerned, this library is EOL https://github.com/MadLittleMods/node-usb-detection/pull/169.

Have you tried https://github.com/node-usb/node-usb? Maybe it will handle this better?

If you want to try and fix this, I expect its a problem of this using the SetupDiGetDeviceRegistryPropertyA (ansi) method from the DLL instead of the SetupDiGetDeviceRegistryPropertyW (unicode) version. Maybe it will work if you switch which ones it is importing and fix up any resulting type errors?

ilyaryabchinski commented 1 year ago

Thanks @Julusian! I've just tried using SetupDiGetDeviceRegistryPropertyW and now it prints only first letters, I guess it has something to do with buf sizes 🤔 image

ilyaryabchinski commented 1 year ago

it doesn't work 😢 I tried to fix and change all the types to WCHARand wstring but somehow broke the logic