gpt4 book ai didi

visual-c++ - 如何等待 ShellExecute 运行?

转载 作者:行者123 更新时间:2023-12-03 11:07:13 24 4
gpt4 key购买 nike

我设法在 VC++ 中使用 ShellExecute 来启动文档。
现在我希望运行一个命令行工具来接收一些参数,并在后台运行(隐藏的,而不是最小化的)并让它阻塞我的程序流,这样我就可以等待它完成。
如何更改以下命令行:

ShellExecute(NULL,"open",FULL_PATH_TO_CMD_LINE_TOOL,ARGUMENTS,NULL,SW_HIDE);

问题是,我有将 html 转换为 pdf 的工具,我希望一旦该工具完成,又名 pdf 准备就绪,有另一个 ShellExecute 来查看它。

最佳答案

有一个CodeProject article这显示了如何使用 ShellExecuteEx而不是 ShellExecute :

SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "c:\\MyProgram.exe";
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
CloseHandle(ShExecInfo.hProcess);

关键是标志 SEE_MASK_NOCLOSEPROCESS , 其中, as MSDN says

Use to indicate that the hProcess member receives the process handle. This handle is typically used to allow an application to find out when a process created with ShellExecuteEx terminates



另外,请注意:

The calling application is responsible for closing the handle when it is no longer needed.

关于visual-c++ - 如何等待 ShellExecute 运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17638674/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com