I provided two example with the exact same code except in one location of each attachment where we PUSH instead of INVOKE .... Everyone may have experienced this at one time or another. It don't happen that often, only. For me, I just never barked about it until now, and I hope someone has the fix for this and can explain why this happen, and what coding effect causes this to happen ...
How can I make PUSH Work in a situation like this Once and For All....
Any and all information may be helpful no matter how large or short comments may be. I need to get to the bottom of it. Tired of wondering about it...
Thanks in Advance
Invoke_Works Attachment Has This Code and it WORKS ! ! ! :
invoke CoCreateInstance,ADDR CLSID_ITaskbarList,NULL,CLSCTX_INPROC_SERVER,\
ADDR IID_ITaskbarList,ADDR ptb
Push_Do_Not Attachment Has This Code and it DON'T Work ! ! ! :
IT WILL CRASH ON BUTTON CLICK
And you can't say PUSH offset ptb without receiving an
"invalid operand for OFFSET"when trying to assemble
PUSH ptb ; ADDR ptb
PUSH offset IID_ITaskbarList ; GUID
PUSH 1 ; CLSCTX_INPROC_SERVER
PUSH 0 ; NULL
PUSH offset CLSID_ITaskbarList ; GUID
CALL CoCreateInstance
strange...
[attachment deleted by admin]
Try this,
; Replace
PUSH ptb
; with
lea eax, ptb
push eax
WoW!!!
Now I see why...
Thank you Mr.hutch
but what is the diffrence between PUSH and LEA,is not it the same? because i had this problem some times in my programs and changed the PUSH OFFSET with LEA without knowing the reason.
If you are using the address of LOCAL variables as parameters, that address is located within the stack and is not known at assembly time (it can be anywhere on the stack depending when the procedure is called). Therefore, its OFFSET is not known and trying to use "mov eax,offset variable" cannot work. For LOCAL variables within a procedure, only "lea eax,variable" will retrieve that address which is coded as a displacement in the stack along with the EBP register.
When using "push variable" with a LOCAL variable, you actually push the value currently located at that address within the stack (NOT its address).
Quote from: ossama on December 18, 2007, 06:42:19 PM
but what is the diffrence between PUSH and LEA,is not it the same? because i had this problem some times in my programs and changed the PUSH OFFSET with LEA without knowing the reason.
sorry it is my mistake, i mean : i changed the (ADDR variable) with the (LEA variable) solved the problem.
using push offset of local variable will get error at assembly time,but using the (addr variable) will not get error at assembly time, it will get error at run time,but when i changed the (addr variable) with (lea variable) solved the problem.
i hope my explanation is clear (sorry for the english i have)
thank you