进程的返回值
如何获取进程的返回值? 基本上我是 **ShellExecute( )**从 DLL 中创建 .NET 进程(在 C++ 中)。 该进程执行其任务,但现在我想知道它是成功还是失败。 如何在 WinAPI 或 MFC 中做到这一点?
How can I get the return value of a process? Basically I'm **ShellExecute()**ing a .NET process from a DLL (in C++). The process does its task, but now I want to know whether it succeeded or failed. How to do that in WinAPI or MFC?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用CreateProcess()。 保留进程句柄,并在进程句柄发出信号时调用 GetExitCodeProcess()。
Use CreateProcess(). keep the process handle and call GetExitCodeProcess() when the process handle becomes signalled.
使用
ShellExecuteEx
代替,这样你就可以得到已启动进程的句柄。 然后,您应该能够使用GetExitCodeProcess
获取退出代码。(尽管 MSalters 也有类似的答案,但我还是在这里留下了这个答案,因为我怀疑您故意使用 ShellExecute 来获取 shell 行为,而不是显式创建进程。)
Use
ShellExecuteEx
instead so you can get a handle to the process which was launched. You should then be able to useGetExitCodeProcess
to obtain the exit code.(I've left this answer here despite the similar one from MSalters, as I suspect you're using
ShellExecute
deliberately to get the shell behaviour instead of explicitly creating the process.)ShellExecute() 在其本机中是 16 位调用,因此它并不旨在提供反馈/回调,尽管您可以 saerch 线程/进程/内存地址(如果您找到可用内存空间)及其标志(如果没有这样的像血腥标志这样的东西,WinAPI(32 位)将比现在简单得多)。
要提供完整的反馈,您可以尝试扩展版本或纯 32 位函数的 CreateProcess() 函数。
不幸的是,我无法向您提供有关标志/Lparameters 和其他 API 参数的任何详细信息。
此外,主要所有执行函数/过程/方法都返回布尔值,因此您始终可以从 [if..then] 语句作为返回提供者开始。
哦,当我写这篇文章时,已经做出了三个答案。
ShellExecute() in its native is 16-bit call, so it is not intended to give feedback / callback althought you can saerch thread / process / memory adress ( if you locate usable memory space ) and its flags ( if there would be no such a thing as bloody flags, WinAPI (32-bit) would be much simpatic than it is now ).
To provide full feedback, you can try extended version or CreateProcess() function with is pure 32-bit function.
Unfourtinately I cannot give you any detailed info about flags / Lparameters and other API parameters.
Besides, mainly all executive function/procedures/methods retur booleans, so you always can start with [if..then] statement as return provider.
Opps, while i was writing this, already three answers were made.