Hey guys.... why does this return error? check it out...
.data
WindowHandles dd 50000 dup(0) ; huge number to prevent overflow
lpWindowHandles dd offset WindowHandles
.code
....
invoke EnumWindows,addr EnumProc,NULL
....
EnumProc PROC hWnd:DWORD,Arg:DWORD
mov edi,lpWindowHandles
mov eax,hWnd
stosd
cld
invoke GetWindowText,eax,addr WindowName
invoke SendMessage,hListbox,LB_ADDSTRING,NULL,addr WindowName
mov lpWindowHandles,edi
mov eax,TRUE
ret
EnumProc endp
Why is this not working? Someone ? :lol
Thanks and bye
What kind of errors? You are NOT preserving edi!
EnumProc PROC uses edi hWnd:DWORD,Arg:DWORD
Rob is right
but, i noticed something that was a little odd
stosd
cld
you shouldn't have to CLD - it should already be cleared
and, if you do have to CLD, you might want to do it before the STOSD :P
yes ded. i kinda made that mistake but only here. But why do i need to preserve edi? when i do the mov edi,lpWindowHandles and lpWindowHandles,edi i don't think there's any danger. is there? let me try that out.
its working fine now. thanks
works fine with pushes, but, still... why do i need to preserce edi? I load it in the beggining of EnumProc and deload it in the end. What difference does it make to push and pop? Someone pls clarify me. Thanks
You need to preserve EDI because EnumProc is a callback. Since Windows is calling it, it needs to follow the register-preservation conventions.
re read my post above.... you don't need to uses push/pop... instead put USES EDI after the word proc... easier then using push reg and remembering to pop it before leaving the proc
Oh ok. Since windows is calling the callback function and it may be useing edi, you preserve it to prevent errors. Thanks. That was kinda hard to understand. I'm such a dumbo. Thanks guys and byebye. :)
Well, anytime you use esi, edi ebx in a proc you must save their contents, especially in a callback procedure... it is proper programming etiquette :bg
open up the help file masm32/help/asmintro.chm and read the section called Register Preservation Convention