News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Have a way to get proto parameters?

Started by mineiro, June 13, 2011, 05:16:00 PM

Previous topic - Next topic

mineiro

Hello Sr's;
I'm playing with invoke macro for a while and the question is about this:
Have one way to get the proto arguments?
ExitProcess PROTO :DWORD   ;I like to get this DWORD
I like(trying without sucess) to do a macro that check's if the user have entered correct number of params.(external or internal)
Any suggestion is welcomed.
Thanks.

jj2007

Invoke does check the correct # of parameters. There is apparently no way to get x=paras(ExitProcess), unless you are willing to write an external preprocessor...

Or have I completely misunderstood what you try to achieve??

qWord

An other possibility is to write a macro, that is used for declaring the prototype. This macro then records the parameters and declare the prototype.
(you can also  ask Japhet to add such an (powerfull) feature to jwasm  :dance:)
FPU in a trice: SmplMath
It's that simple!

mineiro

I'm dealing with ml64, this is why about this question.If have one way to do this in 32 , so to 64 have one way too.
In my findings, proto directive is inside ml64, like a reserved word.
In win32, I can see the ExitProcess@4 inside .obj file, so no problem, but I cannot see this in .obj of 64.

jj2007, if I "wrongly" declare something like, in win32:
ExitProcess PROTO :PTR DWORD
If I invoke exitprocess with a constant, It accepts, and don't generating warning or error saying that a ptr is required.

qWord, but if I do something like "inv Exitprocess,0,1,2,3" this will be acceptable without generating errors alright?

Thank for the answers. Follows a minimalist code.


includelib \masm32\lib\kernel32.lib
EXTERNDEF ExitProcess: PROTO :QWORD ;this works,r ml64(QWORD) and ml32(DWORD)

inv MACRO procname:REQ,arglist:VARARG
ArgNum = 0
% FOR item, <arglist>
IF ArgNum EQ 0
;...OPATTR checking
mov rcx,item ;;param1
ELSEIF ArgNum EQ 1
mov rdx,item ;;param2
ELSEIF ArgNum EQ 2
mov r8,item ;;param3
ELSEIF ArgNum EQ 3
mov r9,item ;;param4
ELSE
push item
ENDIF
% ArgNum=ArgNum+1
ENDM
call procname
endm

.code
inv ExitProcess,0
inv ExitProcess,0,1,2,3,4,5,6,7 ;works, but don't check number of parameteres.

qWord

here an quick example:
typed_proto macro FncName:req,args:VARARG
tp_cntr = 0
FOR _arg,<&args>
@CatStr(<&FncName&_param_>,%tp_cntr) SUBSTR <&_arg>,@InStr(1,<&_arg>,<:>)+1
tp_cntr = tp_cntr + 1
ENDM
&FncName&_nparam = tp_cntr
FncName proto args
endm

show_proto_info macro FncName:req
%echo function: FncName
%echo nParams: @CatStr(%(&FncName&_nparam))
cntr  = 0
WHILE cntr LT &FncName&_nparam
%echo @CatStr(<param #>,%cntr+1,<: >) @CatStr(<&FncName&_param_>,%cntr)
cntr = cntr + 1
ENDM
endm

...

; declare prototype and record parameters type-specifier
typed_proto MyFunction,psz: ptr CHAR,dwNum:DWORD

; show the infos in the build console
show_proto_info MyFunction


BTW: I'm just wondering why you are using this crappy software called ml64  :snooty:
FPU in a trice: SmplMath
It's that simple!

mineiro

Thank you for this gift qWord, I have tested it alone and do what I want. So, now, I'm reading all manual again to see my faults with macro world.
Well man, how can I say that this is a crappy without see with my eyes?. I agree with your words about v8, but v10 is a bit more smart.
I agree with you about using jwasm, this are only test's.
So, thank you Sr qWord, and thank you Sr jj2007 (this was the same question of MessageBox some months ago).

mineiro

Well, now I figure how to do the correct checking using proto.

.586
.model flat,stdcall
option casemap:none
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

EXTERNDEF MessageBoxA: PROTO, hWnd:DWORD,lpText:PTR DWORD,lpCaption:PTR DWORD,uType:DWORD
EXTERNDEF ExitProcess: PROTO, uExitCode:DWORD
.data
texto db "checking",00h

.code
start:
invoke MessageBoxA,0,texto,texto,0      ;error A2114: INVOKE argument type mismatch : argument : 3,2
invoke MessageBoxA,0,addr texto,addr texto,0
invoke ExitProcess,0
end start

This is an extension of this topic.
http://www.masm32.com/board/index.php?topic=16702.0

The fine news, ml64 check for these parameters too, using call.
EXTERNDEF MessageBoxA: PROTO, hWnd:QWORD,lpText:PTR QWORD,lpCaption:PTR QWORD,uType:QWORD
but, from some search in net, I have seen some rumors about PROTO end. So, you can change the PROTO above in ml64 by PROC and everything goes fine, but I think this is not absolutely true, but works in the time I have write this.
Now I'm thinking in rewrite the include files of win32 to be compatible with both.