SSV_INITLIB2 SSV_LireCartePS
This commit is contained in:
@ -4,3 +4,4 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
winapi = { version = "0.3.8", features = ["winuser","libloaderapi"] }
|
||||
|
63
clego/src/SV_DLL_Win.rs
Normal file
63
clego/src/SV_DLL_Win.rs
Normal file
@ -0,0 +1,63 @@
|
||||
extern crate winapi;
|
||||
|
||||
use winapi::um::libloaderapi::{ LoadLibraryA, GetProcAddress};
|
||||
|
||||
use std::ffi::{CString , c_void};
|
||||
|
||||
// Définissez une énumération pour les deux types possibles
|
||||
|
||||
|
||||
//récupérer le handle sur la library
|
||||
fn load_library(dll_path: &str)->*mut winapi::shared::minwindef::HINSTANCE__ {
|
||||
let dll_path_c = CString::new(dll_path).expect("Chemin de DLL invalide");
|
||||
unsafe {
|
||||
let h_module = LoadLibraryA(dll_path_c.as_ptr());
|
||||
h_module
|
||||
}
|
||||
}
|
||||
|
||||
//SSV_INITLIB2
|
||||
fn ssv_initlib2(dll_handle:*mut winapi::shared::minwindef::HINSTANCE__ , sesamini_path :String)->i32{
|
||||
// Résolution d'une fonction exportée ("SSV_InitLIB2")
|
||||
let symbol_name = CString::new("SSV_InitLIB2").expect("Nom de symbole invalide");
|
||||
unsafe {
|
||||
let function_ptr = GetProcAddress(dll_handle, symbol_name.as_ptr());
|
||||
|
||||
if function_ptr.is_null() { panic!("Échec de la résolution du symbole");}
|
||||
|
||||
// Convertir le pointeur en une fonction Rust
|
||||
type MyFunctionType = unsafe extern "C" fn(*const i8) -> i32;
|
||||
let my_function: MyFunctionType = std::mem::transmute(function_ptr);
|
||||
|
||||
let result = my_function(
|
||||
CString::new(sesamini_path).unwrap().as_ptr()
|
||||
);
|
||||
result
|
||||
}}
|
||||
|
||||
//SSV_LireCartePS
|
||||
fn ssv_lirecarteps(dll_handle:*mut winapi::shared::minwindef::HINSTANCE__ , NomRessourcePS :String , NomRessourceLecteur :String , CodePorteurPS :String,
|
||||
mut ZDonneesSortie: *mut c_void , mut TTailleDonneesSortie: usize)->i32{
|
||||
// Résolution d'une fonction exportée ("SSV_LireCartePS")
|
||||
let symbol_name = CString::new("SSV_LireCartePS").expect("Nom de symbole invalide");
|
||||
unsafe {
|
||||
let function_ptr = GetProcAddress(dll_handle, symbol_name.as_ptr());
|
||||
if function_ptr.is_null() {
|
||||
panic!("Échec de la résolution du symbole");
|
||||
}
|
||||
|
||||
// Convertir le pointeur en une fonction Rust
|
||||
type MyFunctionType = unsafe extern "C" fn(*const i8, *const i8, *const i8, *mut *mut c_void, *mut usize) -> i32;
|
||||
let my_function: MyFunctionType = std::mem::transmute(function_ptr);
|
||||
|
||||
// appel de la fonction
|
||||
ZDonneesSortie= std::ptr::null_mut();
|
||||
TTailleDonneesSortie=0;
|
||||
let result = my_function(CString::new(NomRessourcePS).unwrap().as_ptr(),
|
||||
CString::new(NomRessourceLecteur).unwrap().as_ptr(),
|
||||
CString::new(CodePorteurPS).unwrap().as_ptr(),
|
||||
&mut ZDonneesSortie,
|
||||
&mut TTailleDonneesSortie);
|
||||
result
|
||||
}
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
mod SV_DLL_Win;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
|
Reference in New Issue
Block a user