我编写了一个工具,它可以通过dll获取设备ID,并将id复制到剪贴板。
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<GetHylinkDeviceId> = 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)
}
效果很好,我使用货物构建它,自动生成可执行文件。我需要在运行它时将dll文件和exe放在同一个目录中。
我想知道是否有货物将dll文件打包到exe文件中?