【发布时间】:2014-12-09 10:56:47
【问题描述】:
我知道 system() 内部调用“CreateProcess()”。
但从应用程序的角度来看,我发现它与它的用法有 1 个主要区别。 让我们看下面的示例代码sn-p。
VC++代码sn-p::
Main()
{
//Line 1 code....
//Line2 code.....
............
CreateProcess(); // Used to launch some app which needs to be kept running till the entire //program finishes.
LaunchWindowsMediaPlayer();
...
}
}
Main()
{
//Line 1 code....
//Line2 code.....
............
std::system(); // // Same as above -- Used to launch some app which needs to be kept running //till the entire program finishes.
LaunchWindowsMediaPlayer();
...
}
CreateProcess() 用法:
如第一个代码 sn-p 中给出的,如果我在此代码中调用“CreateProcess(),那么在启动应用程序 uisng CreateProcess() 后,控件会立即进入下一行并调用 LaunchWindowsMediaPlayer();。
但在 system()(第二个代码 sn-p)的情况下,只有在 system(0 应该执行的操作完成后,控制才从 system() 返回。
但是假设您有一个用例,其中您需要运行一些需要在整个代码中保持运行的帮助应用程序,那么使用 system() API 是不可能的。
有没有办法使用 system() API 实现这一点?
【问题讨论】:
标签: c++ visual-c++ system std createprocess