Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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

share|improve this question
4  
    
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
4  
An abomination. –  Thomas Eding Apr 16 '13 at 21:55

2 Answers 2

up vote 32 down vote accepted

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
4  
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
1  
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'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: http://msdn.microsoft.com/en-us/library/windows/desktop/ms645511(v=vs.85).aspx

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

 
discard

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.