A.Krasniqi
A.Krasniqi

Reputation: 165

Cannot add TCHAR* to const char

Hello I'm trying to make my application to run on startup, and to do this to work on my clients PC firstly I needed to get their PC username, but when I'm trying to make this working I'm getting this error :

E2140 expression must have integral or unscoped enum type

Here's the code:

HKEY hKey;
const char* czStartName = "MY application";
TCHAR pcusername[UNLEN + 1];
DWORD pcusername_len = UNLEN + 1;
GetUserName((TCHAR*)pcusername, &pcusername_len);
const char* czExePath = "\"C:\\Users\\" + pcusername + "\\Desktop\\Myapplication.exe\" /background";

How Can I convert TCHAR* to Const Char?

Upvotes: 1

Views: 664

Answers (1)

Brad S.
Brad S.

Reputation: 337

As others have said in the comments, you cannot concatenate strings in C using the addition operator. You can do something like in this example:

#include <string.h>

char buf[4096];
snprintf(buf, sizeof(buf), "\"C:\\Users\\%s\\Desktop\\Myapplication.exe\" /background", username);

const char* czExePath = buf;

Upvotes: 1

Related Questions