typedef std::basic_string<TCHAR> tstring; TCHAR* StringToTCHAR(string& s) { tstring tstr; const char* all = s.c_str(); int len = 1 + strlen(all); wchar_t* t = new wchar_t[len]; if (NULL == t) throw std::bad_alloc(); mbstowcs(t, all, len); return (TCHAR*)t; } std::string TCHARToString(const TCHAR* ptsz) { int len = wcslen((wchar_t*)ptsz); char* psz = new char[2*len + 1]; wcstombs(psz, (wchar_t*)ptsz, 2*len + 1); std::string s = psz; delete [] psz; return s; }
Announcement
Collapse
No announcement yet.
Converting std::string to TCHAR and vice verse
Collapse
X
-
Converting std::string to TCHAR and vice verse
I struggled with this A LOT. Xeno123 tried to help me with his mexican boost casts and i tried and tried but finally found this way and ended up using it, i really hope this will be useful for other people too who have similiar problems, at least it fixed my problem :p
Code:lolmaoman: Germans are born with a lifetime x22 login engraved into their birth certificates. True story.Tags: None
Comment