Skip to content

Instantly share code, notes, and snippets.

@bplaat
Created February 1, 2023 13:15
Show Gist options
  • Save bplaat/3ef892f94f74e80e606f79cdbe55311d to your computer and use it in GitHub Desktop.
Save bplaat/3ef892f94f74e80e606f79cdbe55311d to your computer and use it in GitHub Desktop.
A simple rust program without stdlib that links to the win32 libs
[package]
name = "bassietest"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"
[dependencies]
#![no_std]
#![no_main]
use core::panic::PanicInfo;
// Bindings
#[link(name = "kernel32")]
extern "C" {
fn ExitProcess(uExitCode: u32) -> !;
}
const HWND_DESKTOP: u64 = 0;
const MB_OK: u32 = 0;
#[link(name = "user32")]
extern "C" {
fn MessageBoxA(hWnd: u64, lpText: *const u8, lpCaption: *const u8, uType: u32) -> i32;
}
// Main
#[no_mangle]
pub extern "C" fn _start() -> ! {
unsafe {
MessageBoxA(HWND_DESKTOP, "World!\0".as_ptr(), "Hello\0".as_ptr(), MB_OK);
ExitProcess(0);
}
}
// Panic handler
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment