rust/src/test/ui/x86stdcall2.rs

34 lines
800 B
Rust
Raw Normal View History

// run-pass
#![allow(non_camel_case_types)]
2015-09-17 04:03:27 -05:00
pub type HANDLE = usize;
2013-03-06 21:09:17 -06:00
pub type DWORD = u32;
pub type SIZE_T = u32;
pub type LPVOID = usize;
2013-03-06 21:09:17 -06:00
pub type BOOL = u8;
2013-11-10 16:57:53 -06:00
#[cfg(windows)]
mod kernel32 {
2013-03-06 21:09:17 -06:00
use super::{HANDLE, DWORD, SIZE_T, LPVOID, BOOL};
2013-11-10 16:57:53 -06:00
extern "system" {
pub fn GetProcessHeap() -> HANDLE;
pub fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T)
-> LPVOID;
pub fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) -> BOOL;
}
}
2013-11-10 16:57:53 -06:00
#[cfg(windows)]
pub fn main() {
let heap = unsafe { kernel32::GetProcessHeap() };
let mem = unsafe { kernel32::HeapAlloc(heap, 0, 100) };
assert!(mem != 0);
let res = unsafe { kernel32::HeapFree(heap, 0, mem) };
assert!(res != 0);
}
2013-11-10 16:57:53 -06:00
#[cfg(not(windows))]
pub fn main() { }