cannot convert from 'TCHAR [260]' to 'std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>

error C2440: 'initializing': cannot convert from 'TCHAR [260]' to 'std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>
I get this error, been stuck on this for a few hours..
TCHAR szModName[MAX_PATH];
if (!GetModuleFileNameEx(hProcess, hMods[i], szModName, sizeof(szModName) / sizeof(TCHAR))) // Get the full path to the module's file
continue;
wstring modName = szModName; <-------- this is what im having problem with
You're assuming szModName is a wide string, but TCHAR is char or wchar_t depending on whether UNICODE is set. Maybe try something like this.
1
2
3
4
5
6
7
#ifdef UNICODE
typedef wstring TSTRING;
#else
typedef string TSTRING;
#endif

TSTRING modName = szModeName;

My recommendation is to just not bother with TCHAR and just call the wide version.
1
2
3
4
wchar_t szModName[MAX_PATH];
if (!GetModuleFileNameExW(hProcess, hMods[i], szModName, sizeof(szModName) / sizeof(wchar_t))) // Get the full path to the module's file
    continue;
wstring modName = szModName;
Last edited on
Topic archived. No new replies allowed.