Visual Studio 6.0


BSTR SetSysString( BSTR* pbstr ) const;

Return Value

The new string.



A pointer to a character string.


Reallocates the BSTR pointed to by pbstr and copies the contents of the CString object into it, including the NULL character. The value of the BSTR referenced by pbstr may change. The function throws a CMemoryException if insufficient memory exists.

This function is normally used to change the value of strings passed by reference for OLE Automation.

For more information about OLE reallocation functions in Windows, see https://msdn.microsoft.com/en-us/library/ms221533(v=vs.60).aspx and https://msdn.microsoft.com/en-us/library/ms221481(v=vs.60).aspx in the Win32 SDK OLE Programmer’s Referenc.


// create an OLE string
BSTR bstr = ::SysAllocString(L"Golf is fun!");

// create a CString and change the OLE
// string to the contents of the BSTR
CString str("Hockey is best!");
BSTR bstr2 = str.SetSysString(&bstr);

// Now, both bstr and bstr2 reference a single instance of
// the "Hockey" string. The "Golf" string has been freed.
ASSERT(bstr2 == bstr);

CString OverviewClass MembersHierarchy Chart