Author Topic: Macro for argument count testing in procedure calls.  (Read 372 times)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4867
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Macro for argument count testing in procedure calls.
« on: October 26, 2016, 01:04:06 AM »
I have got used to the economy of not be burdened with endless prototypes but I have tested a macro that does reliable arg count testing. The multiple argument macro ".ma" is used to reduce the line count so you could fit more pseudo prototypes into a smaller space.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    .MessageBox MACRO args:VARARG
      .ma cnterr .MessageBox,4,args # invoke __imp_MessageBoxA,args
    ENDM

    cnterr MACRO mname,cnt,args:VARARG
      IF argcount(args) NE cnt
      echo ****************************************************
      echo mname Incorrect Argument Count, cnt Expected
      echo ****************************************************
      .err <mname Incorrect Argument Count, cnt Expected>
      ENDIF
    ENDM

    api MACRO args:VARARG
      args
      EXITM <rax>
    ENDM

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    LOCAL rval :QWORD

    .MessageBox 0,"Statement Version","Test 1",MB_OK

    mov rval, api(.MessageBox 0,"Function Version","Test 2",MB_OK)

    invoke ExitProcess,0

    ret

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin: