flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > bug with ebx when enumerating windows

Author
Thread Post new topic Reply to topic
wisepenguin



Joined: 30 Mar 2005
Posts: 129
wisepenguin
im new at assembler so this could not be a bug. its most probably
because im doing something blatantly wrong as i dont know assembly.

; ----- ----- ----- ----- -----
; HideAll_EnumProc
; hWnd at [ebp+8]
; lParam at [ebp+12]
; ----- ----- ----- ----- -----
HideAll_EnumProc:
push ebp
mov ebp, esp
sub esp, 0

; cant use EBX here, no idea why
; EAX, ECX, EDX work but not EBX
mov ecx, dword [ebp+8]

; --- wsprintf
push ecx
push sb_StatusBar_Format_String
push sb_lpzStatusBar_Buffer
call [wsprintf]

; --- message box
push MB_OK
push 0
push sb_lpzStatusBar_Buffer
push [g_hMainWindow]
call [MessageBox]

mov esp, ebp
pop ebp

mov eax, 1 ; 1 to continue
ret
; END HideAll_EnumProc

when EBX is used, only one messagebox is shown then it
stops enumerating. when ECX, EAX, EDX is used
a messagebox is brought up with each HWND of a window
because the enumeration continues.

i have no idea why it does this. is my code wrong ?
i dont really understand assembly that well yet, or
procedures.

push 1 ; lparam
push HideAll_EnumProc
push NULL
call [EnumDesktopWindows]

thats the code that starts the enumeration

thanks
Post 30 Mar 2005, 14:56
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Hi.
At first "sub esp,0" is meaningless (but harmless also).
In Windows you MUST preserve EBX, ESI, EDI and EBP (your procedure saves EBP) in every callback procedure - windows procedures, callbacks for all API fuctions that need callback pointer as a parameter.

Windows keeps some internal values in these registers and expects that they will not be changed at the exit of the procedure.

Regards.
Post 30 Mar 2005, 16:23
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
wisepenguin



Joined: 30 Mar 2005
Posts: 129
wisepenguin
thanks very much for that.
i noticed later this afternoon if i put "push ebx" after sub esp, 0
and a pop ebx after the messagebox call that it worked.
but now i know why because of your explanation, thanks.
i will have to change my procedures a bit to save those registers.

i knew about the sub esp, 0 but i left it there for me to realise if i needed
room on the stack to change it. im not that confident with using the stack
so i tend to use global variables.

regards.
Post 30 Mar 2005, 16:58
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
You'll also have to preserve the direction flag if you change it - ie, if you use "std" you will have to "cld" before returning. Stack must always be 4-byte aligned (never push word-sized data), and some structures and other data items also have to be aligned to 4-byte boundaries. You won't always see the effect of failure to adhere to these standards, it will differ between windows versions.

Also know that the register preservation rules mean that every time you call an external function, you should treat EAX,ECX,EDX as being destroyed - if you need the values in these registers across external calls, do some push/pop.
Post 30 Mar 2005, 18:05
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.