Allocates an Automation-compatible string of the type BSTR and copies the contents of the CStringT object into it, including the terminating null character.
BSTR AllocSysString() const;
The newly allocated string.
Commonly, if this string is passed to a COM function as an [in] parameter, then this requires the caller to free the string. This can be done by using SysFreeString, as described in the Windows SDK. For more information, see Allocating and Releasing Memory for a BSTR.
For more information about OLE allocation functions in Windows, see SysAllocString in the Windows SDK.
The following example demonstrates the use of CStringT::AllocSysString.
// typedef CStringT<TCHAR, StrTraitATL<TCHAR, ChTraitsCRT<TCHAR>>> CAtlString; CAtlString str(_T("This is a test string!")); BSTR bstr = str.AllocSysString(); // bstr now contains "This is a test string!", and can be // passed to any OLE function requiring a BSTR. // Normally, if you pass the BSTR, you will // need to free the string after returning from the function call.