To answer the question in the title: you concatenate two TCHAR
strings using the _tcscat
function.
However, there are other issues in your code related to this: GetUserName
expects a LPTSTR
, i.e. a pointer to a buffer TCHAR
characters. Furthermore, there's another TCHAR
usage in
TCHAR* appdatapath ="C:\\Users\\"+username+"\\AppData";
The issue with this is that the type to which TCHAR
expands changes depending on whether _UNICODE
is defined. In particular, if you set it, TCHAR
(eventually) expands to wchar
and hence GetUserName
expects a wchar_t*
but you pass a char*
. Another issue is that you cannot concatenate C arrays using the +
operator.
I suggest to stop worrying about TCHAR
in the first place and always just compile with _UNICODE
defined - and use wchar
throughout your code. Also, since you're using C++, just use std::wstring
:
wchar username[UNLEN+1];
DWORD username_len = UNLEN+1;
GetUserNameW(username, &username_len);
std::wstring appdatapath = L"C:\\Users\\";
appdatapath += username;
appdatapath += L"\\AppData";
Last but not least: your entire code can probably be replaced with a call to the SHGetSpecialFolderPath
function - pass CSIDL_APPDATA
to it to get the "AppData" path.
std::string
orstd::wstring
? Or make your owntstring
by usingstd::basic_string<TCHAR>
? – Servitor