CString::LockBuffer

LPTSTR LockBuffer( );

Return Value

A pointer to a CString object or a NULL-terminated string.

Remarks

Call this member function to lock a string in the buffer.

By calling LockBuffer, you create a copy of the string, and then set the reference count to -1. When the reference count is set to -1, the string in the buffer is considered to be in a "locked" state.  While in a locked state, the string is protected in two ways:

  • No other string can get a reference to the data in the locked string, even if that string is assigned to the locked string.

  • The locked string will never reference another string, even if that other string is copied to the locked string.

By locking the string in the buffer, you ensure that the string’s exclusive hold on the buffer will remain intact.

After you have finished with LockBuffer, call UnlockBuffer to reset the reference count to 1.

For more information about reference counting, see the following articles:

  • in the Win32 SDK Programmer’s Reference

  • in the Win32 SDK Programmer’s Reference

  • in the Win32 SDK Programmer’s Reference

CString OverviewClass MembersHierarchy Chart

See Also   CString::UnlockBuffer, CString::GetBuffer, CString::ReleaseBuffer