你好,我正在尝试让我的应用程序在启动时运行,并且为了在我的客户 PC 上运行,我首先需要获取他们的 PC 用户名,但是当我试图让它工作时,我得到了这个错误:
E2140 expression must have integral or unscoped enum type
代码如下:
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";
如何将 TCHAR* 转换为 Const Char?
最佳答案
正如其他人在评论中所说,您不能使用加法运算符在 C 中连接字符串。你可以在这个例子中做一些类似的事情:
#include <string.h>
char buf[4096];
snprintf(buf, sizeof(buf), "\"C:\\Users\\%s\\Desktop\\Myapplication.exe\" /background", username);
const char* czExePath = buf;
关于c++ - 无法将 TCHAR* 添加到 const char,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46083058/