CString str = "Hello, World!"; const TCHAR* pBuffer = str.LockBuffer(); // do something with pBuffer str.UnlockBuffer();
CString str = "Hello, World!"; LPTSTR pBuffer = str.GetBuffer(); // do something with pBuffer str.ReleaseBuffer();In this example, the GetBuffer method is called to obtain a read-write pointer to the buffer holding the content of the CString object. Then, the pointer pBuffer is passed to some function for processing. After the processing is done, the ReleaseBuffer method is called to release the lock. The CString LockBuffer method belongs to the CString class in the MFC (Microsoft Foundation Class) library, which is a package of classes and functions provided by Microsoft for building Windows-based applications using C++.