CreateProcess( ) doesn't create a new window with CREATE_NEW_CONSOLE flag - C/C++

后端 未结 1 1346
一整个雨季
一整个雨季 2021-01-18 03:57

I\'ve been trying to create a process with CreateProcess() using the Windows API of course. I haven\'t been able to create a new console for some reason even after scouring

相关标签:
1条回答
  • 2021-01-18 04:29

    CREATE_NEW_CONSOLE is a flag of CreateProcess() itself, not of STARTUPINFO. You are putting the flag in the wrong place. Try this instead:

    int create_process( process * p, const char * exe_path, const char * cmd_line_args )
    {
        ...
        return CreateProcessA(
                                exe_path,
                                cmd_line_args,
                                NULL,
                                NULL,
                                FALSE,
                                CREATE_NEW_CONSOLE, // <-- here
                                NULL,
                                NULL,
                                &p->s_info,
                                &p->p_info
                            );
    }
    

    Also, keep in mind that a STARTUPINFOEX can be passed to CreateProcess(), so your create_process() function should not be forcing p->s_info.cb, that should be the caller's responsibility depending on whether a STARTUPINFO or a STARTUPINFOEX is being used.

    0 讨论(0)
提交回复
热议问题