The process accepts the return code passed by the process end and the return code sent by the process.

Source: Internet
Author: User

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;


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.