use std::{ffi::c_void, mem, ptr};
use dlopen::wrapper::WrapperApi;
use super::type_aliases::{char_t, size_t};
#[repr(i32)]
pub enum hostfxr_delegate_type {
hdt_com_activation = 0,
hdt_load_in_memory_assembly = 1,
hdt_winrt_activation = 2,
hdt_com_register = 3,
hdt_com_unregister = 4,
hdt_load_assembly_and_get_function_pointer = 5,
hdt_get_function_pointer = 6,
}
pub type hostfxr_error_writer_fn = unsafe extern "C" fn(message: *const char_t);
pub type hostfxr_handle = *const c_void;
#[repr(C)]
pub struct hostfxr_initialize_parameters {
pub size: size_t,
pub host_path: *const char_t,
pub dotnet_root: *const char_t,
}
impl hostfxr_initialize_parameters {
pub fn with_host_path(host_path: *const char_t) -> hostfxr_initialize_parameters {
hostfxr_initialize_parameters {
size: mem::size_of::<hostfxr_initialize_parameters>(),
host_path,
dotnet_root: ptr::null(),
}
}
pub fn with_dotnet_root(dotnet_root: *const char_t) -> hostfxr_initialize_parameters {
hostfxr_initialize_parameters {
size: mem::size_of::<hostfxr_initialize_parameters>(),
host_path: ptr::null(),
dotnet_root,
}
}
}
#[derive(WrapperApi)]
pub struct HostfxrLib {
hostfxr_main: unsafe extern "C" fn(argc: i32, argv: *const *const char_t) -> i32,
hostfxr_main_startupinfo: unsafe extern "C" fn(
argc: i32,
argv: *const *const char_t,
host_path: *const char_t,
dotnet_root: *const char_t,
app_path: *const char_t,
) -> i32,
hostfxr_main_bundle_startupinfo: unsafe extern "C" fn(
argc: i32,
argv: *const *const char_t,
host_path: *const char_t,
dotnet_root: *const char_t,
app_path: *const char_t,
bundle_header_offset: i64,
) -> i32,
hostfxr_set_error_writer:
unsafe extern "C" fn(error_writer: hostfxr_error_writer_fn) -> hostfxr_error_writer_fn,
hostfxr_initialize_for_dotnet_command_line: unsafe extern "C" fn(
argc: i32,
argv: *const *const char_t,
parameters: *const hostfxr_initialize_parameters,
/*out*/ host_context_handle: *mut hostfxr_handle,
) -> i32,
hostfxr_initialize_for_runtime_config: unsafe extern "C" fn(
runtime_config_path: *const char_t,
parameters: *const hostfxr_initialize_parameters,
/*out*/ host_context_handle: *mut hostfxr_handle,
) -> i32,
hostfxr_get_runtime_property_value: unsafe extern "C" fn(
host_context_handle: hostfxr_handle,
name: *const char_t,
/*out*/ value: *mut *const char_t,
) -> i32,
hostfxr_set_runtime_property_value: unsafe extern "C" fn(
host_context_handle: hostfxr_handle,
name: *const char_t,
value: *const char_t,
) -> i32,
hostfxr_get_runtime_properties: unsafe extern "C" fn(
host_context_handle: hostfxr_handle,
/*inout*/ count: *mut size_t,
/*out*/ keys: *mut *const char_t,
/*out*/ values: *mut *const char_t,
) -> i32,
hostfxr_run_app: unsafe extern "C" fn(host_context_handle: hostfxr_handle) -> i32,
hostfxr_get_runtime_delegate: unsafe extern "C" fn(
host_context_handle: hostfxr_handle,
r#type: hostfxr_delegate_type,
/*out*/ delegate: *mut *const (),
) -> i32,
hostfxr_close: unsafe extern "C" fn(host_context_handle: hostfxr_handle) -> i32,
}
pub type load_assembly_and_get_function_pointer_fn = unsafe extern "system" fn(
assembly_path: *const char_t,
type_name: *const char_t,
method_name: *const char_t,
delegate_type_name: *const char_t,
reserved: *const c_void,
delegate: *mut *const c_void,
) -> i32;
pub type get_function_pointer_fn = unsafe extern "system" fn(
type_name: *const char_t,
method_name: *const char_t,
delegate_type_name: *const char_t,
load_context: *const c_void,
reserved: *const c_void,
delegate: *mut *const c_void,
) -> i32;
pub type component_entry_point_fn = unsafe extern "system" fn(*const c_void, size_t) -> i32;