In the project I want to implement a function: a process to create a B process run, through the end of B process to return the error code to carry out the next process.
Referring to some of the online code, the final form of such an absolutely feasible solution. A process:
if (CreateProcess (null,m_file,null,null,true,create_new_process_group| CREATE_DEFAULT_ERROR_MODE,NULL,NULL,&SI,&PI)) { //Wait until child process exits. WaitForSingleObject (pi.hprocess, INFINITE); GetExitCodeProcess (pi.hprocess, &exitcode); Close process and thread handles. CloseHandle (pi.hprocess); CloseHandle (Pi.hthread); if (id_cancel = = ExitCode) break;}
In the B process, send the Wm_quit message via PostQuitMessage (exit), and then get the error code via WPARAM
while (Msg.message!=wm_quit) {if (PeekMessage (&msg, NULL, 0U, 0U, Pm_remove)) {//Handles external message translatemessage (&MSG); DispatchMessage (&msg);} Else{}}}return Msg.wparam;
The process accepts the return code of the process end pass