diff --git a/src/windows.rs b/src/windows.rs index c48ae7f..3b16d72 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -186,10 +186,10 @@ pub enum MinifbError { UnableToCreateWindow, } -fn to_wstring(str: &str) -> *const u16 { +fn to_wstring(str: &str) -> Vec { let mut v: Vec = OsStr::new(str).encode_wide().chain(Some(0).into_iter()).collect(); v.push(0u16); - v.as_ptr() + v } pub struct Window { @@ -214,7 +214,7 @@ impl Window { hCursor: ptr::null_mut(), hbrBackground: ptr::null_mut(), lpszMenuName: ptr::null(), - lpszClassName: class_name, + lpszClassName: class_name.as_ptr(), }; if user32::RegisterClassW(&class) == 0 { @@ -236,9 +236,11 @@ impl Window { rect.right -= rect.left; rect.bottom -= rect.top; + let window_name = to_wstring(name); + let handle = user32::CreateWindowExW(0, - class_name, - to_wstring(name), + class_name.as_ptr(), + window_name.as_ptr(), winapi::WS_OVERLAPPEDWINDOW & !winapi::WS_MAXIMIZEBOX & !winapi::WS_THICKFRAME,