pub struct BString(/* private fields */);Expand description
An owned BSTR string Rust type.
Used for passing strings with their ownership through the COM interfaces.
§BSTR details
The BSTR is both a length prefixed and zero terminated string with UTF-16
encoding. It is the string type widely used with Microsoft COM for
interoperability purposes.
What makes the BSTR exotic is that the *mut u16 pointer references the
start of the string data. The length prefix is located before the pointed
value.
It is important to note that when COM servers return BSTR strings, they
pass ownership of the string to the COM client. After this the COM client
is responsible for de-allocating the memory. Because of this it is
important that the memory allocation for BSTR values is well defined.
On Windows this means allocating the strings using SysAllocString or
SysAllocStringLen methods and freeing them with SysFreeString by
default.
Implementations§
Source§impl BString
impl BString
Sourcepub unsafe fn from_ptr(ptr: *mut u16) -> BString
pub unsafe fn from_ptr(ptr: *mut u16) -> BString
§Safety
The parameter must be a valid BSTR pointer. This includes both the memory layout and allocation using BSTR-compatible allocation functions.
In addition the pointer ownership moves to the BString and the pointer must not be freed outside of BString drop.
Sourcepub fn as_mut_ptr(&mut self) -> *mut u16
pub fn as_mut_ptr(&mut self) -> *mut u16
Returns the pointer as a 16-bit wide character pointer.