flat assembler
Message board for the users of flat assembler.

Index > Windows > bug in me or fasm macros

Author
Thread Post new topic Reply to topic
m



Joined: 28 Dec 2006
Posts: 304
Location: in
m
Error is explained in the code:
Code:

        include 'win32axp.inc'

        .data
_hpen dd 0
_class db 'FooClass',0
_title db 'Foo',0

        .code
proc wndProc hWnd, umsg, wpar, lpar
 local ps:PAINTSTRUCT
 local rect:RECT
 local hdc:DWORD
        .if [umsg] = WM_PAINT
                invoke BeginPaint, [hWnd], addr ps
                mov [hdc], eax
                invoke GetClientRect, [hWnd], addr rect
                inc [rect.left]
                inc [rect.top]
                dec [rect.right]
                dec [rect.bottom]
                invoke Ellipse, [hdc], [rect.left], [rect.top], [rect.right], [rect.bottom]
                invoke EndPaint, [hWnd], addr ps
        .elseif [umsg] = WM_DESTROY
                invoke PostQuitMessage, 0
        .else
                invoke DefWindowProc, [hWnd], [umsg], [wpar], [lpar]
                ret
        .endif
        xor eax, eax
        ret
endp

proc start
 local wcx:WNDCLASSEX
 local msg:MSG

; Uncomment the following line and program stops working. Why?
; Well it still compiles and executes, but window does not show up. Why?
; I am foxed !

; local hwnd:DWORD ; *** This line causes error ***

        mov [wcx.cbSize], sizeof.WNDCLASSEX
        mov [wcx.style], CS_HREDRAW+CS_VREDRAW
        mov [wcx.lpfnWndProc], wndProc
        invoke GetModuleHandle, NULL
        mov [wcx.hInstance], eax
        invoke LoadIcon, 0, IDI_APPLICATION
        mov [wcx.hIcon], eax
        mov [wcx.hIconSm], eax
        invoke LoadCursor, 0, IDC_ARROW
        mov [wcx.hCursor], eax
        mov [wcx.hbrBackground], COLOR_WINDOW+1
        mov [wcx.lpszMenuName], NULL
        mov [wcx.lpszClassName], _class

        invoke RegisterClassEx, addr wcx
        invoke CreateWindowEx, 0, _class, _title, WS_OVERLAPPEDWINDOW, \
               20, 20, 400, 300, 0, 0, [wcx.hInstance], 0
        invoke ShowWindow, eax, SW_NORMAL
        .while TRUE
                invoke GetMessage, addr wcx, 0, 0, 0
                .if eax = 0
                        invoke ExitProcess, 0
                .endif
                invoke TranslateMessage, addr wcx
                invoke DispatchMessage, addr wcx
        .endw
endp

.end start

    

_________________
Attitude!
Post 03 Jun 2007, 01:04
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
Your problem is the variables.

Code:
        include 'win32axp.inc'

        .data 
_hpen dd 0 
_class db 'FooClass',0 
_title db 'Foo',0
 wcx WNDCLASSEX
 msg MSG

        .code 
proc wndProc hWnd, umsg, wpar, lpar 
 local ps:PAINTSTRUCT 
 local rect:RECT 
 local hdc:DWORD 
        .if [umsg] = WM_PAINT 
                invoke BeginPaint, [hWnd], addr ps 
                mov [hdc], eax 
                invoke GetClientRect, [hWnd], addr rect 
                inc [rect.left] 
                inc [rect.top] 
                dec [rect.right] 
                dec [rect.bottom] 
                invoke Ellipse, [hdc], [rect.left], [rect.top], [rect.right], [rect.bottom] 
                invoke EndPaint, [hWnd], addr ps 
        .elseif [umsg] = WM_DESTROY 
                invoke PostQuitMessage, 0 
        .else 
                invoke DefWindowProc, [hWnd], [umsg], [wpar], [lpar] 
                ret 
        .endif 
        xor eax, eax 
        ret 
endp 

proc start

; Uncomment the following line and program stops working. Why? 
; Well it still compiles and executes, but window does not show up. Why? 
; I am foxed ! 

