🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages Started by Binzhong Zhou Tue, 28 Mar 2006 04:12
Terminate Process started by CreateProcess
#4081
Author: Binzhong Zhou
Date: Tue, 28 Mar 2006 04:12
8 lines
1222 bytes
Could some one tell how I can safely terminate an application started by 
CreateProcess? I want to kill all the processes started from my application 
before I exit my application. When you kill the process, it may still work, 
say play a movie or song. Based on the help, TerminateProcess is  obviously 
not recommanded. What is alternative?

Thanks,
        Binzhong 
Re: Terminate Process started by CreateProcess
#4083
Author: JD
Date: Tue, 28 Mar 2006 09:41
28 lines
1986 bytes
"Binzhong Zhou" <Binzhong.Zhou@csiro.au> wrote:
>
> Could some one tell how I can safely terminate an application
> started by CreateProcess?

If you look in the win32.hlp file for CreateProcess and
examine the LPPROCESS_INFORMATION parameter, you'll see that
that pointer is used to pass back information about the new
process in the form of a PROCESS_INFORMATION structure which
has a dwProcessId member that you can use to accomplish what
you want.

When your application closes, use the win32 API EnumWindows to
enumerate all of the windows. In the callback function for
EnumWindows, use the win32 API GetWindowThreadProcessId and
compare the returned ID to the dwProcessId member of the
PROCESS_INFORMATION structure and if they match then use the
win32 API SendMessage to send a WM_CLOSE message to that
window.

> [...] Based on the help, TerminateProcess is  obviously
> not recommanded. What is alternative?

If any of the processes do not have a window, you'll have to
brute force it with TerminateProcess.

~ JD
Re: Terminate Process started by CreateProcess
#3984
Author: Remy Lebeau (TeamB)
Date: Tue, 28 Mar 2006 11:29
13 lines
1200 bytes
"Binzhong Zhou" <Binzhong.Zhou@csiro.au> wrote in message
news:4428b7bf$1@newsgroups.borland.com...

> Could some one tell how I can safely terminate an application
> started by CreateProcess?

Use EnumWindows() and GetWindowThreadProcessId() to find any windows that
belong to the spawned process, and send them all a WM_CLOSE or WM_QUIT
message.


Gambit
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads