LPCSTR, LPCTSTR and LPTSTR
To answer the first part of your question:
LPCSTR
is a pointer to a const string (LP means Long Pointer)
LPCTSTR
is a pointer to a const TCHAR
string, (TCHAR
being either a wide char or char depending on whether UNICODE is defined in your project)
LPTSTR
is a pointer to a (non-const) TCHAR
string
In practice when talking about these in the past, we've left out the "pointer to a" phrase for simplicity, but as mentioned by lightness-races-in-orbit they are all pointers.
This is a great codeproject article describing C++ strings (see 2/3 the way down for a chart comparing the different types)
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 compiler options.
Bonus Reading
From What does the letter "T" in LPTSTR stand for?: archive
What does the letter "T" in LPTSTR stand for?
October 17th, 2006
The “T” in LPTSTR comes from the “T” in TCHAR. I don’t know for certain, but it seems pretty likely that it stands for “text”. By comparison, the “W” in WCHAR probably comes from the C language standard, where it stands for “wide”.
8-bit AnsiStrings
char
: 8-bit character (underlying C/C++ data type)CHAR
: alias ofchar
(Windows data type)LPSTR
: null-terminated string ofCHAR
(Long Pointer)LPCSTR
: constant null-terminated string ofCHAR
(Long Pointer Constant)
16-bit UnicodeStrings
wchar_t
: 16-bit character (underlying C/C++ data type)WCHAR
: alias ofwchar_t
(Windows data type)LPWSTR
: null-terminated string ofWCHAR
(Long Pointer)LPCWSTR
: constant null-terminated string ofWCHAR
(Long Pointer Constant)
depending on UNICODE
define
TCHAR
: alias ofWCHAR
if UNICODE is defined; otherwiseCHAR
LPTSTR
: null-terminated string ofTCHAR
(Long Pointer)LPCTSTR
: constant null-terminated string ofTCHAR
(Long Pointer Constant)
So:
Item | 8-bit (Ansi) | 16-bit (Wide) | Varies |
---|---|---|---|
character | CHAR |
WCHAR |
TCHAR |
string | LPSTR |
LPWSTR |
LPTSTR |
string (const) | LPCSTR |
LPCWSTR |
LPCTSTR |
Bonus Reading
TCHAR
→ Text Char (archive.is)
Why is the default 8-bit codepage called "ANSI"?
From Unicode and Windows XP
by Cathy Wissink
Program Manager, Windows Globalization
Microsoft Corporation
May 2002
Despite the underlying Unicode support on Windows NT 3.1, code page support continued to be necessary for many of the higher-level applications and components included in the system, explaining the pervasive use of the “A” [ANSI] versions of the Win32 APIs rather than the “W” [“wide” or Unicode] versions. (The term “ANSI” as used to signify Windows code pages is a historical reference, but is nowadays a misnomer that continues to persist in the Windows community. The source of this comes from the fact that the Windows code page 1252 was originally based on an ANSI draft, which became ISO Standard 8859-1. However, in adding code points to the range reserved for control codes in the ISO standard, the Windows code page 1252 and subsequent Windows code pages originally based on the ISO 8859-x series deviated from ISO. To this day, it is not uncommon to have the development community, both within and outside of Microsoft, confuse the 8859-1 code page with Windows 1252, as well as see “ANSI” or “A” used to signify Windows code page support.)