Visual Studio 6.0


BSTR AllocSysString ( ) const;
throw( CMemoryException );

Return Value

Points to the newly allocated string.


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 https://msdn.microsoft.com/en-us/library/ms221458(v=vs.60).aspx and https://msdn.microsoft.com/en-us/library/ms221481(v=vs.60).aspx in the Win32 SDK OLE Programmer’s Reference.


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   https://msdn.microsoft.com/en-us/library/ms221458(v=vs.60).aspx , https://msdn.microsoft.com/en-us/library/ms221481(v=vs.60).aspx , CMemoryException