I have to convert a TCHAR variable (which is a path retrieved with OpenBrowseDir) into a std::string. I'm currently having this code which works. I'm using WideCharToMultiByte.
TCHAR path[MAX_PATH];
OpenBrowseDir(path);
/*conversion from TCHAR to std::string*/
char ch[MAX_PATH];
char DefChar = ' ';
WideCharToMultiByte(CP_ACP, 0, path, -1, ch, MAX_PATH, &DefChar, NULL);
string spath(ch);
On my project TCHAR is wchar_t.
In OpenBrowseDir I'm opening a browse dialog so the user can select a directory. I'm using a variable BROWSEINFO bi, and bi.pszDisplayName is of type TCHAR.
Are there other better solutions?