Created
January 13, 2022 15:25
-
-
Save pratikpc/346857c7efe938abb15cfb34afcb5ff0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn stringify_buffer(buffer: &IBuffer) -> windows::core::Result<String> { | |
let buffer_length = buffer.Length()?; | |
let reader: DataReader = DataReader::FromBuffer(buffer)?; | |
// Create an array of the correct size | |
let mut temp: Vec<u8> = vec![0; buffer_length as usize]; | |
// Read bytes into the array | |
// This now contains our buffer | |
reader.ReadBytes(temp.as_mut())?; | |
let string = String::from_utf8(temp).unwrap(); | |
Ok(string) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment