使用旧的Rust 2015
0.1.0-alpha1 |
|
---|
#22 in #wide
8KB
60 代码行
在Windows FFI之间转换安全类型和原始 u16
指针。
最初来自 wio-rs b895086
示例
创建一个空终止的宽字符串
use std::ffi::OsString;
use std::ptr;
use lpwstr::ToWide; // for to_wide_null
#
let class_name = OsString::from("MozillaWindowClass").to_wide_null();
unsafe {
let window = FindWindowW(class_name.as_ptr(), ptr::null_mut());
}
读取一个空终止的宽字符串
use std::ffi::OsString;
use std::mem;
use lpwstr::FromWide; // for from_wide_ptr_null
#
let computer_name;
unsafe {
let mut buffer = vec![mem::uninitialized(); MAX_COMPUTERNAME_LENGTH + 1];
GetComputerNameW(buffer.as_mut_ptr(), &mut (buffer.len() as u32));
computer_name = OsString::from_wide_ptr_null(buffer.as_ptr());
}
assert_eq!(computer_name.to_string_lossy(), "COMPUTRON");