Hi folks.

If a proc is defined with MASM, say:


MessageBeep proto :dword


how can I find out the required number of parameters
given the name of the proc, "MessageBeep"?


I'm trying to INVOKE a procedure using a register, like this:


        protoreg ebx, MessageBeep
        invoke  ebx, -1


Currently, my "protoreg" macro requires a third param that specifies
the required number of bytes (ie. protoreg ebx, MessageBeep, 4)


The question is:
how can I find out the required number of parameters
given the name of the proc, "MessageBeep"?


I've tried
ifdef <MessageBeep@4> and
ifdef <_MessageBeep@4> w/o luck..


Have a nice day!


macros:


;=====================================================
protoreg macro reg:req, name, nParams


        ifb <name>
                assume reg:nothing
        else


                ifb <nParams>
%                      assume reg:_FakeFunc0
                else
%                      assume reg:_FakeFunc&nParams
                endif


                mov    reg,offset name
        endif
endm


;=====================================================
;assign several FakeFunctions:


prototype macro name, argl:vararg
local @tmp_a


        name proto argl


        @tmp_a typedef proto argl
        _&name typedef ptr @tmp_a
endm


prototype FakeFunc0
prototype FakeFunc1,  :dword
prototype FakeFunc2,  :dword, :dword,
prototype FakeFunc3,  :dword, :dword, :dword,
prototype FakeFunc4,  :dword, :dword, :dword, :dword


etc..


;=====================================================

Posted on 2007-06-12 18:19:42 by aleksaZR
The question is:
how can I find out the required number of parameters
given the name of the proc, "MessageBeep"?


Personally, if I were to write a program which calls external functions, I would consult the Help file to find out how many (and which) parameters are required.

Raymond
Posted on 2007-06-12 21:46:39 by Raymond
how can I find out the required number of parameters
given the name of the proc, "MessageBeep"?


AFAIK, you can't.

you could do a workaround by redefining all of your prototypes so that name matches type;
only then you wouldn't have to know the required number of function parameters
TYPE_ExitProcess TYPEDEF PROTO STDCALL :DWORD
EXTERNDEF _imp__ExitProcess@4:PTR TYPE_ExitProcess
ExitProcess EQU <_imp__ExitProcess@4>
protoreg macro reg:req,name
ifb <reg>
ASSUME reg:NOTHING
else
ifdef TYPE_&name
mov reg,name
ASSUME esi:PTR TYPE_&name
endif
endif
endm
protoreg esi,ExitProcess
invoke esi,0
protoreg esi
invoke ExitProcess,0
Posted on 2007-06-12 22:15:02 by drizz

how can I find out the required number of parameters
given the name of the proc, "MessageBeep"?


AFAIK, you can't.

you could do a workaround by redefining all of your prototypes so that name matches type;
only then you wouldn't have to know the required number of function parameters
TYPE_ExitProcess TYPEDEF PROTO STDCALL :DWORD
EXTERNDEF _imp__ExitProcess@4:PTR TYPE_ExitProcess
ExitProcess EQU <_imp__ExitProcess@4>
protoreg macro reg:req,name
ifb <reg>
ASSUME reg:NOTHING
else
ifdef TYPE_&name
mov reg,name
ASSUME esi:PTR TYPE_&name
endif
endif
endm
protoreg esi,ExitProcess
invoke esi,0
protoreg esi
invoke ExitProcess,0



That was my first idea, to convert all the existing PROTOs into macros.

I've changed all masm32 files (user32.inc, kernel32.inc, etc.)

from:

AddAtomW PROTO :DWORD
AllocConsole PROTO
AllocateUserPhysicalPages PROTO :DWORD,:DWORD,:DWORD
...

to:

PROTOREG AddAtomW, :DWORD
PROTOREG AllocConsole
PROTOREG AllocateUserPhysicalPages, :DWORD,:DWORD,:DWORD
...


That was working nicely (don't have a macro definition anymore),
but the assembly process on my aged PI 166MHz became sooo sloooooow...

Well.... it's easy to count the required number of params,
so I'll have something like "protoreg ebx, MessageBeep, 1"

Bye 8)
Posted on 2007-06-13 09:52:57 by aleksaZR
Try out japheth's include files (japheth.de).
The functions are all prototyped with a macro, and the package is better than masm32
and you can use "protoreg" with them but you have to specify A or W suffix:
protoreg macro reg:req,name
ifb <name>
ASSUME reg:NOTHING
else
ifdef proto_&name
mov reg,name
ASSUME reg:PTR proto_&name
endif
endif
endm

int 3
protoreg esi,GetModuleHandleA
invoke esi,0
protoreg esi
invoke GetModuleHandle,0

Posted on 2007-06-13 15:41:51 by drizz