Hello,

Well I'm trying to call a register but Macros wont work.

I've tried invoke, scall and xcall, tried also to modify them but I can't make it work...

Suppose this little piece of code:



.data

szDllName BYTE "user32.dll",0
szFuncName BYTE "MessageBoxA",0

.code

invoke Loadlibrary,addr szDllName
mov hModule,eax

invoke GetProcAddress,hModule,addr szFuncName
;function pointer in eax

invoke eax, hWin, addr szText, addr szCaption,MB_OK ; I'm searching for something like that



Anyone know what I must change to Xcall macro to make it accpet registers as first value ?

Maybe I should write a new macro ?

Thank you very much.

Thanks to fodder for pointing me to xcall (that's a really good macro, thanks Stryker !)

Regards, Neitsa.
Posted on 2004-07-19 19:58:22 by Neitsa
smile :grin:
.686

.MMX
.XMM
.MODEL FLAT, STDCALL
OPTION SCOPED
OPTION CASEMAP:NONE

INCLUDE C:masm32includewindows.inc
INCLUDE C:masm32includekernel32.inc
INCLUDELIB C:masm32libkernel32.lib
INCLUDE C:masm32includeuser32.inc
INCLUDELIB C:masm32libuser32.lib

@str macro _str:vararg
local @@1
if @InStr(1, <_str>, <!"> )
.data
@@1 db _str, 0
.code
exitm <offset @@1>
else
exitm <_str>
endif
endm

@preverse MACRO ParList:REQ
LOCAL Value, arg
Value TEXTEQU <>
% FOR arg, <ParList>
Value CATSTR <arg>, <,>, Value
ENDM
Value SUBSTR Value, 1, @SizeStr( %Value ) - 1
Value CATSTR <!<>, Value, <!>>
EXITM Value
ENDM

xcall MACRO function:REQ, parameters:VARARG
LOCAL paddr
IFNB <parameters>
% FOR param, @preverse(<parameters>)
IF @SizeStr(<param> ) GT 4
paddr SUBSTR <param>, 1, 5
IFIDNI paddr, <ADDR >
paddr SUBSTR <param>, 6, @SizeStr(<param>) - 5
lea eax, paddr
push eax
ELSE
push @str(<param>)
ENDIF
ELSE
push @str(<param>)
ENDIF
ENDM
ENDIF
call function
ENDM

.DATA

szText BYTE "Text", 0
szCaption BYTE "Caption", 0

szDllName BYTE "user32.dll",0
szFuncName BYTE "MessageBoxA",0

.DATA

hWin DWORD ?
hModule DWORD ?

.CODE

start:

invoke LoadLibrary, ADDR szDllName
mov hModule, eax

invoke GetProcAddress, hModule, ADDR szFuncName
mov ecx, eax

xcall ecx, hWin, ADDR szText, ADDR szCaption, MB_OK ; I'm searching for something like that

invoke ExitProcess, 0
ret

END start
remember ADDR is
lea eax, LABEL

push eax
:grin:
Posted on 2004-07-19 21:59:27 by arkane
Another simulation of invoke macro:


_invoke MACRO funcname:REQ,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20
local pos

FOR arg,<p20,p19,p18,p17,p16,p15,p14,p13,p12,p11,p10,p9,p8,p7,p6,p5,p4,p3,p2,p1>

IFNB <arg>
pos=@InStr(1,arg,<ADDR>) OR @InStr(1,arg,<addr>) OR @InStr(1,arg,<Addr>)

IF pos

IF (OPATTR(@SubStr(arg,%pos+5))) EQ 98
lea eax,@SubStr(<arg>,%pos+5)
push eax
ELSE
push OFFSET @SubStr(<arg>,%pos+5)
ENDIF

ELSE
push arg
ENDIF
ENDIF
ENDM
call funcname
ENDM
Posted on 2004-07-20 05:22:11 by Vortex
Hello,

Thank you very much for your answers.

It seems to work now. :alright:

I've got some compile errors in some cases, dunno exactly where it came from. I'll continue to search. Anyway now It works...

Thanks a lot.

Regards, Neitsa.
Posted on 2004-07-20 07:05:34 by Neitsa