CComBSTR( );
CComBSTR( int nSize );
CComBSTR( int nSize, LPCOLESTR sz );
CComBSTR( int nSize, LPCSTR sz );
CComBSTR( LPCOLESTR pSrc );
CComBSTR( LPCSTR pSrc );
CComBSTR( const CComBSTR& src );
Parameters
nSize
[in] The number of characters to copy from sz.
sz
[in] A string to copy. The Unicode version specifies an LPCOLESTR; the ANSI version specifies an LPCSTR. Only nSize characters will be copied. The default value is NULL.
pSrc
[in] A string to copy. The Unicode version specifies an LPCOLESTR; the ANSI version specifies an LPCSTR.
src
[in] A CComBSTR object.
Remarks
The default constructor sets the m_str member to NULL. The copy constructor sets m_str to a copy of the BSTR member of src.
The other four constructors set m_str to a copy of the specified string; however, if you pass a value for nSize, then only nSize characters will be copied, followed by a terminating null character.
The destructor frees the string pointed to by m_str.
Example
CComBSTR bstr1; // BSTR points to NULL
bstr1 = "Bye"; // initialize with assignment operator
OLECHAR* str = OLESTR("ta ta"); // wide char string of length 5
CComBSTR bstr2(wcslen(str)); // unitialized BSTR of length 5
wcscpy(bstr2.m_str, str); // copy wide char string to BSTR
CComBSTR bstr3(5, OLESTR("Hello World")); // BSTR containing 'Hello',
// input string is wide char
CComBSTR bstr4(5, "Hello World"); // same as above, input string
// is ANSI
CComBSTR bstr5(OLESTR("Hey there")); // BSTR containing 'Hey there',
// input string is wide char
CComBSTR bstr6("Hey there"); // same as above, input string
// is ANSI
CComBSTR bstr7(bstr6); // copy constructor, bstr7 contains 'Hey there'