スキップしてメイン コンテンツに移動

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

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();

拙作 wstr.rs を使うと楽に変換できる。
コンパイル時定数文字列を UTF-16 に変換するなら windows::core::w! マクロでよい。

コメント