It really sounds like (for MFC) it's better to completely stay away from
LPCTSTR & TCHAR.
Use CString, CString& or similarly with the "const" in front for Read Only.
On May 12, 4:36 pm, "JCO" <some...@somewhere.com> wrote:
As I get back into MFC Coding, I'm reminded of the different data types
that
can be used for proper & efficient coding. Generally, I see functions
that
use LPTSTR & LPCTSTR. I'm wondering why the CString is not used as much
as
a parameter. If you pass "CString &", of course, it would be efficient
as
compared to passing the entire CString class.
That is correct. In context of MFC it is normally a major performance
fault to pass LPCTSTR around, because of e.g. this:
f(LPCTSTR param)
{
CString s(param); // Allocation!
// or similar use.
}
CString s = ...;
f(s);
Compare this to:
f(const CString& param)
{
CString s(param); // NO ALLOCATION, I win.
}
CString s = ...;
f(s);
In other words, one should use LPCTSTR only when sure that it will not
be converted to a CString, or somehow mixed with one, somewhere down
the line. And that's typically a tall order.
Goran.