News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

need help with macro

Started by jimg, February 09, 2020, 05:46:31 AM

Previous topic - Next topic

jimg

I've been playing with some of KetilO's code.  One macro is causing problems in uasm.  It works without complaint in masm.

Here's a test program just to test the stdmethod macro-
.686
.model Flat, Stdcall
option Casemap :None   ; case sensitive
.xmm
.nolist
include Windows.inc
uselibs macro libs:vararg
    for nlib,<libs>
        include nlib.inc
        includelib nlib.lib
    endm
endm
uselibs user32,kernel32 ;,comctl32,comdlg32,gdi32,shlwapi,ole32,msvcrt  ; add ,masm32,debug   for debug
inv equ invoke
.listall

stdmethod macro name,argl:vararg
    local t1
    local t2
    t1 typedef proto this_:dword,argl
    t2 typedef ptr t1
    name t2 ?
ENDM

IUnknown struct
stdmethod QueryInterface,:DWORD,:DWORD
stdmethod AddRef
IUnknown ends

.code
Program:
    inv ExitProcess,0
End Program

masm give these results:

00000008 IUnknown struct
stdmethod QueryInterface,:DWORD,:DWORD
     1     local t1
     1     local t2
     1     ??0019 typedef proto this_:dword,:DWORD,:DWORD
     1     ??001A typedef ptr ??0019
00000000  00000000      1     QueryInterface ??001A ?

stdmethod AddRef
     1     local t1
     1     local t2
     1     ??001B typedef proto this_:dword,
     1     ??001C typedef ptr ??001B
00000004  00000000      1     AddRef ??001C ?

While uasm complains with the following:
00000000                        IUnknown struct
                                stdmethod QueryInterface,:DWORD,:DWORD
                             1      ??0019 typedef proto this_:dword,:DWORD,:DWORD
                             1      ??001A typedef ptr ??0019
00000000                     1      QueryInterface ??001A ?
                               
                                stdmethod AddRef
                             1      ??001B typedef proto this_:dword,??001C typedef ptr ??001B
                           Error A2084: Colon is expected
                             1      AddRef ??001C ?
                           Error A2210: Syntax error: AddRef
                               
00000004                        IUnknown ends


This is stuff I never do myself, and just convoluted enough that I can't quite see how to make uasm happy.
Anyone have a suggestion as how to make this work?

jj2007

Try this:
stdmethod macro name,argl:vararg
local t1, t2
  ifnb <argl>
t1 typedef PROTO this_:DWORD, argl
  else
t1 typedef PROTO this_:DWORD
  endif
  t2 typedef ptr t1
  name t2 ?
ENDM


Apparently, UAsm and AsmC do not like a trailing comma as in typedef PROTO this_:DWORD,

jimg

That works, thanks!
Don't know why I couldn't recognize that trailing comma  :rolleyes:

jimg

So, just getting back to this.

stdmethod macro name,argl:vararg
local t1, t2
  ifnb <argl>
   t1 typedef PROTO this_:DWORD, argl
  else
   t1 typedef PROTO this_:DWORD
  endif
  t2 typedef ptr t1
  name t2 ?
ENDM

The end result looks like it would be     name typedef ptr typedef proto this_:dword   but that's not right, so

it must be    name typedef ptr proto this_:dword         yes?

or would it ultimately be     name typdef proto this_:dword?

What is a pointer to a proto?

And what is this_     I could not find a reference to anywhere other than in the macro.  Nowhere to be found in the masm reference manual.

Having never used anything remotely like this, I'm having trouble understanding what this means.

Especially the way it is used.   It is use like this-

IUnknown struct
   STDMETHOD QueryInterface,:DWORD,:DWORD
   STDMETHOD AddRef
   STDMETHOD Release
IUnknown ends

so you end up with a structure that only contains protos.   What?


The next statement is-

IDropTarget   struct
   ;IUnknown methods
   iu                  IUnknown <?>
   ;IDropTarget methods
   STDMETHOD DragEnter,:DWORD,:DWORD,:DWORD,:DWORD
   STDMETHOD DragOver,:DWORD,:DWORD,:DWORD
   STDMETHOD DragLeave
   STDMETHOD Drop,:DWORD,:DWORD,:DWORD,:DWORD
   ;Additional   data
   refcount            dd ?
   valid               dd ?
   hwnd               dd ?
   cp                  dd ?
IDropTarget   ends

and ultimately it is used like this

      mov      eax,pthis
      mov      [edx],eax
      mov      edx,[eax]
      invoke [edx].IDropTarget.iu.AddRef,eax
      mov      eax,S_OK

I'm beginning to think I don't have a prayer of figuring out what is going on.  And I refuse to believe there isn't a much simpler way to achieve the ultimate results.

KetilO must have been some evil genius.



HSE

Quote from: jimg on February 10, 2020, 05:22:45 PM
And what is this_

this_ is a pointer to object's instance.

Every object's method is a procedure with that pointer as first argument.

Quote from: jimg on February 10, 2020, 05:22:45 PM
  name t2 ?

What is a pointer to a proto?

It's a pointer to the procedure.  Several of this pointers make the VMT (virtual method table) of the object. The object don't have the procedures, just the address of procedures.

You can see a more advanced implementation of objects in ObjAsm in this forum
Equations in Assembly: SmplMath

johnsa

You can have a look at the macros in the lib of UASM we use for creating COM structures and invokes and the OO stuff, it works the same way.

jimg