开发者

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 diffe开发者_C百科rent application?

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? (MSDN)

BOOL TerminateProcess( HANDLE hProcess, 
                       DWORD uExitCode );

You will need the HANDLE to the process which you can easily obtain using the Toolhelp32 APIs. 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 provides clean process shutdown where as TerminateProcess exit the process unconditionally. Syntax for 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 should cause the app's message pump loop to exit and subsequently terminate. 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 TerminateProcess.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