Windows apps
Collapse the table of content
Expand the table of content

SysAllocString Function

Allocates a new string and copies the passed string into it.

BSTR SysAllocString(
  const OLECHAR   *sz


A zero-terminated string to copy. The sz parameter must be a Unicode string in 32-bit applications, and an ANSI string in 16-bit applications. The argument sz may be NULL.

If successful, returns a BSTR containing the string. If sz is a zero-length string, returns a zero-length BSTR. If sz is NULL or insufficient memory exists, returns NULL.

You can free strings created with SysAllocString using SysFreeString.

inline void CStatBar::SetText(OLECHAR * sz)
   SysFreeString(m_bstrMsg);   // Free previous string, if any.
   m_bstrMsg = SysAllocString(sz);
   // Caller should check to see if m_bstrMsg is null after calling this method.
© 2017 Microsoft