CString::SetSysString

BSTRSetSysString(BSTR*pbstr) const;

Return Value

The new string.

Parameters

pbstr

A pointer to a character string.

Remarks

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 and in the Win32 SDK OLE Programmer’s Referenc.

Example

// 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