Hi there guys
For special reasons, I've been away from the Forum
But I came back quickly
And now I have a question
how to i can trace the event of (Current Process End or Terminate),If possible, and if it exists, like WM_CLOSE or WM_DESTROY in window
I mean, in any type of programs, Console - Win32App ...
Any idea please
+ I'm sorry for my English
a debugger is the perfect tool to do that (windbg can read the dll code).
hi ToutEnMasm;
To clarify, I want a way to impose a program that invoke 'ProcEndp' when it ends
include masm32rt.inc
;.............................
.code
ProcEndp PROC
;.............................
ret
ProcEndp endp
start:
;.............................
end start
How can I impose that the procedure 'ProcEndp' will be invoked when the Process is closed by windows or when it is terminated
I want to make the Event END related by Invoke 'ProcEndp'
Is there a particular EVENT when the expiration or termination of the program
for GUI programs, there is a system of messages
http://masm32.com/board/index.php?topic=1491.msg15340#msg15340 (http://masm32.com/board/index.php?topic=1491.msg15340#msg15340)
for console mode programs, you can use SetConsoleCtrlHandler to set an event handler
http://msdn.microsoft.com/en-us/library/windows/desktop/ms686016%28v=vs.85%29.aspx (http://msdn.microsoft.com/en-us/library/windows/desktop/ms686016%28v=vs.85%29.aspx)
you could also use GetConsoleWindow to get a handle and subclass WndProc - then use the GUI methods
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683175%28v=vs.85%29.aspx (http://msdn.microsoft.com/en-us/library/windows/desktop/ms683175%28v=vs.85%29.aspx)
Or you can try the CRT atexit (http://msdn.microsoft.com/en-us/library/tze57ck3.aspx) or _onexit (http://msdn.microsoft.com/en-us/library/zk17ww08.aspx) functions. You'll need to run this code from a command prompt to see the output from the procedures.
;===============================================================================
include \masm32\include\masm32rt.inc
;===============================================================================
.data
.code
;===============================================================================
OnExit1 proc C
printf("OnExit1\n")
ret
OnExit1 endp
OnExit2 proc C
printf("OnExit2\n")
ret
OnExit2 endp
AtExit1 proc C
printf("AtExit1\n")
ret
AtExit1 endp
AtExit2 proc C
printf("AtExit2\n")
ret
AtExit2 endp
;===============================================================================
start:
;===============================================================================
; _onexit returns a pointer to the function for success, or zero for error.
; atexit returns zero for success, or non-zero for error.
invoke crt__onexit, OnExit1
printf("%d\n",eax)
invoke crt__onexit, OnExit2
printf("%d\n",eax)
invoke crt_atexit, AtExit1
printf("%d\n",eax)
invoke crt_atexit, AtExit2
printf("%d\n",eax)
inkey
exit
end start
;===============================================================================
And I get no output if I terminate the app from Task Manager.
Welcome back to the forum. :-)
You control your program, so in your message loop exit you call EndProc, then ExitProcess.
If someone else uses TerminateProcess (http://msdn.microsoft.com/en-us/library/windows/desktop/ms686714(v=vs.85).aspx), you don't get any notifications
QuoteA process cannot prevent itself from being terminated.
I thank you all
I thank you MichaelW, That's exactly what I 'm looking for, I will try if it works