I stumbled on this class when browsing the internet this morning: CStrBufT.
I understand that it is meant to be used instead of:
CString::GetBuffer
CString::GetBufferSetLength
CString::ReleaseBuffer
But the documentation lacks a usage example, and my searches on the internet don't seem to show this class being used, but the respective CString methods.
What is the correct way to use this wrapper when you need a buffer?
Most commonly, you use
CStrBufwhen you have to pass a string buffer to a C API that is filled by the called function. Here is an example that callsGetModuleFileName()from C++ (off the top of my head).CStrBufhas anoperator LPTSTR, i.e., it can be converted to a writable string implicitly. For this reason, it can be written as a temporary object in place of anLPTSTRargument (the second argument in this example).Note that
CStrBufTis a class template just likeCStringTis. Stick with the specializationCStrBufthat is akin toCString.