winapi-rs
winapi-rs copied to clipboard
Wrong type of SE_RESTORE_NAME
I want to use LookupPrivilegeValueW, and its second parameter expects a LPCWSTR.
But when looking at type of SE_RESTORE_NAME, I find it is a &'static str, which cannot
be used in LookupPrivilegeValueW.
Unfortunately Rust does not offer any good way to express wide string literals. Hopefully in 0.4 I'll figure out a good way to do this, potentially a procedural macro. In the meantime you'll have to perform the conversion at runtime.
Thanks. In the meantime I declared two constants:
static SE_RESTORE_NAME: [u16; 19] = [
b'S' as u16, b'e' as _,
b'R' as _, b'e' as _, b's' as _, b't' as _, b'o' as _, b'r' as _, b'e' as _,
b'P' as _, b'r' as _, b'i' as _, b'v' as _, b'i' as _, b'l' as _, b'e' as _, b'g' as _, b'e' as _,
0,
];
static SE_BACKUP_NAME: [u16; 18] = [
b'S' as u16, b'e' as _,
b'B' as _, b'a' as _, b'c' as _, b'k' as _, b'u' as _, b'p' as _,
b'P' as _, b'r' as _, b'i' as _, b'v' as _, b'i' as _, b'l' as _, b'e' as _, b'g' as _, b'e' as _,
0,
];
Maybe
widestring::U16CString::from_str(SE_RESTORE_NAME).unwrap().as_ptr() as LPWSTR