c++ convert from LPCTSTR to const char *

Since you’re using MFC, you can easily let CString do an automatic conversion from char to TCHAR:

MyFunction(CString(wChar));

This works whether your original string is char or wchar_t based.

Edit: It seems my original answer was opposite of what you asked for. Easily fixed:

MyFunction(CStringA(wChar));

CStringA is a version of CString that specifically contains char characters, not TCHAR. There’s also a CStringW which holds wchar_t.

Leave a Comment