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
fn allocate_bstr(&mut self) -> Result<Ptr<u16>, BStringError>
Allocates a Ptr
fn allocate_managed_bstr(&mut self) -> Result<DroppableBString, BStringError>
Allocates a DroppableBString container - automatically frees the memory properly if dropped.
fn deallocate_bstr(bstr: Ptr<u16>)
Manually and correct free the memory allocated via Sys* methods
fn from_bstr(bstr: *mut u16) -> U16String
Convenience method for conversion to a good intermediary type
fn from_pbstr(bstr: Ptr<u16>) -> U16String
Convenience method for conversion to a good intermediary type
fn from_boxed_bstr(bstr: Box<u16>) -> U16String
Convenience method for conversion to a good intermediary type
Implementations on Foreign Types
impl BStringExt for U16String
[src]
impl BStringExt for U16String
fn allocate_bstr(&mut self) -> Result<Ptr<u16>, BStringError>
[src]
fn allocate_bstr(&mut self) -> Result<Ptr<u16>, BStringError>
fn allocate_managed_bstr(&mut self) -> Result<DroppableBString, BStringError>
[src]
fn allocate_managed_bstr(&mut self) -> Result<DroppableBString, BStringError>
fn deallocate_bstr(bstr: Ptr<u16>)
[src]
fn deallocate_bstr(bstr: Ptr<u16>)
fn from_bstr(bstr: *mut u16) -> U16String
[src]
fn from_bstr(bstr: *mut u16) -> U16String
fn from_pbstr(bstr: Ptr<u16>) -> U16String
[src]
fn from_pbstr(bstr: Ptr<u16>) -> U16String
fn from_boxed_bstr(bstr: Box<u16>) -> U16String
[src]
fn from_boxed_bstr(bstr: Box<u16>) -> U16String