flat assembler
Message board for the users of flat assembler.

Index > Windows > exiting programs directly, without PostQuitMessage ?

Author
Thread Post new topic Reply to topic
Slai



Joined: 11 Jan 2006
Posts: 40
Location: NY/Bulgaria
Slai
Is it ok if I dont restore the previous condition of the stack pointer when I exit the program ? I tryed using directly ExitProcess instead of PostQuitMessage without poping ebx esi edi and it worked, so I guess Windows restores esp anyways? What are the risks if I exit this way?
Code:
include '%include%/win32a.inc'
;        invoke  GetModuleHandle,0
        invoke  DialogBoxParam,eax,0,HWND_DESKTOP,DialogProc,0

proc DialogProc uses ebx esi edi ,hwnd,msg,wparam,lparam
        cmp     [msg],WM_CLOSE 
        je      close
        xor     eax,eax 
        ret
 close: invoke  ExitProcess,0
endp

data resource ;section '.rsrc' resource data readable
    directory RT_DIALOG,dialog0
        resource dialog0,0,LANG_ENGLISH+SUBLANG_DEFAULT,demonstration
    dialog demonstration,'Create message box',0,0,400,300,WS_VISIBLE+WS_SYSMENU+WS_MAXIMIZEBOX+WS_MINIMIZEBOX+WS_THICKFRAME+DS_CENTER,2
    enddialog
end data
data import ;section '.import' import data readable writeable
  library kernel32,'KERNEL32.DLL', user32,'USER32.DLL'
  include '%apia%\kernel32.inc'
  include '%apia%\user32.inc'
end data    
Post 01 Sep 2006, 10:59
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
shoorick
correct way to close dialog box is using of EndDialog, and ExitProcess has to be placed after DialogBoxParam. otherwise everything depends on capabilities of OS to clear all resources by process. some controls may allocate memory or other resources, and should be closed correctly to release all of them - this will be done by default dialog procedure. You may feel visually ok just because your program is extremelly lite, but this way is incorrect.
Post 01 Sep 2006, 11:14
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
shoorick
btw, is it working example with commented GetModuleHandle? Wink
Post 01 Sep 2006, 11:16
View user's profile Send private message Visit poster's website Reply with quote
Slai



Joined: 11 Jan 2006
Posts: 40
Location: NY/Bulgaria
Slai
Yes it works without it. There was a thread in here that was discussing the use of GetModuleHandle, and I didn't saw an satisfying aswer why it should be used, but I guess it should be used for compability isues ..
I know about the correct way to close a dialog, I was just curious how incorect is this one. So exiting this way may leave resources in the memory and make this memory unusable by the other programs ?
Post 01 Sep 2006, 17:21
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
shoorick
So exiting this way may leave resources in the memory and make this memory unusable by the other programs > yes
Post 04 Sep 2006, 05:13
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
shoorick wrote:
So exiting this way may leave resources in the memory and make this memory unusable by the other programs > yes


Nope. Windows does cleanup when your process terminates. The only thing you have to be vary of is GDI stuff if you want to support win9x - win9x is a leaky piece of shit that doesn't handle stuff well.

_________________
Image - carpe noctem
Post 04 Sep 2006, 11:12
View user's profile Send private message Visit poster's website Reply with quote
Slai



Joined: 11 Jan 2006
Posts: 40
Location: NY/Bulgaria
Slai
I goth both, expected and satisfying answers Smile. Thank you. I guess it's best if I dont use this direct exiting, for any case :], and because I have some GDI stuff for changing the font colour.
Post 05 Sep 2006, 01:45
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
shoorick
Windows does cleanup when your process terminates
i will not insist on opposite, but there are could be controls on dialog which may create some global/shareable/COM etc. objects which can be left after process has been terminated. editbox, btw, allocates memory in global memory (to be compatible with win3x i think, unless it has DS_LOCALEDIT style).
Post 05 Sep 2006, 04:54
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
"There is no such thing as global memory on win32", especially not NT. Closest you come would be named memory mapped files, but those should be cleaned up even on TerminateProcess. And ExitProcess is even cleaner than that.

Or perhaps you know something I don't Smile
Post 05 Sep 2006, 06:01
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
shoorick
Or perhaps you know something I don't > i do not think so Very Happy
just prefer to be sure then hope. btw, it is possible exit window proc with "retn" instead "retn 16" (whole byte economy Smile ), but i do not think somebody does like this Wink
Post 05 Sep 2006, 06:54
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.