LPCSTR, LPCTSTR and LPTSTR


Question

What the difference between LPCSTR, LPCTSTR and LPTSTR?

Why do we need to do this to convert a string into a LV / _ITEM structure variable pszText:

LV_DISPINFO dispinfo;  
dispinfo.item.pszText = LPTSTR((LPCTSTR)string);
1
97
2/5/2018 10:17:37 PM

Accepted Answer

To answer the first part of your question:

LPCSTR is a const string

LPCTSTR is a const TCHAR string, (TCHAR being either a wide char or char depending on whether UNICODE is defined in your project)

LPTSTR is a (non-const) TCHAR string

This is a great codeproject article describing C++ strings (see 2/3 the way down for a chart comparing the different types)

111
2/24/2015 4:19:41 PM

Quick and dirty:

LP == Long Pointer. Just think pointer or char*

C = Const, in this case, I think they mean the character string is a const, not the pointer being const.

STR is string

the T is for a wide character or char (TCHAR) depending on compile options.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon