C++上带有const char(结果GetComputerName)的连接字符串

Glo*_*ure 0 c++ concat strcpy strcat

需要:连接function GetComputerName (nameBuf)命令的结果以打开Chormium.

目标:使用正在执行安装的计算机的名称创建新的配置文件.

问题:我不知道如何实现这种连接,试图成功完成strcpystrcat取得成功.

这是我的代码:

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;
}
Run Code Online (Sandbox Code Playgroud)

-

Pastbin:http://pastebin.com/N1eyAfGV

mas*_*oud 5

strcpyconst char *调用未定义的行为:

std::string s = "chromium\\ChromiumPortable ...";
s += nameBuf;

WinExec(s.c_str(), SW_HIDE);
Run Code Online (Sandbox Code Playgroud)