1

我想通过 mfc 调用一个进程,但我需要新的 exe 必须假装像一个子对话框。因此,如果新的 exe 不会关闭,用户不应该到达主进程(对话框),这可能吗?

4

2 回答 2

2

是的。当您打开新进程时,您必须等待用户直到关闭子进程然后您必须使用 WaitForSingleObject(pi.hProcess, INFINITE);

以下代码...

if( !CreateProcess( NULL, // No module name (use command line).
    exePath,      // Command line.
    NULL,// Process handle not inheritable.
    NULL,                 // Thread handle not inheritable.
    FALSE,                // Set handle inheritance to FALSE.
    NORMAL_PRIORITY_CLASS,// No creation flags.
    NULL,                 // Use parent's environment block.
    NULL,                 // Use parent's starting directory.
    &si,                  // Pointer to STARTUPINFO structure.
    &pi )                 // Pointer to PROCESS_INFORMATION structure.
    )
{
    cout << "Unable to create\n";}
    // Close process and thread handles. 
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );

    return false;

}

    WaitForSingleObject( pi.hProcess, INFINITE );// wait user till close exe(after close child process then go parent process)
return true;

// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
于 2013-10-29T07:18:39.330 回答
0

可以使用 OLE-Automation / COM 轻松完成。使用进程外服务器,您有一个过程接口和第二个进程......

于 2013-10-28T09:35:48.630 回答