From 2f5503d115da5b42b6abf42939f49385b7e24d03 Mon Sep 17 00:00:00 2001 From: Daniel Collin Date: Fri, 11 Dec 2015 09:46:10 +0100 Subject: [PATCH] Make sure to keep wchars alive --- src/windows.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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,