Article View: borland.public.cppbuilder.nativeapi
Article #14572Re: CreateProcess and ExitProcess woes
From: Remy Lebeau (TeamB)
Date: Thu, 07 Aug 2003 17:58
Date: Thu, 07 Aug 2003 17:58
42 lines
3010 bytes
3010 bytes
"Mark D" <m.davenCROPHEREport@ntlworld.com> wrote in message
news:3f322e37$1@newsgroups.borland.com...
> How about TerminateProcess().
TerminateProcess() will work, however keep in mind that it is a brute-force
termination that will not allow the spawned process to clean up correctly.
Microsoft warns of this situation in the documentation:
"The TerminateProcess function is used to unconditionally cause a
process to exit. Use it only in extreme circumstances. The state of global
data maintained by dynamic-link libraries (DLLs) may be compromised if
TerminateProcess is used rather than ExitProcess.
TerminateProcess causes all threads within a process to terminate, and
causes a process to exit, but DLLs attached to the process are not notified
that the process is terminating. "
> If so I use the suggested window enumeration to find all
> windows associated with the spawned process
That is preferred whenever possible. If the spawned process has windows
associated with it, then a more graceful terminate would involve using
EnumWindows(), GetWindowThreadProcessId() and WM_CLOSE/WM_QUIT to send
messages to all of the windows belonging to the spawned process ID.
The tricky part is when theprocess doesn't have any windows, though, such as
command-line utilities.
> or have an idle loop running in the called process which waits
> for the main app to execute, and then kills itself.
That requires the two processes (yours and the spawned one) to have
knowledge of each other, as well as the fact that you would have to be
writing the spawned program yourself to begin with (or by someone who knows
you). If they are always your own programs, then you can do whatever you
want. But, you can't rely on that approach for spawning any arbitrary
process, as most programs are not programmed to work that way.
Gambit
Technical Details
Message-ID:
<3f3291dd$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!t-online.de!newsfeed.freenet.de!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3f31016b@newsgroups.borland.com> <3f3130f6$1@newsgroups.borland.com> <3f322e37$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,e076c50d5b2e440a X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-08-07 11:02:30 PST From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f31016b@newsgroups.borland.com> <3f3130f6$1@newsgroups.borland.com> <3f322e37$1@newsgroups.borland.com> Subject: Re: CreateProcess and ExitProcess woes Date: Thu, 7 Aug 2003 10:58:49 -0700 Lines: 44 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 207.175.226.26 Message-ID: <3f3291dd$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1060278749 207.175.226.26 (7 Aug 2003 10:52:29 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!t-online.de!newsfeed.freenet.de!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail