Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

CComBSTR::CComBSTR

 

The constructor. The default constructor sets the m_str member to NULL.


      CComBSTR( ) throw( ); 
CComBSTR(
   const CComBSTR& src 
);
CComBSTR(
   REFGUID guid 
);
CComBSTR(
   int nSize 
);
CComBSTR(
   int nSize,
   LPCOLESTR sz 
);
CComBSTR(
   int nSize,
   LPCSTR sz 
);
CComBSTR(
   LPCOLESTR pSrc 
);
CComBSTR(
   LPCSTR pSrc 
);
CComBSTR(
   CComBSTR&& src 
);

nSize

[in] The number of characters to copy from sz or the initial size in characters for the CComBSTR.

sz

[in] A string to copy. The Unicode version specifies an LPCOLESTR; the ANSI version specifies an LPCSTR.

pSrc

[in] A string to copy. The Unicode version specifies an LPCOLESTR; the ANSI version specifies an LPCSTR.

src

[in] A CComBSTR object.

guid

[in] A reference to a GUID structure.

The copy constructor sets m_str to a copy of the BSTR member of src. The REFGUID constructor converts the GUID to a string using StringFromGUID2 and stores the result.

The other constructors set m_str to a copy of the specified string. If you pass a value for nSize, then only nSize characters will be copied, followed by a terminating null character.

CComBSTR supports move semantics. You can use the move constructor (the constructor that takes an rvalue reference (&&) to create a new object that uses the same underlying data as the old object you pass in as an argument, without the overhead of copying the object.

The destructor frees the string pointed to by m_str.

Example

CComBSTR bstr1;   // BSTR points to NULL
bstr1 = "Bye";    // initialize with assignment operator
                  // ANSI string is converted to wide char

OLECHAR* str = OLESTR("Bye bye!");  // wide char string of length 5
int len = (int)wcslen(str);
CComBSTR bstr2(len + 1);// unintialized BSTR of length 6
wcsncpy_s(bstr2.m_str, bstr2.Length(), str, len); // 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'   

Requirements

Header: atlbase.h

Show: