How do I convert argv to lpCommandLine parameter of CreateProcess?

后端 未结 4 641
深忆病人
深忆病人 2021-01-29 14:37

Let I want to write an application, that launches another application. Like this:

# This will launch another_app.exe
my_app.exe another_app.exe 
# This will laun         


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-29 14:52

    You can check out the below code if it suits your need, the txt array sz can be used as a string pointer. I have added code support for both Unicode and MBCS,

                #include 
                #include 
    
                #ifdef _UNICODE
                    #define String std::wstring
                #else
                    #define String std::string
                #endif 
    
                int _tmain(int argc, _TCHAR* argv[])
                {
                    TCHAR sz[1024] = {0};
                    std::vector allArgs(argv, argv + argc);
    
                    for(unsigned i=1; i < allArgs.size(); i++)
                    {
                        TCHAR* ptr = (TCHAR*)allArgs[i].c_str();
                        _stprintf_s(sz, sizeof(sz), _T("%s %s"), sz, ptr);
                    }
    
                    return 0;
                }
    

提交回复
热议问题