Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ANSI Windows API to fix improper UTF-16 use #13

Merged
merged 2 commits into from
Jan 24, 2024

Conversation

lachlanm-git
Copy link
Contributor

Fixes #12

Use the ANSI "A" style API over wide "W" style. Fix for:

  • RegQueryValueEx: affected .port_name, .system_location
  • SetupDiGetDeviceRegistryProperty: affected .friendly_name, .description, .manufacturer

Also, able to remove some @ptrCast() and @as() by cleaning up API function definitions to use [*] instead of *.

switch RegQueryValueEx from "W" wide to "A" ANSI API.

fixed utf16 being used instead of intended utf8
`SetupDiGetDeviceRegistryProperty` changed to from wide to ANSI style API.

Additionally, remove some `@ptrCast` and `@as` by cleaning up API function definitions.
@ikskuh
Copy link
Collaborator

ikskuh commented Jan 23, 2024

Have you verified this works?

@lachlanm-git
Copy link
Contributor Author

Have you verified this works?

Yes, verified with zig 0.11.0 on Windows 10.

  1. "serial-list-info.exe" still prints OK.
    Previously I didn't notice this since I was just looking at the printed output. It looked OK as every 2nd byte of the slice was a '\0' character so wasn't observed.

  2. Here is a quick verification script I've run that works for me: https://gist.github.com/lachlanm-git/8a852c42b133ba24523751e9c708c242
    It prints the number of characters which now match what I think we'd expect (previously it was twice as big).
    It then actually uses the .system_location to echo on an FTDI.

@ikskuh ikskuh merged commit ff5179d into ZigEmbeddedGroup:master Jan 24, 2024
@lachlanm-git lachlanm-git deleted the fix-12-utf16-into-utf8 branch October 13, 2024 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reading UTF-16 into a UTF-8 buffer
2 participants