Wednesday, April 21, 2010

How to convert _TCHAR* to char* in C++

_TCHAR is a typedef of wide characters or wchar_t. Hence, we use wcstombs function to convert it to multibyte characters. This function should help you with that.

char * wchar_to_string(_TCHAR* widechar)
{
int size=0;
while( (char)widechar[size] != '\0'){
size++;
}
size++;
char * charpointer = new char[size];
wcstombs(charpointer, widechar, size );
return charpointer;
}

No comments: