Click or drag to resize

CString Basics

This section describes common usage of the CString smart data type.

Returning a BSTR

When implementing a method that should return a BSTR, either as [out, retval], [in, out] or [out], the BSTR should be allocated by the driver and freed by the client.

C++
HRESULT Acme4321::IAcme4321Display_get_Text(BSTR* val)
{
  HRESULT hr = S_OK;

  CString strText(_T("Hello world."));

  // Allocate a BSTR
  *val = strText.AllocSysString();

  return hr;
}

More information is available in the MSDN documentation for CString.

See Also

Other Resources

Download a complete CHM version of this documentation here.