I'm calling a c function which returns a memory address of a char. I've stored the memory address in a rust c_void variable. How can I get the char stored at the memory address?
To clarify the rust c_void variable holds a memory address for example: 0x123456
The c function expects a c_void. I just tried dereference it, it doesn't work.
Here is some of my code:
// Pretty sure this is incorrect, but works for now. I need to create a variable that can store a memory address.
let mut r = unsafe { malloc(4) as *const c_char };
call_c_func(r as *mut c_void);
let c = unsafe { *r };
println!("{:?}", c);
// Console output is
-44
What value are you expecting? 51 is ASCII '3', if that helps.
The last parameter PUINT should be a pointer too, I guess unsigned int* -> *mut u32. Or use usize with 0 if you want to quickly approximate NULL.
I think your malloc is wasted here. VerQueryValue says it returns a pointer info the buffer you provide in the first parameter. Since this result is an out parameter, it doesn't matter what it points to going in, and should probably just start NULL.