Manipulate BSTR values

Web Site  Methods

 
Str::AllocSysString
 
BSTR AllocSysString () const
Only available under Windows

This is a helper method for COM / ATL programmers. It will allocate a new BSTR instance containing a copy of the string data and return it to the caller.

The caller is responsible for freeing the returned BSTR when it is no longer needed.

The method will work both with ANSI and Unicode modules, but will be faster in the latter case because no conversion is required.

Note: as per COM specifications, an empty string can always be represented with a NULL BSTR value.  Thus, calling AllocSysString on an empty string will now return a NULL value instead of allocating a string with no characters except the null terminator.

 

 
Str::SetSysString
 
BSTR SetSysString (BSTR* str) const
Only available under Windows

This is a helper method for COM / ATL programmers. It requires a pointer to a BSTR that should be initialized with a valid value or set to NULL upon entry.

The method will copy the Str object content into a newly allocated BSTR instance that will be stored in the passed location (if the original value was not NULL, the previous BSTR will be freed). The return value of the method will be equal to the content of the location pointed to by str.

 

 
Str::operator =
 
const Str& operator= (BSTR s)
Only available under Windows

Similar to operator = (const STRWCHAR*), this will copy the value of the passed BSTR in the Str object. Unlike most other method calls accepting C-style string pointers, this operator will correctly handle a NULL pointer value (which, under the BSTR documentation, means "empty string").

 

See also: Windows-specific