The process accepts the return code passed by the process end and the return code sent by the process.
In the project, I want to implement the following function: process A creates process B to run, and uses the error code returned when process B ends.
According to some online code, such an absolutely feasible solution was finally formed. 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 process B, send the WM_QUIT message through PostQuitMessage (exit), and then get the error code through wparam.
While (msg. message! = WM_QUIT) {if (PeekMessage (& msg, NULL, 0U, 0U, PM_REMOVE) {// process external message TranslateMessage (& msg); DispatchMessage (& msg );} else {}} return msg. wParam;