Macro netcorehost::cast_managed_fn [−][src]
macro_rules! cast_managed_fn {
($fn_ptr : expr, $($fn_ty : tt) *) => { ... };
($fn_ptr : expr, unsafe $($fn_ty : tt) *) => { ... };
($fn_ptr : expr, extern "system" $($fn_ty : tt) *) => { ... };
($fn_ptr : expr, unsafe extern "system" $($fn_ty : tt) *) => { ... };
}
Expand description
Macro for casting a MethodWithUnknownSignature
to a concrete function signature with the correct calling convention.
Example
Type annotations are not needed and only for clarity.
// Get a pointer to the managed "UnmanagedHello" method.
let hello: MethodWithUnknownSignature = fn_loader.get_function_pointer_for_unmanaged_callers_only_method(
pdcstr!("Test.Program, Test"),
pdcstr!("UnmanagedHello"),
).unwrap();
// Cast the unknown function pointer to the concrete function type with the correct signature and calling convention.
let hello: extern "system" fn() = unsafe { cast_managed_fn!(hello, fn()) };