在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
代码: #[cfg(windows)] extern crate winapi; use std::io::Error; #[cfg(windows)] fn print_message(msg: &str) -> Result<i32, Error> { use std::ffi::OsStr; use std::iter::once; use std::os::windows::ffi::OsStrExt; use std::ptr::null_mut; use winapi::um::winuser::{MB_OK, MessageBoxW}; let wide: Vec<u16> = OsStr::new(msg).encode_wide().chain(once(0)).collect(); let ret = unsafe { MessageBoxW(null_mut(), wide.as_ptr(), wide.as_ptr(), MB_OK) }; if ret == 0 { Err(Error::last_os_error()) } else { Ok(ret) } } #[cfg(not(windows))] fn print_message(msg: &str) -> Result<(), Error> { println!("{}", msg); Ok(()) } fn main() { print_message("Hello, world!你好!").unwrap(); } cargo.toml [target.'cfg(windows)'.dependencies]
参考:https://github.com/retep998/winapi-rs |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论