Share via


CString::AllocSysString

BSTRAllocSysString() const;
throw(CMemoryException);

Return Value

Points to the newly allocated string.

Remarks

Allocates a new OLE Automation–compatible string of the type BSTR and copies the contents of the CString object into it, including the terminating null character. A CMemoryException is thrown if insufficient memory exists. This function is normally used to return strings for OLE Automation.

Use ::SysFreeString in the rare case that you need to deallocate the returned string.

Note   You must link with MFCO42D.DLL to obtain this function if you are using MFC in a shared library and building in debug mode. You can cause the linker to get MFCO42D.DLL automatically by including <afxdisp.h> in your STDAFX.H file.

For more information about OLE allocation functions in Windows, see and in the Win32 SDK OLE Programmer’s Reference.

Example

CString str("Hockey is Best!");
BSTR bstr = str.AllocSysString();

// bstr now contains "Hockey is best", and can be
// passed to any OLE function requiring a BSTR.
// Normally, the function receiving the BSTR will
// free the string when it is done using it.

CString OverviewClass MembersHierarchy Chart

See Also   , , CMemoryException