1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Rust で &str や String から UTF-16/PCWSTR/PWSTR を作る方法

Last updated at Posted at 2025-01-08

https://github.com/microsoft/windows-rs/issues/973#issuecomment-1346528303
これが唯一の正解

str.encode_utf16().chain(Some(0)).collect(); // 動かない

とか

OsStr::new(str).encode_wide().chain(Some(0).into_iter()).collect::<Vec<_>>() // 動かない

と書いてる人が多く見受けられるけど、どれも動かない。

UTF-16 にしたい場合

HSTRING::from(source).to_vec() // --> Vec<u16> これは動く

でよい。

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?