简体   繁体   English

强制应用程序使用C ++在Windows CE上关闭

[英]Force application to close on Windows CE using C++

How can I force an application, say myapp.exe , to close using C++ on Windows CE from a different application? 我如何强制一个应用程序,比如myapp.exe ,在不同的应用程序上使用Windows CE上的C ++关闭?

The scenario is that I have a previous installation of some software that does not behave properly when upgrading to a new version. 这种情况是我之前安装的某些软件在升级到新版本时行为不正常。 I therefore need to kill a process (from the updater) before continuing the update. 因此,我需要在继续更新之前终止进程(来自更新程序)。

TerminateProcess? 了TerminateProcess? ( MSDN ) MSDN

BOOL TerminateProcess( HANDLE hProcess, 
                       DWORD uExitCode );

You will need the HANDLE to the process which you can easily obtain using the Toolhelp32 APIs. 您将需要使用Toolhelp32 API轻松获取的过程的HANDLE An eample of their use to enumerate all processes on the system can be found here . 可以在此处找到它们用于枚举系统上所有进程的示例。

I think ExitProcess is more systematic approach than TerminateProcess. 我认为ExitProcess比TerminateProcess更系统化。 ExitProcess provides clean process shutdown where as TerminateProcess exit the process unconditionally. ExitProcess提供干净的进程关闭,因为TerminateProcess无条件地退出进程。 Syntax for ExitProcess: ExitProcess的语法:

VOID ExitProcess(
  UINT uExitCode
);

For more information please visit this link. 有关更多信息,请访问链接。

It totally depends on your application how it wants to exit. 这完全取决于您的应用程序如何退出。

The first thing to do is to send it a WM_QUIT to see if it might close down gracefully. 首先要做的是发送一个WM_QUIT来查看它是否可以正常关闭。 WM_QUIT should cause the app's message pump loop to exit and subsequently terminate. WM_QUIT应该导致应用程序的消息泵循环退出并随后终止。 This should allow the app to clean up it's resources cleanly. 这应该允许应用程序干净地清理它的资源。

If that fails, (and only after it fails) then you can use the toolhelp APIs to find the process (create a snapshot using NOHEAPS, then iterate to find it with First/Next calls) and terminate it using T erminateProcess . 如果失败,(并且只有在失败之后),那么您可以使用toolhelp API查找进程(使用NOHEAPS创建快照,然后迭代以使用First / Next调用找到它)并使用T erminateProcess终止它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM