flat assembler
Message board for the users of flat assembler.

Index > Windows > Why should return zero after WM_QUIT ?

Author
Thread Post new topic Reply to topic
barmentalisk



Joined: 06 Sep 2005
Posts: 36
barmentalisk
Hi, guys, I've searched all the MSDN but can not find simple answer for my question. For example lets take portion of code from FASM's "TEMPLATE":
Code:
proc WindowProc hwnd,wmsg,wparam,lparam
       push    ebx esi edi
 cmp     [wmsg],WM_DESTROY
   je      .wmdestroy
  .defwndproc:
    invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
       jmp     .finish
  .wmdestroy:
        invoke  PostQuitMessage,0
   xor     eax,eax
  .finish:
   pop     edi esi ebx
 ret
endp
    


Why should procedure return zero, I've found only in MSDN's description of WinMain Function:
Quote:
If the function succeeds, terminating when it receives a WM_QUIT message, it should return the exit value contained in that message's wParam parameter. If the function terminates before entering the message loop, it should return zero.


But I can't understand, what does it mean "before entering the message loop" ?
Please, somebody, explain for me: which API needs this zero to correctly process WM_QUIT message?
Post 12 Jul 2009, 09:02
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:49; edited 1 time in total
Post 12 Jul 2009, 10:00
View user's profile Send private message Reply with quote
barmentalisk



Joined: 06 Sep 2005
Posts: 36
barmentalisk
But GetMessage returns 0 itself when recieved WM_QUIT, why should put 0 to eax after PostQuitMessage ?
Post 12 Jul 2009, 10:30
View user's profile Send private message Reply with quote
barmentalisk



Joined: 06 Sep 2005
Posts: 36
barmentalisk
OK, I see in description of WM_DESTROY messge:
"If an application processes this message, it should return zero. "

But who process this zero? DispatchMessage ?
Post 12 Jul 2009, 10:46
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:49; edited 1 time in total
Post 12 Jul 2009, 11:00
View user's profile Send private message Reply with quote
barmentalisk



Joined: 06 Sep 2005
Posts: 36
barmentalisk
AFAIK GetMessage does not get the result of processing message - DispatchMessage does it.
Am I right?
Post 12 Jul 2009, 13:39
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:49; edited 1 time in total
Post 12 Jul 2009, 14:38
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:49; edited 1 time in total
Post 12 Jul 2009, 14:39
View user's profile Send private message Reply with quote
barmentalisk



Joined: 06 Sep 2005
Posts: 36
barmentalisk
I know it all.
GetMessage results in zero if gets WM_QUIT.
I wonder why must mov NULL to eax after invoking PostQuitMessage ?
I even know that it is a recomendation from MSDN.
But how it works?

That zero is a return value when returning from WindowProc,
WindowProc is called by DispatchMessage,
so DispatchMessge takes this value...
and what will be if returning value is not zero?
Post 12 Jul 2009, 18:24
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
barmentalisk,

Probably the answer lies in Win32K.Sys. I think, WindowProc's return value is silently ignored; perhaps it was important in pre-Win32 era (cooperative multitasking?).
Post 16 Jul 2009, 17:02
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
When you push a value for PostQuitMessage the system
sets up for WM_QUIT and places that value in MSG::wParam
This is only really useful if the process was spawned and
the parent process would like to get an exit code from its child.
GetMessage will return zero upon WM_QUIT but PeekMesage will not.
As for WindowProc return value it is not ignored but determines required action.
Most of the time we return zero to indicate that no further processing
is needed but other times returning one or a value to customize handling.
There are very few undocumented cases which you never may use.
Post 18 Jul 2009, 02:11
View user's profile Send private message 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. Also on YouTube, Twitter.

Website powered by rwasa.