serialport-rs icon indicating copy to clipboard operation
serialport-rs copied to clipboard

Windows unicode (`_W`) api for all Win32 functions

Open Crzyrndm opened this issue 2 years ago • 2 comments

Based on #84. The new changes

We should probably be using the unicode (SetupDiClassGuidsFromNameW) or automatic (SetupDiClassGuidsFromName) versions of all windows functions. Otherwise devices from non-english speaking manufacturers or users in different localities may run into issues getting correct device names and information.

See: https://learn.microsoft.com/en-us/windows/win32/intl/unicode-in-the-windows-api

Originally posted by @mlsvrts in https://github.com/serialport/serialport-rs/pull/84#discussion_r1148426835

In that case, I think updating these in another PR instead of putting additional changes here makes more sense to me!

Originally posted by @mlsvrts in https://github.com/serialport/serialport-rs/pull/84#discussion_r1148673211

Crzyrndm avatar Mar 27 '23 11:03 Crzyrndm

I believe this would be a good change, since using the wide function are generally recommended and would make their usage consistent throughout the codebase. Just needs to be rebased.

RossSmyth avatar Jul 02 '24 19:07 RossSmyth

I believe this would be a good change, since using the wide function are generally recommended and would make their usage consistent throughout the codebase. Just needs to be rebased.

This has been (squashed and) rebased. I lack the hardware to test this that I had last year though :/

Crzyrndm avatar Jul 02 '24 23:07 Crzyrndm

Thank you very much for your PR @Crzyrndm and for the recent attention @RossSmyth!

I lack the hardware to test this that I had last year though :/

Did you had a piece of hardware returning actual UTF-16 codepoints?

sirhcel avatar Jul 28 '24 22:07 sirhcel

I recommended this change since we saw issues with reporting device serial numbers as fixed by: https://github.com/serialport/serialport-rs/pull/63

It's kind of a case of "if you can do, then someone will do it."

But I doubt it would be a common issue.

mlsvrts avatar Jul 28 '24 23:07 mlsvrts

If desired I can give this a more thorough review later in the week.

The API provided by the windows crate does't seem to bring more ergonomics witch respect to this buffer handling here.

If it is desired to move to the Windows crate I would recommend that windows-sys is used and not windows-rs ~~because my work computer's anti-virus kills compilation of windows-rs~~ because it is pretty big. Which I do think would be a worthwhile endeavor at some point as winapi is dead.

wrt to buffer handling, the wide literal macro could be copied for now to try and reduce allocation if that is important.

RossSmyth avatar Jul 30 '24 01:07 RossSmyth

Rebased to resolve conflict with main branch.

sirhcel avatar Jul 31 '24 14:07 sirhcel

Thank you for pushing forward with this PR @Crzyrndm! See my replies to https://github.com/serialport/serialport-rs/pull/89#pullrequestreview-2204667053. Resolved the merge conflict with main and added some more cleanup. A local test with list_ports looks good.

If desired I can give this a more thorough review later in the week.

This would be great @RossSmyth.

sirhcel avatar Jul 31 '24 15:07 sirhcel