News:

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

A macro problem in beta 1.0

Started by hutch--, January 30, 2006, 02:17:17 AM

Previous topic - Next topic

hutch--

I have just been coding up some examples and ran into this problem.

Using this pair of macros,

    reparg MACRO arg            ;; ANSI version
      LOCAL nustr
      IF (OPATTR arg) AND 8000h ;; is it a "string"...?
        .data
          nustr db arg,0        ;; write arg to .DATA section
        .code
        EXITM <ADDR nustr>      ;; append name to ADDR operator
      ELSE
        EXITM <arg>             ;; else return arg
      ENDIF
    ENDM

    fn MACRO FuncName:REQ,args:VARARG
      arg equ <invoke FuncName>         ;; construct invoke and function name
      FOR var,<args>                    ;; loop through all arguments
        arg CATSTR arg,<,>,reparg(var)  ;; replace quotes and append arg
      ENDM
      arg                               ;; write the invoke macro
    ENDM


When I try and use the macro with normal variables I get a list or notation errors.


      ; This works
        mov ecx, hWin
        mov edx, OFFSET szDisplayName
        fn MessageBox,ecx,"You pressed button 1",edx,MB_OK

      ; these fail
        fn MessageBox,hWin,"You pressed button 1",edx,MB_OK
        fn MessageBox,hWin,"You pressed button 1",ADDR szDisplayName,MB_OK

Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

PellesC

If I put < and > around "ADDR szDisplayName" it *seems* to work with version 1.00.7 (Beta). Maybe not beautiful, but anyway...

fn MessageBox,hWin,"You pressed button 1",<ADDR szDisplayName>,MB_OK

Pelle

hutch--

I am having problems with this one and it is probably because I am not performing the correct test to see if a VARARG set of arguments exist.


      pprint MACRO lptxt,therest:VARARG
        LOCAL tail
        invoke StdOut,reparg(lptxt)
        ; IFNB <therest>
        ; or
        ; IFNDEF <therest>
        .data
          tail db therest,0
        .code
        invoke StdOut,OFFSET tail
        ; ENDIF
      ENDM
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

PellesC

The best way of dealing with a comma-separated list of variable arguments in POASM is through a FOR-loop.

Maybe like this...

...
argc = 0
FOR arg, <therest>
    argc = argc + 1
ENDM
if argc GT 0
    ...
endif
...


Pelle

ramguru

Could someone help with my problem ?..
I've used CPROTO (and it assembles OK), found it in one Hutch's post, but when I try to use my new function I get an error message: : error: Expected '<ident>'. But I have no idea how to solve it.
Error because of this line:

invoke SciSend, SciPTR, SCI_SETCODEPAGE, SC_CP_UTF8, 0

I have a prototype like this:

.data?
   SciPTR   dd ?

SciSend CPROTO(adr_,:DWORD,:DWORD,:DWORD,:DWORD)

I get a pointer of function this way:

mov    adr_,   FUNC(SendMessage, win_text, SCI_GETDIRECTFUNCTION, 0, 0) ; win_text obtained with GetDlgItem
mov    SciPTR, FUNC(SendMessage, win_text, SCI_GETDIRECTPOINTER,  0, 0)

I have used fn,rv,ufn but then I get even more error messages...
This code worked perfectly in masm32...

ramguru

I've just noticed that CPROTO macro is included in POASM package (mmacros.asm), could I ask for a working example where this macro is used. (If someone think that I'm persistent he is not mistaking :) )

    ; --------------------------------------------
    ; the following two macros are for prototyping
    ; direct addresses with a known argument list.
    ; --------------------------------------------

      CPROTO MACRO func_addr:REQ,arglist:VARARG     ;; C calling version
        LOCAL lp,var
        .data?
          func_addr dd ?
        .const
        var typedef PROTO C arglist
        lp TYPEDEF PTR var
        EXITM <equ <(TYPE lp) PTR func_addr>>
      ENDM