diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..905172f --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,32 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "clego" +version = "0.1.0" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 761d36a..c25708d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,5 @@ [workspace] members = [ - "webapp", - "clego", - "tauri", + "clego" ] resolver = "2" diff --git a/clego/Cargo.toml b/clego/Cargo.toml index 495a5a2..a4fc835 100644 --- a/clego/Cargo.toml +++ b/clego/Cargo.toml @@ -4,3 +4,4 @@ version = "0.1.0" edition = "2021" [dependencies] +winapi = { version = "0.3.8", features = ["winuser","libloaderapi"] } diff --git a/clego/src/SV_DLL_Win.rs b/clego/src/SV_DLL_Win.rs new file mode 100644 index 0000000..ab96560 --- /dev/null +++ b/clego/src/SV_DLL_Win.rs @@ -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 +} +} \ No newline at end of file diff --git a/clego/src/main.rs b/clego/src/main.rs index e7a11a9..1224355 100644 --- a/clego/src/main.rs +++ b/clego/src/main.rs @@ -1,3 +1,5 @@ +mod SV_DLL_Win; + fn main() { println!("Hello, world!"); }