Terminating a Process

There are rare occasions when you will need to terminate another process from your application. Calling TerminateProcess does this.

DWORD dwExitCode = 1;
if(TerminateProcess(hProcess, dwExitCode))
  cout ≪ _T("Process Terminated");

The function TerminateProcess is passed the handle of the process to terminate as the first parameter and a DWORD containing the exit code to use for the process. The process being terminated does not have the opportunity to set an exit code, so one must be provided.

You should avoid calling TerminateProcess, since DLLs being used by the process do not have DllMain called with the reason code DLL_PROCESS_ DETACH. Therefore, the DLLs cannot free resources they are using and resource or memory leaks ...

Get Windows® CE 3.0 Application Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.