bossman
bossman

Reputation: 421

CreateProcess() not work properly

Im using this code to start my program

     int _tmain(int argc, _TCHAR* argv[])
{
    STARTUPINFO cif;
    ZeroMemory(&cif,sizeof(STARTUPINFO));
    PROCESS_INFORMATION pi;
    if (CreateProcess(L"C:\\test\\test.exe",NULL,
        NULL,NULL,FALSE,CREATE_UNICODE_ENVIRONMENT,NULL,NULL,&cif,&pi)==TRUE)
    {
        cout << "process" << endl;
        cout << "handle " << pi.hProcess << endl;
    }
    system("pause");
    return 0;
}

The program starts normal, but immediately fails(not responding and fails). CreateProcess returns true. When I start test.exe not from code it works properly.

Upvotes: 0

Views: 2541

Answers (2)

bossman
bossman

Reputation: 421

I found problem that I didnt set directory for test.exe( 8th argument in CreateProcess). Thanks to all

Upvotes: 0

Joel Spolsky
Joel Spolsky

Reputation: 33687

You have to zero the memory of both STARTUPINFO and PROCESS_INFORMATION, and you have to set the cb field of the STARTUPINFO structure.

Copying the sample code in the Microsoft documentation is a good place to start.

Upvotes: 5

Related Questions