Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

what is LPCTSTR and LPCTSTR-like (for instance HDC) and what it does stand for?

share|improve this question
This is why we just love Microsoft. – zxcdw Apr 12 '13 at 18:22
Those "types" always exhibit surprises, e.g. when you do LPCSTR p, q; and you wanted to have const char *p, *q;. Can you refuse to use them? – ott-- Apr 12 '13 at 20:38
An abomination. – Thomas Eding Apr 16 '13 at 21:55
64 bit porting of a 32-bit application requires knowledge of such terminologies – overexchange Dec 2 '15 at 20:44
up vote 46 down vote accepted

Quoting Brian Kramer on the MSDN forums

LPCTSTR = L‌ong P‌ointer to a C‌onst T‌CHAR STR‌ing (Don't worry, a long pointer is the same as a pointer. There were two flavors of pointers under 16-bit windows.)

Here's the table:

  • LPSTR = char*
  • LPCSTR = const char*
  • LPWSTR = wchar_t*
  • LPCWSTR = const wchar_t*
  • LPTSTR = char* or wchar_t* depending on _UNICODE
  • LPCTSTR = const char* or const wchar_t* depending on _UNICODE
share|improve this answer
Every time I see that type name I feel like cringing. There's just something about it that makes me uncomfortable. (+1 BTW) – Donal Fellows Apr 13 '13 at 8:44
When should I use this kind of pointer then? – Florian Margaine Apr 13 '13 at 9:16
@FlorianMargaine When an API tells you to. Just use the 'proper' types until then – James Apr 13 '13 at 13:43
"There were two flavors of pointers under 16-bit windows": Does the name come from back then? Some compilers used to call them far pointers... – Giorgio Dec 2 '15 at 20:02
be warned, there are lots of caveats to be aware of here. wchar_t is a 16 bit type, but can be used to store both ucs2 and utf-16 encoded unicode characters. utf-16 may use multiple wchar_t's to encode a single letter, ucs2 only supports a subset of the unicode characterset. Which API functions you need to call also depend on the encoding used. – Michael Shaw Dec 3 '15 at 13:34

There's no need to ever use any of the types relating to TCHAR.

Those types, all structure types that use them, and all related functions are mapped at compile time to an ANSI or UNICODE version (based on your project's configuration). ANSI versions typically have an A appended to the end of the name, and unicode versions append a W. You can use these explicitly if you prefer. MSDN will note this when necessary, for example it lists a MessageBoxIndirectA and MessageBoxIndirectW function here:

Unless you are targeting Windows 9x, which lacked implementations of many unicode functions, there's no need to use the ANSI versions. If you are targeting Windows 9x, you can use TCHAR to build an ansi and unicode binary from the same codebase, as long as your code makes no assumptions about whether TCHAR is a char or wchar.

If you don't care about Windows 9x, I recommend configuring your project as unicode and treating TCHAR as identical to WCHAR. You can explicitly use the W functions and types if you prefer, but as long as you don't plan to run your project on Windows 9x, it doesn't really matter.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.