The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Samishii23 on September 13, 2010, 03:42:53 PM

Title: New Proc Call makes RunTime crash
Post by: Samishii23 on September 13, 2010, 03:42:53 PM
I've been running myself through This (http://win32assembly.online.fr/tut4.html) tutorial lately, and after fixing assembler issues, and cleaning up their "Base Line Windows" code to be nicer on the eyes (while checking that it still worked every minute or so)...

I am on Basic screen Painting. So I got the code:
LOCAL hdc:HDC
LOCAL ps:PAINTSTRUCT
LOCAL rect:RECT

invoke BeginPaint, hWnd, ADDR ps
mov hdc, eax
invoke GetClientRect, hWnd, ADDR rect
invoke DrawText,\  ; Paint Text to Screen
hdc,\          ; Paint Handle
ADDR OurText,\ ; String text to draw
-1,\           ; Number of char to output. -1 if string was null terminated
ADDR rect,\    ; Pointer to rect struc
DT_SINGLELINE or DT_CENTER or DT_VCENTER

invoke EndPaint, hWnd, ADDR ps


In the tutorial it puts this code into the message handler procedure.
I moved it out into a separate procedure.
Program crashes at runtime.
So I put all the code back into the message handler, and it doesn't crash. And it compiles fine...

Heres the exact code thats crashing... ( Proc's placed in this order inside code )
WndPaintTxt proc hWnd:HWND
LOCAL hdc:HDC
LOCAL ps:PAINTSTRUCT
LOCAL rect:RECT

invoke BeginPaint, hWnd, ADDR ps
mov hdc, eax
invoke GetClientRect, hWnd, ADDR rect
invoke DrawText,\  ; Paint Text to Screen
hdc,\          ; Paint Handle
ADDR OurText,\ ; String text to draw
-1,\           ; Number of char to output. -1 if string was null terminated
ADDR rect,\    ; Pointer to rect struc
DT_SINGLELINE or DT_CENTER or DT_VCENTER

invoke EndPaint, hWnd, ADDR ps
WndPaintTxt endp

; Message Handler
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
; WM_DESTROY = Shut Down Program
; WM_PAINT = Repainting of the window
.if uMsg==WM_DESTROY
invoke PostQuitMessage, NULL
.elseif uMsg==WM_PAINT
invoke WndPaintTxt, hWnd
.else
invoke DefWindowProc, hWnd, uMsg, wParam, lParam ; Return unproccessed messages
ret
.endif
xor eax, eax
ret
WndProc endp


Included ASM file in attachment (Code, minus all the comments, can be seen in the above link)
Title: Re: New Proc Call makes RunTime crash
Post by: redskull on September 13, 2010, 03:47:03 PM
see if frktons knows... :bg
Title: Re: New Proc Call makes RunTime crash
Post by: Samishii23 on September 13, 2010, 04:19:52 PM
When I put the WndPaintTxt Procedure before the window register and creation procedure, it opens up 38+ windows, all of them DO NOT CRASH...
But when I put the WndPaintTxt proc under the window register and create... It crashes. Ugh
Title: Re: New Proc Call makes RunTime crash
Post by: redskull on September 13, 2010, 04:31:09 PM
The problem is the 'ret', or more accuratly the lack of one.

http://www.masm32.com/board/index.php?topic=14807.0

-r
Title: Re: New Proc Call makes RunTime crash
Post by: Samishii23 on September 13, 2010, 04:48:23 PM
Oh thats right... Isn't that something to do with WIN32 developement? lol
Title: Re: New Proc Call makes RunTime crash
Post by: Samishii23 on September 13, 2010, 05:06:02 PM
Beautiful! Thanks for the help!  :U