News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

New Proc Call makes RunTime crash

Started by Samishii23, September 13, 2010, 03:42:53 PM

Previous topic - Next topic

Samishii23

I've been running myself through This 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)

redskull

Strange women, lying in ponds, distributing swords, is no basis for a system of government

Samishii23

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

redskull

Strange women, lying in ponds, distributing swords, is no basis for a system of government

Samishii23

Oh thats right... Isn't that something to do with WIN32 developement? lol

Samishii23