Pass an string array to CreateProcess in for loop for multiple processes

I have to admit that most of the win32 api stuff I am not familiar with in this code. That being said, I would like to incorporate what I do know into my learning process. I am trying to create a for loop that will CreateProcess multiple times with different arguments each time. In Visual Studio I get a compile error:

source.cpp(138): error C3867: 'std::basic_string<_Elem,_Traits,_Alloc>::c_str': function call        missing argument list; use '&std::basic_string<_Elem,_Traits,_Alloc>::c_str' to create a     pointer to member
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Alloc=std::allocator<char>
1>          ]

When running the following code:

std::string arrString[3] = {"dir","cd ..","dir"};
            int i;
            LPWSTR cmd =L"cmd";

            for(i=0; i<3; i++)
            {
            STARTUPINFO info={sizeof(info)};
            PROCESS_INFORMATION processInfo;
            if (CreateProcess(cmd, arrString[i].c_str, NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo))
            {
                ::WaitForSingleObject(processInfo.hProcess, INFINITE);
                CloseHandle(processInfo.hProcess);
                CloseHandle(processInfo.hThread);
            }

Am I even headed in the right direction?

EDIT:

            std::string arrString[3] = {"cmd","cmd","cmd"};
            int i;
            LPWSTR cmd =L"cmd";

            for(i=0; i<3; i++)
            {
                STARTUPINFO info={sizeof(info)};
                PROCESS_INFORMATION processInfo;
                vector<wchar_t> cmdline(arrString[i].begin(), arrString[i].end()); 
                CreateProcessW(cmd, &cmdline[0], NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo);
                    ::WaitForSingleObject(processInfo.hProcess, INFINITE);
                    CloseHandle(processInfo.hProcess);
                    CloseHandle(processInfo.hThread);

            }

Answers


In this line

if (CreateProcess(cmd, arrString[i].c_str, NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo))

you wrote arrString[i].c_str when you meant arrString[i].c_str().


Need Your Help

How to print n times n without loops, recursivity or goto in C#

c# c++ constructor

I have this code in c++ to do this but I want to do the same in C# but it's not working and I can't figure it out why?

How to use composer with phpbrew?

php composer-php ubuntu-14.04 phpbrew

I installed phpbrew to use php 5.4 in Ubuntu 14.04. It works fine, except when I try to use composer, which ignores phpbrew and installs dependencies related to php 5.5.