RustでMessageBoxを表示する

下記の手順でRustでMessageBoxを表示することができます。 Rustをインストールする。 Rustのはじめかた 参照 コマンドプロンプトでcargo new --bin MessageBoxを実行する。 MessageBoxディレクトリに移動する。 Cargo.tomlを開き、下記のように修正する。 [package] name = "hello_world" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] winapi = "0.2.7" user32-sys = "0.2.0" src\main.rsを開き、下記のように修正する。 externcrateuser32;externcratewinapi;usestd::ffi::CString;useuser32::MessageBoxA;usewinapi::winuser::{MB_OK,MB_ICONINFORMATION};fn main(){letlp_text=CString::new("Hello, world!").unwrap();letlp_caption=CString::new("MessageBox Example").unwrap();unsafe{MessageBoxA(std::ptr::null_mut(),lp_text.as_ptr(),lp_caption.as_ptr(),MB_OK|MB_ICONINFORMATION);}} コマンドプロンプトでcargo runを実行する。 リリースのビルドをする場合はcargo build --releaseを実行する。 参考 Hello World MesssageBox example in Rust