(Rust question) C++ double pointer to void meaning

  adsi, c++, rust

I’m trying to work with active directory from Rust by following the c++ examples Microsoft posts for the ADSI API and the Windows-RS crate. I’m not understanding quite what is going on here:

https://docs.microsoft.com/en-us/windows/win32/api/adshlp/nf-adshlp-adsopenobject

They create an uninitialized pointer to IADs (drawing from my c# knowledge, it looks like an interface) then, when it comes time to use it, they have a double pointer that is cast as void. I tried to replicate this behavior in Rust, but I’m thinking I’m just not understanding exactly what is happening. This is what I’ve tried so far:

// bindings omitted
use windows::Interface;
use libc::c_void;
 
fn main() -> windows::Result<()> {
        let mut pads: *mut IADs = ptr::null_mut();
        let ppads: *mut *mut c_void = pads as _;

        unsafe {
            let mut ldap_root: Vec<u16> = "LDAP://rootDSE".encode_utf16().collect();
            let hr = ADsOpenObject(
                ldap_root.as_mut_ptr() as _,
                ptr::null_mut(),
                ptr::null_mut(),
                ADS_AUTHENTICATION_ENUM::ADS_SECURE_AUTHENTICATION.0 as _,
                & IADs::IID,
                ppads,
            );
            println!("{:?}", hr);
        }
   
    Ok(())
}

First, I’m probably wrong to be creating a null pointer because that’s not what they’re doing in the example, but the problem is that rust doesn’t permit the use of an uninitialized variable, so I’m not sure what the equivalent is.

Second, presumably the pADs variable is where the output is supposed to go, but I’m not understanding the interaction of having a pointer, then a double pointer, to an object that doesn’t have an owner. Even if that were possible in rust, I get the feeling that it’s not what I’m supposed to do.

Source: Windows Questions C++

LEAVE A COMMENT