How To Convert CString To TCHAR*

See the following code segment.

CString myCString = _T("Hello"); 
const TCHAR* myCharString = LPCTSTR(myCString);

Some Background Info

  1. TCHAR will be evaluated to char if _UNICODE is not defined. Otherwise it will be evaluated to wchar.
  2. LPCTSTR is also a data type which is nothing but const char* or const wchar*, depending on whether _UNICODE defined or not.
  3. CString has a constructor which accepts TCHAR*.
  4. The macro _T will make the supplied string neutral. That is, if _UNICODE is defined, the string will be in 16 bit unicode format, otherwise in 8 bit ANSI format.
Advertisements

One Response to How To Convert CString To TCHAR*

  1. It’s actually a nice and helpful piece of information. I’m satisfied that you simply shared this useful information with us.
    Please stay us up to date like this. Thank you for sharing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: