Strange question - how to store BSTR allocated with SysAllocString,etc?

Let’s say I pass a wide string into SysAllocStringLen - the pointer I get back is a bit more than a raw pointer. The 4 bytes of memory right before that pointer points to a value indicating the # of characters in the BSTR. (2 bytes per character). Unlike normal C-style strings, there can be 0s in a BSTR.

Unfortunately, Pin is still in nightly.

Is there any way to “own” the pointer and hold it without moving it around? Or am I overthinking this and a basic NonNull would work here?

Basic NonNull is totally fine- the only thing you would be moving is the pointer, and there’s no dependence on its location.

1 Like

Wait, right. The pointer itself can move - the location its pointing too can’t be moved. That location is allocated by the Sys functions, so its not touched by Rust.

Thanks. Was definitely overthinking it.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.