在实际的开发中会遇到这样的情况。
A进程在运行时,需要调起B进程完成某些工作(例如取回关键文件),且必须等待该进程完成工作结束后才能往下继续
那么这时候,就可以采用ShellExecuteEx和WaitForSingleObject的结合对被调用进程进行同步,等待被调进程结束后继续,示例代码如下:
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "notepad.exe";
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);