winapi-rs icon indicating copy to clipboard operation
winapi-rs copied to clipboard

Wrong type of SE_RESTORE_NAME

Open tesuji opened this issue 6 years ago • 3 comments

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.

tesuji avatar Oct 28 '19 08:10 tesuji

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.

retep998 avatar Oct 28 '19 09:10 retep998

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,
];

tesuji avatar Oct 28 '19 09:10 tesuji

Maybe widestring::U16CString::from_str(SE_RESTORE_NAME).unwrap().as_ptr() as LPWSTR

0mcandal0 avatar Sep 24 '20 11:09 0mcandal0