At the end it's becomes boring to me always to check manualy the proper invokes and stdcalls in my programs. You know: F1, count the parameters in help, alt-tab, check the source, alt-tab, count again, alt-tab, check again, F9, crash :grin: :grin:

So, I modified some macroses in stdcall.inc and import.inc to make fasm check this for me.

[size=12]

; use it like this:
; import label, 'name', arg_count, \
; label, 'name', arg_count, ...... etc.
macro ImportArg [label,string,arg]
{ forward
local _label
label dd RVA _label
.ArcCount = arg
common
dd 0
forward
_label dw 0
db string,0 }


macro proc name,[arg] ; define procedure
{
common
name:
.ArgCount = 0
virtual at ebp+8
if ~ arg eq
forward
local ..arg
..arg dd ?
arg equ ..arg
.ArgCount = .ArgCount + 1
common
end if
..ret = $ - (ebp+8)
end virtual
local ..dynamic_data,..dynamic_size
dynamic_data equ ..dynamic_data
dynamic_size equ ..dynamic_size
virtual at ebp - dynamic_size
dynamic_data: }

macro stdcall proc,[arg] ; call procedure
{
common
local CNT
CNT = 0
reverse
push arg
CNT = CNT + 1
common
if CNT <> proc#.ArgCount
display 'The arguments count is not correct.'
error
end if
call proc }


macro invoke proc,[arg] ; invoke procedure (indirect)
{
common
local CNT
CNT = 0
forward
push arg
CNT = CNT + 1
common
if ~ proc#.ArgCount eq
if CNT <> proc#.ArgCount
display 'The arguments count is not correct.'
error
end if
end if
if ~ arg eq
stdcall [proc],arg
else
call [proc]
end if
}

[/SIZE]


So, I must confess that I check only proc/stdcall macroses, but IMHO there must no any problem. If you use "ImportArg" to import functions, invoke will check the count, if you use "import", "invoke" will not check the count.

And one idea at the end: Privalov, it's a good idea to insert in fasm syntax directive "error 'error_message'" - this must simply generate error and stop assembly.
Posted on 2002-12-10 04:23:45 by JohnFound
Error directive, for example:

if ...
_error 'Error!'
else
...
end if

macro _error errmsg
{
display errmsg
stop :o
}
Thanks.
Posted on 2002-12-10 06:21:08 by tserk
Have you based on the macros from the win32inc.zip package?
Posted on 2002-12-10 09:00:53 by Tomasz Grysztar
I loaded the package.
Thank You again.
Posted on 2002-12-10 09:31:03 by tserk
Shame on me! :( Visibly I reinvent the wheel (or hot water :stupid: )
I am not based on the win32inc.zip, but it's not change the facts that there is suspicious similarity. But I still think that my version of "proc" macro is better, because of automatic argument count.

BTW: Using "dysplay" with some error line to stop compiling is just a work around. There is need of "error" compiler directive.
Posted on 2002-12-10 23:59:23 by JohnFound