0
votes

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.

2
What does the debugger tell you about what's going wrong? You are using a debugger, aren't you? - Rob Kennedy
Which program is crashing, this code that is launching the new process, or test.exe? - Adam Rosenfield
What happens if you pass 0 for process creation flag (instead of CREATE_UNICODE_ENVIRONMENT)? You're passing CREATE_UNICODE_ENVIRONMENT as this flag and NULL for environment block but are you sure that environment block of the calling process use UNICODE characters? - Bojan Komazec
I found problem that I didnt set environment for test.exe( 8th argument in CreateProcess). Thanks to all - bossman
@bossman Great, add that as an answer to let everyone know how you solved it. - karlphillip

2 Answers

5
votes

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.

0
votes

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