Hey all,
I sorta got two questions:

1) can invoke be used to call an indirect memory stored in a register?

lea eax,MyFunc
invoke eax,ebx

I tried something like this but it complains that there's no PROTO. Just wondering if someone has a work around this.

2) My second question, ( which really isn't much different than the first), is can invoke be used with indirects stored in a variable.


aGetMessage dd offset GetMessage

invoke aGetMessage,addr msg,NULL,NULL,NULL

Furthermore, is this second method "safe". i.e, I'd like to swith to this way of calling APIs but I'm wondering if things might not work on different platforms or whatever. I don't see why they would though.

Thanks all
Posted on 2002-06-23 22:53:42 by chorus
lea eax, myfunc

push ebx
call eax

2. It's safe. Though I myself haven't experienced any problems using this kind of a call.
Posted on 2002-06-23 23:07:50 by stryker

Thanks for the reply, but I think I wasn't clear. The lea/push/call is what I'm doing. What I meant was that I enjoy the convenience of invoke, instead of pushing everything myself. Consider CreateFont or CreateWindowEx. I could push all the values but it's much simpler to use invoke. Plus it reads nicer when you're checking through your code.

Thanks again
Posted on 2002-06-23 23:11:28 by chorus
Warning Ads Are Found Here:

Use XCALL... :) If you don't want it, use a modified version of scall it's on the second page first thread on topic replacing invoke :: faster xcall macro (scall doesn't support aDdR yet).
Posted on 2002-06-23 23:13:54 by stryker
I'll take a look at it. Thanks :)

Posted on 2002-06-23 23:18:53 by chorus

.model flat, stdcall
option casemap:none


include \masm32\include\windows.inc

include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

proto0 typedef proto
proto1 typedef proto :DWORD
proto2 typedef proto :DWORD,:DWORD
proto3 typedef proto :DWORD,:DWORD,:DWORD
proto4 typedef proto :DWORD,:DWORD,:DWORD,:DWORD


szFormat db "%08X", 0
szTitle db "ID of current process:", 0


ShowCurrentProcessId proc uses esi edi ebx

LOCAL acBuffer[16]:CHAR

mov ebx, DWORD PTR GetCurrentProcessId + 2
mov ebx, [ebx]
assume ebx:ptr proto0
invoke ebx

mov ebx, DWORD PTR wsprintf + 2
mov ebx, [ebx]
assume ebx:ptr proto3
lea esi, szFormat
lea edi, acBuffer
invoke ebx, edi, esi, eax

mov ebx, DWORD PTR MessageBox + 2
mov ebx, [ebx]
assume ebx:ptr proto4
invoke ebx, NULL, addr acBuffer, addr szTitle, MB_OK

assume ebx:nothing

ShowCurrentProcessId endp

start proc

lea eax, ShowCurrentProcessId
assume eax:ptr proto0
invoke eax
assume eax:nothing

invoke ExitProcess, eax


start endp
end start
Posted on 2002-06-24 04:22:30 by Four-F
I asked the exact same question awhile ago, and here is the result:

Posted on 2002-06-24 11:22:09 by ThoughtCriminal