Skip to content

Instantly share code, notes, and snippets.

@henninglive
Last active December 19, 2019 23:10
Show Gist options
  • Select an option

  • Save henninglive/c96e72fb3ef2e46b4dee53127378b731 to your computer and use it in GitHub Desktop.

Select an option

Save henninglive/c96e72fb3ef2e46b4dee53127378b731 to your computer and use it in GitHub Desktop.
[package]
name = "load-library-test"
version = "0.1.0"
authors = ["Henning Ottesen <henning@live.no>"]
[dependencies]
winapi = "0.2"
kernel32-sys = "0.2.2"
extern crate winapi;
extern crate kernel32;
use winapi::winnt::LPCSTR;
use winapi::{c_int, c_void};
#[derive(Debug)]
struct MSysError(&'static str);
unsafe extern "system" fn signal_handler(_: c_int) {
}
const SIG_DFL: isize = 0;
const SIG_IGN: isize = 1;
const SIG_ERR: isize = -1;
const SIGHUP: c_int = 1;
const SIGINT: c_int = 2;
unsafe fn msys_signal() -> Result<unsafe extern "system" fn(c_int, unsafe extern "system" fn(c_int)) -> *const c_void, MSysError> {
let lib = kernel32::LoadLibraryA("msys-2.0.dll\0".as_ptr() as LPCSTR);
if lib.is_null() {
return Err(MSysError("LoadLibrary failed, msys-2.0.dll"));
}
let signal = kernel32::GetProcAddress(lib, "signal\0".as_ptr() as LPCSTR);
if signal.is_null() {
return Err(MSysError("GetProcAddress failed, signal(), msys-2.0.dll"));
}v
Ok(::std::mem::transmute(signal))
}
fn main() {
unsafe {
let signal = msys_signal().unwrap();
let r = signal(SIGINT, ::std::mem::transmute(SIG_IGN));
println!("{:?}", r);
}
unsafe {
let signal = msys_signal().unwrap();
let r = signal(SIGHUP, ::std::mem::transmute(SIG_IGN));
println!("{:?}", r);
}
std::thread::sleep(std::time::Duration::from_secs(10));
println!("Hello, world!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment