flat assembler
Message board for the users of flat assembler.
Index
> Compiler Internals > bug with ebx when enumerating windows |
Author |
|
JohnFound 30 Mar 2005, 16:23
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. |
|||
30 Mar 2005, 16:23 |
|
wisepenguin 30 Mar 2005, 16:58
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. |
|||
30 Mar 2005, 16:58 |
|
f0dder 30 Mar 2005, 18:05
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. |
|||
30 Mar 2005, 18:05 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.