需要:用命令连接function GetComputerName (nameBuf)的结果以打开Chormium。
目标:使用正在执行安装的机器的名称创建一个新的配置文件。
Problem:我不知道如何才能完成这一连接,但没有成功地与strcpy和strcat进行连接。
这里我的代码:
int WINAPI WinMain(HINSTANCE inst,HINSTANCE prev,LPSTR cmd,int show)
{
//Close phpdesktop.exe
WinExec("taskkill /F /IM phpdesktop.exe", SW_HIDE);
//Sleep
Sleep(500);
//Open phpdesktop.exe mini server
WinExec("phpdesktop.exe -S 127.0.0.1:54007 -t www -c php.ini", SW_HIDE);
//Sleep
Sleep(500);
//Get computer name
TCHAR nameBuf[MAX_COMPUTERNAME_LENGTH + 2];
DWORD nameBufSize;
nameBufSize = sizeof nameBuf - 1;
if (GetComputerName(nameBuf, &nameBufSize) == TRUE)
{
//How to make the concatenation result nameBuf GetComputerName function with the command of Chromium.
WinExec(strcpy("chromium\\ChromiumPortable -app=http://127.0.0.1:54007/ --profile-directory=", nameBuf), SW_HIDE);
}
//Return
return 0;
}--
Pastbin:http://pastebin.com/N1eyAfGV
发布于 2013-10-22 13:19:49
如果您不想使用第二个缓冲区,请尝试如下
THAR nameBuf[254 + 2]={0};
DWORD nameBufSize;
strcpy(nameBuf,"chromium\\ChromiumPortable -app=http://127.0.0.1:54007/ --profile-directory=");
nameBufSize = sizeof nameBuf - 1;
int index = strlen(nameBuf);
if (GetComputerName(&nameBuf[index], &nameBufSize) == TRUE)
{
WinExec(nameBuf, SW_HIDE);
}发布于 2013-10-22 12:35:58
进入strcpy的const char *调用未定义的行为
std::string s = "chromium\\ChromiumPortable ...";
s += nameBuf;
WinExec(s.c_str(), SW_HIDE);发布于 2013-10-22 12:37:33
试一试:
TCHAR command[1024];
strcpy(command, "chromium\\ChromiumPortable -app=http://127.0.0.1:54007/ --profile-directory=");
strcat(command,nameBuf);
WinExec(command, SW_HIDE);https://stackoverflow.com/questions/19517892
复制相似问题