in Education by
I write a tool, It can get device id through the dll, and copy the id to clipboard. extern crate clipboard; use clipboard::ClipboardProvider; use clipboard::ClipboardContext; extern crate libloading; use libloading::{Library, Symbol}; use std::ffi::CStr; use std::str; type GetHylinkDeviceId = unsafe fn() -> *const i8; fn copy_to_clipboard(x3id: String) { let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap(); println!("{:?}", ctx.get_contents()); ctx.set_contents(x3id); } fn get_x3id() -> String { let library_path = "PcInfo.dll"; println!("Loading add() from {:?}", library_path); let lib = Library::new(library_path).unwrap(); let x3id = unsafe { let func: Symbol = lib.get(b"GetHylinkDeviceId").unwrap(); let c_buf: *const i8 = func(); let c_str: &CStr = unsafe { CStr::from_ptr(c_buf) }; let str_slice: &str = c_str.to_str().unwrap(); let str_buf: String = str_slice.to_owned(); str_buf }; x3id } fn main() { let x3id: String = get_x3id(); println!("{:?}", x3id); copy_to_clipboard(x3id) } It works well, I use cargo build it, auto generate an executable. I need to put dll file and exe in the same dir when run it. I want to know if there is anyway to pack dll file into the exe by cargo? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I known how to do, code example: extern crate clipboard; use clipboard::ClipboardProvider; use clipboard::ClipboardContext; extern crate libloading; use libloading::{Library, Symbol}; use std::io::prelude::*; use std::path::Path; use std::ffi::CStr; use std::fs::File; use std::str; use std::io; type GetHylinkDeviceId = unsafe fn() -> *const i8; const LIBRARY_PATH: &'static str = "PcInfo.dll"; const HYLINK_DLL: &'static [u8] = include_bytes!("PcInfo.dll"); fn generate_hylink_dll(filename: &str, buf: &[u8]) -> io::Result<()> { let mut f = try!(File::create(filename)); try!(f.write(&buf)); Ok(()) } fn copy_to_clipboard(x3id: String) { let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap(); println!("{:?}", ctx.get_contents()); ctx.set_contents(x3id).unwrap(); } fn get_x3id() -> String { if !Path::new(LIBRARY_PATH).exists() { match generate_hylink_dll(LIBRARY_PATH, HYLINK_DLL) { Ok(s) => println!("Generate hylink dll file success {:?}", s), Err(r) => println!("Generate hylink dll file failed {:?}", r), } } // load lib let lib = Library::new(LIBRARY_PATH).unwrap(); println!("{:?}", lib); // call let x3id = unsafe { let func: Symbol = lib.get(b"GetHylinkDeviceId").unwrap(); let c_buf: *const i8 = func(); let c_str: &CStr = CStr::from_ptr(c_buf); let str_slice: &str = c_str.to_str().unwrap(); let str_buf: String = str_slice.to_owned(); str_buf }; x3id } fn main() { let x3id: String = get_x3id(); println!("{:?}", x3id); copy_to_clipboard(x3id) }

Related questions

0 votes
    I'm working on a C# program that uses iTextSharp.dll and WebCam_Capture.dll. When I build the program, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I am not too familiar with .NET desktop applications (using Visual Studio 2005). Is it possible to have ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I am not too familiar with .NET desktop applications (using Visual Studio 2005). Is it possible to have ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I am not too familiar with .NET desktop applications (using Visual Studio 2005). Is it possible to have ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I am not too familiar with .NET desktop applications (using Visual Studio 2005). Is it possible to have ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    recently i'm working on some project with arm but no OS in it. Now when i compile it, i must ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I am trying to retrieve a particular file from multiple FTP servers. those server details are stored in ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I want to execute a certain batch file and redirect its console output to a text control in visual c ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I want to execute a certain batch file and redirect its console output to a text control in visual c ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I got some question regarding the shared and static libraries.So let me tell you what i did is, I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    After writing a basic LFSR-based stream cipher encryption module in C, I tried it on usual text files, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
0 votes
    I'm working in an FFI library and have encountered this pattern quite a few times that I don't ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I had a hard time finding any useful information about the Rust debugging story on iOS/Android. I guess ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    Which of the following is useful way to put text, code, data, output all in one document? (a) ... questions and answers pdf, Data Science interview questions for beginners...
asked Oct 31, 2021 in Education by JackTerrance
...