Trait oaidl::BStringExt[][src]

pub trait BStringExt {
    fn allocate_bstr(&mut self) -> Result<Ptr<u16>, BStringError>;
fn allocate_managed_bstr(
        &mut self
    ) -> Result<DroppableBString, BStringError>;
fn deallocate_bstr(bstr: Ptr<u16>);
fn from_bstr(bstr: *mut u16) -> U16String;
fn from_pbstr(bstr: Ptr<u16>) -> U16String;
fn from_boxed_bstr(bstr: Box<u16>) -> U16String; }

This trait is implemented on String to enable the convenient and safe conversion of It utilizes the Sys* functions to manage the allocated memory. Generally you will want to use .allocate_managed_bstr() because it provides a type that will automatically free the BSTR when dropped.

For FFI, you cannot use a straight up *mut u16 when an interface calls for a BSTR. The reason being is that at the four bytes before where the BSTR pointer points to, there is a length prefix. In addition, the memory will be freed by the same allocator used in SysAllocString, which can cause UB if you didn't allocate the memory that way. Any other allocation method will cause UB and crashes.

Required Methods

Allocates a Ptr (aka a *mut u16 aka a BSTR)

Allocates a DroppableBString container - automatically frees the memory properly if dropped.

Manually and correct free the memory allocated via Sys* methods

Convenience method for conversion to a good intermediary type

Convenience method for conversion to a good intermediary type

Convenience method for conversion to a good intermediary type

Implementations on Foreign Types

impl BStringExt for U16String
[src]

Implementors