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

Request for implementations of From/Into to convert between PWSTR/PCWSTR and String/&str #645

Closed
wravery opened this issue Mar 25, 2021 · 1 comment

Comments

@wravery
Copy link
Collaborator

wravery commented Mar 25, 2021

Most COM and Win32 apps #define UNICODE and prefer the W APIs which take PWSTR or PCWSTR. Rust has built-in String::encode_utf16 and String::from_utf16 methods, it would be great if PWSTR and PCWSTR could implement From/Into traits to encapsulate that.

It's tricky since it needs extra storage, but maybe the tuple could be extended with an , Option<Vec<u16>> to hold the extra allocation, and the .0 could point to that when this is used.

@kennykerr
Copy link
Collaborator

This already works for input parameters. You can pass a string to any function expecting a PSTR or PWSTR and it will create the null-terminated string of the appropriate encoding. For example, the following just works today:

 SetWindowTextA(handle, "Hello A");
 SetWindowTextW(handle, "Hello W");

I'm still working on making it easier for PWSTR and PSTR output parameters. That is tracked by #595.

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

No branches or pull requests

2 participants