Поделиться через


CStringT::SetSysString

Reallocates the BSTR pointed to by pbstr and copies the contents of the CStringT object into it, including the NULL character.

BSTR SetSysString(
   BSTR* pbstr
) const;

Параметры

  • pbstr
    A pointer to a character string.

Возвращаемое значение

The new string.

Заметки

Depending on the contents of the CStringT object, the value of the BSTR referenced by pbstr can 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 Automation.

For more information about OLE reallocation functions in Windows, see SysReAllocStringLen and SysFreeString.

Пример

BSTR bstr = ::SysAllocString(L"Golf is fun!");

// create a CAtlString and change the OLE
// string to the contents of the BSTR
// typedef CStringT<TCHAR, StrTraitATL<TCHAR, ChTraitsCRT<TCHAR>>> CAtlString;

CAtlString str(_T("Soccer is best!"));
BSTR bstr2 = str.SetSysString(&bstr);

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

Требования

Header: cstringt.h

См. также

Основные понятия

CStringT Class

CStringT Members

CMemoryException Class