Given
CString buffer = "";
Cstring value = "blah";
buffer.Format ("%s %s", value, value.GetBuffer());
are the two ways of passing a CString equivalent, or does passing the CString have something happening behind the scenes that causes it to be equivalent?
Neither one is correct. The first one seems to work, by coincidence while the latter uses a tool that serves a different purpose. The only correct way is to invoke the cast operator:
Passing a
CStringobject directly works by coincidence only since the pointer-sized value at the beginning of the object is interpreted as a pointer to a character array. The first class member of theCStringclass happens to be them_pszDatamember - a pointer that stores the controlled sequence of characters.GetBuffershould only be used if you have to manipulate aCStrings contents directly. Note that this returns a non-constpointer. This is often used when interfacing with C APIs (see Modifying CString Contents Directly for details).