invoke HeapAlloc, hInstance, 30
push eax
invoke SendMessage, hWnd, WM_GETTEXT, 30, eax
invoke MessageBox, NULL, [esp-12], NULL, MB_OK


In the above example, I push a heap allocated memory address onto the stack. Line 3 (SendMessage) returns data from an edit control into my HeapAllocated buffer. I want to display this text in a messagebox, without popping eax (pop eax) because I will need it again later. So it must remain on the stack. Is it possible to use esp or ebp in an invoke like this? Is my wrong? I'm pretty sure it's got something to do with writing from memory-to-memory (not allowed)? What do others do when they want to access data, via invoke that already sits on the stack? I don't really want "complicated" code like this;



invoke HeapAlloc, hInstance, 30
push dword ptr MB_OK
push dword ptr NULL
push eax
invoke SendMessage, hWnd, WM_GETTEXT, 30, eax
push NULL
call MessageBox


Sorry, I think I'm missing some vital basics of Assembler here! Programmers block! :stupid:
Posted on 2004-03-31 02:28:30 by SubEvil
invoke HeapAlloc, hInstance, 30

push eax
invoke SendMessage, hWnd, WM_GETTEXT, 30, eax
invoke MessageBox, NULL, [esp+8], NULL, MB_OK
Posted on 2004-03-31 02:40:29 by donkey
Mmm,

I guess I should explain why...

When you finish the call to SendMessage your Heap pointer is at ESP (remember the stack is read backwards). Then you push the MB_OK on the stack and 4 is subtracted from ESP so it is at ESP+4, following that you push another NULL (-4 from ESP) and it is at ESP+8 etc....
Posted on 2004-03-31 02:56:51 by donkey
SubEvil,
Perhaps you should look toward the end of the thread linked below to see how to reference parameters on the stack. Ratch
http://www.masmforum.com/viewtopic.php?t=2307
Posted on 2004-03-31 12:51:16 by Ratch