; local hwnd:DWORD ; *** This line causes error *** 

        mov [wcx.cbSize], sizeof.WNDCLASSEX 
        mov [wcx.style], CS_HREDRAW+CS_VREDRAW 
        mov [wcx.lpfnWndProc], wndProc 
        invoke GetModuleHandle, NULL 
        mov [wcx.hInstance], eax 
        invoke LoadIcon, 0, IDI_APPLICATION 
        mov [wcx.hIcon], eax 
        mov [wcx.hIconSm], eax 
        invoke LoadCursor, 0, IDC_ARROW 
        mov [wcx.hCursor], eax 
        mov [wcx.hbrBackground], COLOR_WINDOW+1 
        mov [wcx.lpszMenuName], NULL 
        mov [wcx.lpszClassName], _class 

        invoke RegisterClassEx, addr wcx 
        invoke CreateWindowEx, 0, _class, _title, WS_OVERLAPPEDWINDOW, \ 
               20, 20, 400, 300, 0, 0, [wcx.hInstance], 0 
        invoke ShowWindow, eax, SW_NORMAL 
        .while TRUE 
                invoke GetMessage, addr wcx, 0, 0, 0 
                .if eax = 0 
                        invoke ExitProcess, 0 
                .endif 
                invoke TranslateMessage, addr wcx 
                invoke DispatchMessage, addr wcx 
        .endw 
endp 

.end start 
    


Just move them to where i put them and it's all fine.
Post 03 Jun 2007, 01:50
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
m



Joined: 28 Dec 2006
Posts: 304
Location: in
m
I am even more confused now ! ! !
Why I have to do that ?
As an aside, I have run the same code in MASM32, without a problem !
Post 03 Jun 2007, 02:03
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
FASMFORMAT != MASMFORMAT
Post 03 Jun 2007, 02:10
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
m



Joined: 28 Dec 2006
Posts: 304
Location: in
m
Thank you, Mr. Kohlrak !

The high-level-macros of fasm always confuse me.
I feel more comfortable, without them (macros) !
Post 03 Jun 2007, 02:53
View user's profile Send private message Reply with quote
Yardman



Joined: 12 Apr 2005
Posts: 245
Location: US
Yardman
[ Post removed by author. ]


Last edited by Yardman on 04 Apr 2012, 02:14; edited 1 time in total
Post 03 Jun 2007, 03:09
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
I've never used those macro, so i'm not 100% sure, but theoretically the code gets placed in the execution area, which if placed carefully could give the right spots the values they need to work, but dangerously.
Post 03 Jun 2007, 03:42
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
Yardman



Joined: 12 Apr 2005
Posts: 245
Location: US
Yardman
[ Post removed by author. ]


Last edited by Yardman on 04 Apr 2012, 02:15; edited 1 time in total
Post 03 Jun 2007, 04:46
View user's profile Send private message Reply with quote
m



Joined: 28 Dec 2006
Posts: 304
Location: in
m
Yardman is right ! Changing the order or variables did help me!
And if I completely ignore the macros available with fasm, I do feel the the guilt, but my programs work just fine, and are in my total control.

T.G. should check his macros (may be), cause I never dared to even try to do something like understanding his macros.
Post 03 Jun 2007, 11:29
View user's profile Send private message Reply with quote
asmfan



Joined: 11 Aug 2006
Posts: 392
Location: Russian
asmfan
Macro is allright. Just as Yardman said the problem is in clearing local vars (the space where esp points). With different sequence of params some portion of local space is initially equal to zero but some not. And calling api funcs that receive pointers on structs we must remember that those structs (or some field of struct e.g. size) should be initialized with values from documentation (e.g. MSDN) or with zeros at least.
Post 03 Jun 2007, 12:05
View user's profile Send private message Reply with quote
m



Joined: 28 Dec 2006
Posts: 304
Location: in
m
It was a BUG in me.
Post 20 Jul 2007, 13:31
View user's profile Send private message Reply with quote
FrozenKnight



Joined: 24 Jun 2005
Posts: 128
FrozenKnight
i agree it is nice to know how to do the same thing without macros. but the macros make it much easier. (PS. i have been avoiding using local in a large number of my apps to try to get a better idea of local memory management. just i wish i knew how the macros worked so dynamically.)
Post 22 Jul 2007, 08:30
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.

Powered by rwasa.