Created
September 14, 2019 07:30
-
-
Save LuoZijun/b363d1d4e6795d37ed58178c3da19f88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(non_camel_case_types, non_snake_case, unused_variables, unused_macros)] | |
// #[macro_use] | |
// #[path = "src/macros.rs"] | |
// mod macros; | |
macro_rules! FN { | |
(stdcall $func:ident($($t:ty,)*) -> $ret:ty) => ( | |
pub type $func = Option<unsafe extern "system" fn($($t,)*) -> $ret>; | |
); | |
(stdcall $func:ident($($p:ident: $t:ty,)*) -> $ret:ty) => ( | |
pub type $func = Option<unsafe extern "system" fn($($p: $t,)*) -> $ret>; | |
); | |
(cdecl $func:ident($($t:ty,)*) -> $ret:ty) => ( | |
pub type $func = Option<unsafe extern "C" fn($($t,)*) -> $ret>; | |
); | |
(cdecl $func:ident($($p:ident: $t:ty,)*) -> $ret:ty) => ( | |
pub type $func = Option<unsafe extern "C" fn($($p: $t,)*) -> $ret>; | |
); | |
} | |
pub enum c_void { } | |
pub type c_uchar = u8; | |
pub type c_ulong = u64; | |
pub type DWORD = c_ulong; | |
pub type UCHAR = c_uchar; | |
pub type BOOLEAN = UCHAR; | |
pub type USHORT = u16; | |
pub type ADDRESS_FAMILY = USHORT; | |
pub type PVOID = *mut c_void; | |
pub type HANDLE = *mut c_void; | |
pub type NETIO_STATUS = DWORD; | |
pub type NETIOAPI_API = NETIO_STATUS; | |
// type PIPFORWARD_CHANGE_CALLBACK = Option<unsafe extern "system" fn(CallerContext: PVOID)>; | |
FN!{stdcall PIPFORWARD_CHANGE_CALLBACK( | |
CallerContext: PVOID, | |
// Row: PMIB_IPFORWARD_ROW2, | |
// NotificationType: MIB_NOTIFICATION_TYPE, | |
) -> ()} | |
extern "system" { | |
pub fn NotifyRouteChange2( | |
AddressFamily: ADDRESS_FAMILY, | |
Callback: PIPFORWARD_CHANGE_CALLBACK, | |
// CallerContext: PVOID, | |
// InitialNotification: BOOLEAN, | |
// NotificationHandle: *mut HANDLE, | |
) -> NETIOAPI_API; | |
} | |
pub unsafe extern "system" fn callback_fn(CallerContext: PVOID) { | |
println!("ok."); | |
} | |
pub fn foo() { | |
let callback: PIPFORWARD_CHANGE_CALLBACK = Some(callback_fn); | |
unsafe { | |
NotifyRouteChange2(0, callback ); | |
} | |
} | |
fn main() { | |
// foo(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment