News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

EnumWindows with window handles dump gives errors!!!

Started by xandaz, December 19, 2010, 02:19:56 AM

Previous topic - Next topic

xandaz

    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

Gunner

What kind of errors?  You are NOT preserving edi!
EnumProc PROC uses edi hWnd:DWORD,Arg:DWORD
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

dedndave

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

xandaz

 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.

oex

We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

xandaz


xandaz

   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

MichaelW

You need to preserve EDI because EnumProc is a callback. Since Windows is calling it, it needs to follow the register-preservation conventions.
eschew obfuscation

Gunner

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
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

xandaz

    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. :)

Gunner

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


~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com