Skip to main content
gamedev.net
🔒 Locked

Question About TerminateProcess

Started by aboeing Sep 19, 2005 at 10:40 PM 1 replies 1.4k views
Original Post
aboeing
aboeing
Hi, I was having a problem with my program crashing after main did its: return 0; I realise this is because of some dodgy code I'd written, but I managed to 'eliminate' the problem by doing this: TerminateProcess(GetCurrentProcess(),0); I get the feeling this is a really bad idea, but I don't actually know why. (Is it?) Would anyone be able to explain what the difference between:

int main(int argc, char *argv[]) {
 return 0;
}
//and
int main(int argc, char *argv[]) {
 TerminateProcess(GetCurrentProcess(),0);
 return 0; //doesn't get executed
}
is? Thanks! // edit - added some white space to the title
LessBread
LessBread
According to the docs for TerminateProcess:

Quote:

The TerminateProcess function is used to unconditionally cause a process to exit. The state of global data maintained by dynamic-link libraries (DLLs) may be compromised if TerminateProcess is used rather than ExitProcess.

TerminateProcess initiates termination and returns immediately. This stops execution of all threads within the process and requests cancellation of all pending I/O. The terminated process cannot exit until all pending I/O has been completed or canceled.

A process cannot prevent itself from being terminated.


Among other things, TerminateProcess doesn't notify attached dlls that the process is terminating.

You might find these articles helpful.

A Safer Alternative to TerminateProcess

How To Terminate an Application "Cleanly" in Win32

Processes: How can I kill a process?

"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
aboeing
aboeing
Thanks for the links. "A Safer Alternative to TerminateProcess" required WDN registration, but looks good.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.