Tag: rust

在DllImport中使用Unicode字符串和用Rust编写的DLL

我试图从C#程序调用Rust编写的DLL。 DLL有两个简单的函数,它们以不同的方式进行stings并打印到控制台。 Rust DLL代码 #![crate_type = “lib”] extern crate libc; use libc::{c_char}; use std::ffi::CStr; #[no_mangle] pub extern fn printc(s: *const c_char){ let c_str : &CStr = unsafe { assert!(!s.is_null()); CStr::from_ptr(s) }; println!(“{:?}”, c_str.to_bytes().len()); //prints “1” if unicode let r_str = std::str::from_utf8(c_str.to_bytes()).unwrap(); println!(“{:?}”, r_str); } #[no_mangle] pub extern fn print2(string: String) { println!(“{:?}”, string) } C#控制台程序代码 […]