Chris
Chris

Reputation: 27384

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?

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.

Upvotes: 3

Views: 2758

Answers (3)

ctacke
ctacke

Reputation: 67168

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.

Upvotes: 0

Konrad
Konrad

Reputation: 40937

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.

Upvotes: 2

user001
user001

Reputation: 444

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.

Upvotes: 0

Related Questions