flat assembler
Message board for the users of flat assembler.

Index > Windows > DialogBox problem

Author
Thread Post new topic Reply to topic
Evgeny



Joined: 16 Jan 2006
Posts: 11
Evgeny
What's wrong with this code?

Code:
        format  pe gui 4.0
        entry   start
        include 'win32a.inc'

start:  invoke  GetModuleHandle,0
        invoke  DialogBoxParam,eax,101,0,MainDlgProc,eax
        invoke  ExitProcess,eax

MainDlgProc:
        cmp     dword[esp+0x08],\       ;ESP+0x08: DialogProc.uMsg.
                WM_INITDIALOG

        jz      .init

;***************************************;
        nop                             ;Try to (un)comment this.
;***************************************;

        xor     eax,eax                 ;Return 0.
        ret     0x10                    ;4 parameters * 4 bytes.

.init:  xor     eax,eax
        inc     eax                     ;Return 1.
        ret     0x10                    ;4 parameters * 4 bytes.


        data    import
        library kernel32,'KERNEL32.DLL',\
                user32,'USER32.DLL'
        include 'apia/kernel32.inc'
        include 'apia/user32.inc'
        end     data

        data    resource from 'res/main.res'
        end     data
    


Description:
Download
Filename: src16012006.zip
Filesize: 1.66 KB
Downloaded: 60 Time(s)

Post 16 Jan 2006, 15:03
View user's profile Send private message Reply with quote
FrozenKnight



Joined: 24 Jun 2005
Posts: 128
FrozenKnight
The first thing i noticed is that your dialog has no handlers for closing the window. i had about one million problems when i didn't process the WM_CLOSE message.

also your not saving your esp to ebp.
and i believe the value for uMsg should be +0x0C not +0x08. +0x08 is your wParam.

i personally like ot copy the uMsg into eax then rum my checks then have the program smoothly run into my unhandled message processor.
Post 16 Jan 2006, 20:55
View user's profile Send private message Reply with quote
Evgeny



Joined: 16 Jan 2006
Posts: 11
Evgeny
Quote:
The first thing i noticed is that your dialog has no handlers for closing the window.

I've removed that code when I searched for error.

Quote:
also your not saving your esp to ebp.

Saving ESP to EBP (creating stack frame) is usually done to simplify access to local variables. I have no local variables, so…

Quote:
and i believe the value for uMsg should be +0x0C not +0x08. +0x08 is your wParam.

Why? I'm addressing via esp, not ebp (and even when addressing via ebp [ebp+0x08] will be hWndDlg, not wParam!):
Code:
[esp+0x00] ;Return address.
[esp+0x04] ;1st parameter (hWndDlg).
[esp+0x08] ;2nd parameter (uMsg).
[esp+0x0c] ;3rd parameter (wParam).
[esp+0x10] ;4th parameter (lParam).    


Quote:
i personally like ot copy the uMsg into eax

Thanks, I know how to write good-style WindowProc's and DialogProc's.

But the question was: why my code doesn't work, when nop is uncommented? On WinXP DialogProc returns 0xffffffff (and GetLastError reports, that class was not found), on Win98 it causes divide error in USER.EXE. Why? Smile

[added] Hmm… I've placed dialog resource into separate section and now it works ok. But why? Surprised
Post 17 Jan 2006, 06:08
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
shoorick
your program works occasionally
you do not restore stack before leaving window proc:
should be:

leave
ret 0x10

(do not mess with ret macro in procedure defined with proc macro)
regards!
======
i was wrong: you did not made frame - then i do not know Wink
======
add 2: the thing is aligning - after added "align 32" before import and resources everything start to work with nop and without (32 - i do not know exact needed aligning for such data - can be less then 32)
regards!
Post 17 Jan 2006, 06:33
View user's profile Send private message Visit poster's website Reply with quote
Evgeny



Joined: 16 Jan 2006
Posts: 11
Evgeny
I've just downloaded fasm v1.65.8 and now it works. Problem was in fasm v1.64?
Post 17 Jan 2006, 06:46
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
shoorick
i still use 1.64 (a while). your example with aligning works in 1.64 - i tested. maybe "data" macro in 1.65 has aligning inside - just do not know yet.

regards!
Post 17 Jan 2006, 06:51
View user's profile Send private message Visit poster's website Reply with quote
FrozenKnight



Joined: 24 Jun 2005
Posts: 128
FrozenKnight
Sorry about the confused post i was kind of tired. i only scanned it anc compared it to a disasembly of one of my programs the 0x0C is correct when you push ebp onto the stack like i did :/
Post 17 Jan 2006, 09:25
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
AFAIK resources must be aligned to some fixed value. You were just lucky once, beacuse without nop the alignment was ok. This one byte 0x90 crashed the program.
Post 17 Jan 2006, 13:46
View user's profile Send private message Visit poster's website 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.