开发者

ShellExecute async (launch program from within C++ and exit immediately)

开发者 https://www.devze.com 2023-04-08 18:14 出处:网络
I want to launch MYAPPLICATION from within a C++ program and immediately exit the C++ program (so I do NOT want to wait until MYAPPLICATION has finished or get a reference to the program): just start

I want to launch MYAPPLICATION from within a C++ program and immediately exit the C++ program (so I do NOT want to wait until MYAPPLICATION has finished or get a reference to the program): just start the MYAPPLICATION and exit.

I tried ShellExecute, but the C++ app is still running after the MYAPPLICATION is started. I also tried using a thread, but if I don't wait for the thread, MYAPPLICATION is not started at all.

if ((err = _waccess_s( MYAPPLICATION, 0 )) == 0 )
    {
        // application found
        ShellExecute(NULL, _T("open"), MYAPPLICA开发者_StackOverflow社区TION,NULL, NULL, SW_SHOWNORMAL);

        // Create thread 1.
        int Data_Of_Thread_1 = 1;
        HANDLE Handle_Of_Thread_1 = 0;
        HANDLE Array_Of_Thread_Handles[1];
        Handle_Of_Thread_1 = CreateThread( NULL, 0, Thread_no_1, &Data_Of_Thread_1, 0, NULL);  
        Array_Of_Thread_Handles[0] = Handle_Of_Thread_1;
        WaitForMultipleObjects( 1, Array_Of_Thread_Handles, TRUE, INFINITE);
        CloseHandle(Handle_Of_Thread_1);

    }

How can I start MYAPPLICATION from within C++ and immediately exit the C++ app?

Thanks.


You need to terminate your process using ExitProcess(), TerminateProcess(), or returning from WinMain() after you start the child process.

0

精彩评论

暂无评论...
验证码 换一张
取 消