Before my WndProc function returns I 'xor eax, eax'

When I do this my program locks up ... kind of

I can still kill it by bringing up the Task manager and killing process

If I take this code out my program loads up just fine.

I have also seen this in Iczelion's tut 3
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_DESTROY ; if the user closes our window
invoke PostQuitMessage,NULL ; quit our application
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam ; Default message processing
ret
.ENDIF
xor eax,eax
ret
WndProc endp



I have looked at my MSDN that I have on my computer ( not at msdn.microsoft.com ) I have also searced for Icz tutorial and I haven't found anything yet.

Anyways my question is why does this crash/lock/freeze?

What is correct to return when I handle messages? Or don't handle messages?

Thanks

I didn't attach my code - its a basic Win32 skeleton
Posted on 2002-07-31 09:48:24 by gorshing
You have to return the value returned by DefWindowProc. Return values
go in EAX.
Posted on 2002-07-31 10:02:24 by f0dder
Gorshing, I see nothing wrong in your code fragment. It also works fine when I paste it into my program template. Maybe you should post your full skeleton program.
Posted on 2002-07-31 10:04:08 by Frank
I know that return values ( most ) go into eax, just didn't know why this hangs up....here is the code

Near the end I have ( like I said ) xor eax, eax. When this is uncommented it hangs when I take it out( comment ) it runs fine.
Posted on 2002-07-31 10:05:51 by gorshing
f0dder is right, you are blatting the value returned by DefWindowProc.

You need to either add a ret after the call to DefWindowProc, or
put the xor in each of the other cases:



WndProc proc hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
mov eax, uMsg
.IF eax==WM_CREATE
invoke MessageBox, NULL, offset AppName, offset AppName, MB_OK
.ELSEIF eax==WM_DESTROY
invoke PostQuitMessage, NULL
.ELSE
invoke DefWindowProc, hWnd, uMsg, wParam, lParam
ret
.ENDIF
xor eax, eax
ret
WndProc endp


Or:



WndProc proc hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
mov eax, uMsg
.IF eax==WM_CREATE
invoke MessageBox, NULL, offset AppName, offset AppName, MB_OK
xor eax, eax
.ELSEIF eax==WM_DESTROY
invoke PostQuitMessage, NULL
xor eax, eax
.ELSE
invoke DefWindowProc, hWnd, uMsg, wParam, lParam
.ENDIF
ret
WndProc endp


Mirno
Posted on 2002-07-31 10:14:40 by Mirno
Doh! my bad...thanks...I see now
Posted on 2002-07-31 10:16:26 by gorshing
but the


ret

already stood in the code when he posted it...
Posted on 2002-07-31 12:37:52 by hartyl
hartyl you are correct, the code he posted is fine. In fact thats why frank said:
Gorshing, I see nothing wrong in your code fragment. It also works fine when I paste it into my program template. Maybe you should post your full skeleton program.


And indeed when gorshing posted his actual code, and I looked at it, it turns out f0dder was right.

Thats the problem with what turn out to be "stupid" mistakes, they are so easy to miss, and are the last thing you think of to debug. They also are the kind of things you can accidentally not copy across when typing in a problem to the messageboard - and hence not actually give the problem you are trying to solve.

Mirno
Posted on 2002-07-31 13:12:12 by Mirno
To clear up the code that I had posted in my very first post was from Iczelion ... sorry to cause any confusion.


What my problem was that I didn't have a ret right after DefWindowProc
Posted on 2002-07-31 13:46:27 by gorshing