Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
takubokudori committed Jul 24, 2021
1 parent 5748210 commit 18171bc
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 9 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,23 @@ windy-macros = "0.1.1"
use windy::WStr;
use windy_macros::wstr;

#[allow(non_snake_case)]
#[link(name = "user32")]
extern "system" {
pub fn MessageBoxW(
hWnd: *mut c_void,
lpText: *const u16,
lpCaption: *const u16,
uType: u32,
) -> i32;
}

fn main() {
let s: &WStr = wstr!("test");
let text: &WStr = wstr!("World");
let caption: &WStr = wstr!("CaptionW");
unsafe {
MessageBoxW(0 as _, text.as_ptr(), caption.as_ptr(), 0);
}
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use windy::*;
#[cfg(feature = "std")]
extern "system" {
fn GetEnvironmentVariableA(
lpName: *const u8,
lpName: *const i8,
lpBuffer: *mut u8,
nSize: u32,
) -> u32;
Expand Down
55 changes: 55 additions & 0 deletions examples/message_box.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright takubokudori.
// This source code is licensed under the MIT or Apache-2.0 license.
use core::ffi::c_void;
#[cfg(feature = "std")]
use windy::*;

#[allow(non_snake_case)]
#[cfg(feature = "std")]
#[link(name = "user32")]
extern "system" {
pub fn MessageBoxA(
hWnd: *mut c_void,
lpText: *const i8,
lpCaption: *const i8,
uType: u32,
) -> i32;

pub fn MessageBoxW(
hWnd: *mut c_void,
lpText: *const u16,
lpCaption: *const u16,
uType: u32,
) -> i32;
}

#[cfg(feature = "std")]
fn message_box_a() {
let text = AString::from_str("Hello").unwrap();
let caption = AString::from_str("CaptionA").unwrap();
unsafe {
MessageBoxA(0 as _, text.as_ptr(), caption.as_ptr(), 0);
}
}

#[cfg(feature = "std")]
fn message_box_w() {
let text = WString::from_str("World").unwrap();
let caption = WString::from_str("CaptionW").unwrap();
unsafe {
MessageBoxW(0 as _, text.as_ptr(), caption.as_ptr(), 0);
}
}

#[cfg(feature = "std")]
fn main() {
println!("*****message_box_a*****");
message_box_a();
println!("*****message_box_w*****");
message_box_w();
}

#[cfg(not(feature = "std"))]
fn main() {
panic!("Use std feature!");
}
7 changes: 0 additions & 7 deletions src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ impl WString {
}
}

#[inline]
pub fn as_ptr(&self) -> *const u16 { self.inner.as_ptr() }

/// Returns the length of bytes.
#[inline]
pub fn len(&self) -> usize { self.inner.len() }
Expand Down Expand Up @@ -367,10 +364,6 @@ impl AString {
}
}

/// Returns the `*const u8` pointer.
#[inline]
pub fn as_ptr(&self) -> *const u8 { self.inner.as_ptr() }

/// Returns the length of bytes.
#[inline]
pub fn len(&self) -> usize { self.inner.len() }
Expand Down

0 comments on commit 18171bc

Please sign in to comment.