Created
May 28, 2015 22:28
-
-
Save Mr-Byte/11ed82e0c94cc6a70e2c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::ffi::OsString; | |
use std::os::windows::ffi::OsStrExt; | |
#[link(name = "user32")] | |
extern "stdcall" { | |
fn MessageBoxW(hwnd: *mut (), message: *const u16, title: *const u16, kind: u32); | |
} | |
struct LPCWSTR { | |
str: Vec<u16> | |
} | |
impl LPCWSTR { | |
fn as_ptr(&self) -> *const u16 { | |
self.str.as_ptr() | |
} | |
} | |
impl<T: Into<OsString>> From<T> for LPCWSTR { | |
fn from(source: T) -> LPCWSTR { | |
LPCWSTR { str: source.into().as_os_str().encode_wide().chain(Some(0).into_iter()).collect::<Vec<_>>() } | |
} | |
} | |
fn message_box<T: Into<LPCWSTR>>(message: T, title: T) { | |
unsafe { MessageBoxW(::std::ptr::null_mut(), message.into().as_ptr(), title.into().as_ptr(), 0) }; | |
} | |
fn main() { | |
message_box("Hello, world!", "Greetings"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment