News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Process End

Started by mabdelouahab, October 24, 2014, 08:48:31 AM

Previous topic - Next topic

mabdelouahab

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

TouEnMasm

a debugger is the perfect tool to do that (windbg can read the dll code).
Fa is a musical note to play with CL

mabdelouahab

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'

mabdelouahab

Is there a particular EVENT when the expiration or termination of the program

dedndave

for GUI programs, there is a system of messages

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

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

MichaelW

Or you can try the CRT atexit or _onexit 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.
Well Microsoft, here's another nice mess you've gotten us into.

Magnum

Welcome back to the forum. :-)
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

sinsi

You control your program, so in your message loop exit you call EndProc, then ExitProcess.
If someone else uses TerminateProcess, you don't get any notifications
QuoteA process cannot prevent itself from being terminated.

mabdelouahab

I thank you all
I thank you MichaelW, That's exactly what I 'm looking for, I will try if it works