News:

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

Macro problem again

Started by minor28, December 09, 2009, 10:05:49 PM

Previous topic - Next topic

minor28

I am learning macro and I read a post from 2005 how to handle a C calling convention using a macro "tprint".

I am trying to apply this on a procedure with no vararg parameters.

RUNMETHOD(pApp,CTEXT("MyText"),IDC_BTN1,addr buffer)

With this make error

MainDlg.asm(37) : error A2008: syntax error : addr
RUNMETHOD(21): Macro Called From
  MainDlg.asm(37): Include File
MainDlg.asm(37) : error A2207: missing right parenthesis in expression
RUNMETHOD(24): Macro Called From
  MainDlg.asm(37): Include File


Changing to this

lea eax,buffer
RUNMETHOD(pApp,CTEXT("MyText"),IDC_BTN1,eax)

Give this make error

MainDlg.asm(38) : error A2208: missing left parenthesis in expression
RUNMETHOD(21): Macro Called From
  MainDlg.asm(38): Include File
MainDlg.asm(38) : error A2207: missing right parenthesis in expression
RUNMETHOD(24): Macro Called From
  MainDlg.asm(38): Include File


Here is the proto and macro

RunMethod PROTO c :dword,:dword,:dword,:dword,:dword,:vararg

RUNMETHOD macro Arg1,Arg2,Arg3,Arg,Args:vararg

LOCAL acnt,lcnt

push esi
push edi
push edx
invoke GlobalAlloc,GMEM_FIXED or GMEM_ZEROINIT,sizeof Params
mov esi,eax                 

acnt = ArgCount(Args)
lcnt = acnt

repeat acnt
push Repargof(Getarg(lcnt,Args)) ;; push variable number of args
lcnt = lcnt - 1
endm

push esi ;; push the buffer address
mov eax,ArgCount(Args)
push eax ;; push the argument count
push Arg4
push Arg3
push Arg2
push Arg1
call RunMethod ;; call the C calling procedure
add esp, ArgCount(Args)*4+8 ;; correct the stack
add esp,32 ;; correct the stack
push eax

invoke GlobalFree,esi ;; free the memory buffer

pop eax
pop edx
pop edi
pop esi

endm


If I comment out the 4 push argument in the macro there is no make error. Now if I add a couple of vararg argument I get this error

MainDlg.asm(38) : error A2006: undefined symbol : ??001A
RUNMETHOD(13): Macro Called From
  MainDlg.asm(38): Include File
MainDlg.asm(38) : error A2208: missing left parenthesis in expression
RUNMETHOD(10): Macro Called From
  MainDlg.asm(38): Include File
MainDlg.asm(38) : error A2006: undefined symbol : ??001A
RUNMETHOD(11): Macro Called From
  MainDlg.asm(38): Include File
MainDlg.asm(38) : error A2208: missing left parenthesis in expression
RUNMETHOD(19): Macro Called From
  MainDlg.asm(38): Include File
MainDlg.asm(38) : error A2208: missing left parenthesis in expression
RUNMETHOD(26): Macro Called From
  MainDlg.asm(38): Include File


I cannot figure out how to apply this. Hutch example works fine though. Help would be appreciated.

Regards

dedndave

hmmmm - PROTO for a macro ????
i don't think you want a PROTO
rem that line out and see how things go

hutch--

to run a macro in this format,


RUNMETHOD(pApp,CTEXT("MyText"),IDC_BTN1,addr buffer)


It must have an EXITM to return a value, otherwise you remove the brackets.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

minor28

Thank you, now the make error is solved. It remains to see if I can get the function to work in the right way.