News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

UASM 2.46 Release

Started by johnsa, December 05, 2017, 01:11:19 AM

Previous topic - Next topic

johnsa

Hi all,

Packages and git have been updated to 2.46.3 dated 8th Dec.
This includes all the required fixes and a new option hlcall:{on|off} to disable the c style function calling and object/pointer invocations. It's enabled by default.

Cheers

nidud

#31
deleted

johnsa

Great minds ... and all paths lead to Rome .. I noticed you'd published an update about function pointer invocations at about exactly the same time!  :t

LiaoMi

Hi johnsa,

thanks for the Great Job! XP version waiting for updates? Its not on the list of common releases, although the link to the previous version works.

johnsa

The 32bit version is built with WinXP compatibility mode so that should work as-is on XP.

John

jj2007

Congrats, John & Habran :icon14:

Works perfectly with today's version of MasmBasic; I had to add a little switch, as agreed with John. RichMasm will try to install UAsm64 2.46 if there is no \Masm32\bin\uasm64.exe on your disk. This works fine when launching RichMasm from a drive different from C.

Vortex

Hi habran and johnsa,

I am trying to use high level calling syntax with COM. Converting a simple Masm COM example :

IActiveDesktop STRUCT

    QueryInterface          dd ?
    AddRef                  dd ?
    Release                 dd ?
    ApplyChanges            dd ?
    GetWallpaper            dd ?
    SetWallpaper            dd ?
    GetWallpaperOptions     dd ?
    SetWallpaperOptions     dd ?
    GetPattern              dd ?
    SetPattern              dd ?
    GetDesktopItemOptions   dd ?
    SetDesktopItemOptions   dd ?
    AddDesktopItem          dd ?
    AddDesktopItemWithUI    dd ?
    ModifyDesktopItem       dd ?
    RemoveDesktopItem       dd ?
    GetDesktopItemCount     dd ?
    GetDesktopItem          dd ?
    GetDesktopItemByID      dd ?
    GenerateDesktopItemHtml dd ?
    AddUrl                  dd ?
    GetDesktopItemBySource  dd ?

IActiveDesktop ENDS


Probably, my convertion is not correct so I need your help here :

COMINTERFACE IActiveDesktop

CVIRTUAL  ApplyChanges ,DWORD, :DWORD
CVIRTUAL  GetWallpaper ,DWORD, :PTR, :DWORD, :DWORD
CVIRTUAL  SetWallpaper ,DWORD, :PTR, :DWORD
CVIRTUAL  GetWallpaperOptions ,DWORD, :DWORD, :DWORD
CVIRTUAL  SetWallpaperOptions ,DWORD, :DWORD, :DWORD
CVIRTUAL  GetPattern  ,DWORD,:PTR, :DWORD, :DWORD
CVIRTUAL  SetPattern ,DWORD, :PTR, :DWORD
CVIRTUAL  GetDesktopItemOptions ,DWORD, :DWORD, :DWORD
CVIRTUAL  SetDesktopItemOptions ,DWORD, :DWORD, :DWORD
CVIRTUAL  AddDesktopItem ,DWORD, :DWORD, :DWORD
CVIRTUAL  AddDesktopItemWithUI ,DWORD, :HWND, :DWORD, :DWORD
CVIRTUAL  ModifyDesktopItem ,DWORD, :DWORD, :DWORD
CVIRTUAL  RemoveDesktopItem ,DWORD, :DWORD, :DWORD
CVIRTUAL  GetDesktopItemCount ,DWORD, :LPINT, :DWORD
CVIRTUAL  GetDesktopItem ,DWORD, :DWORD, :DWORD, :DWORD
CVIRTUAL  GetDesktopItemByID ,DWORD, :PTR, :DWORD, :DWORD
CVIRTUAL  GenerateDesktopItemHtml ,DWORD, :PTR, :DWORD, :DWORD
CVIRTUAL  AddUrl ,DWORD, :DWORD, :PTR, :DWORD, :DWORD
CVIRTUAL  GetDesktopItemBySource ,DWORD, :PTR, :DWORD, :DWORD

ENDCOMINTERFACE


.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\ole32.inc
include     \masm32\macros\macros.asm
include     SetWallpaper.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\ole32.lib

LPad TYPEDEF PTR IActiveDesktop

.data

CLSID_IActiveDesktop    GUID sCLSID_IActiveDesktop
IID_IActiveDesktop      GUID sIID_IActiveDesktop

WSTR        DesktopImg,"test.bmp"
pAD         LPad 0

.data?

wpo         WALLPAPEROPT <>

.code

start:

    invoke      CoInitialize,NULL

    invoke      CoCreateInstance,ADDR CLSID_IActiveDesktop,NULL,\
                CLSCTX_INPROC_SERVER,ADDR IID_IActiveDesktop,ADDR pAD           

    mov         edx,OFFSET wpo
    mov         WALLPAPEROPT.dwSize[edx],SIZEOF(WALLPAPEROPT)
    mov         WALLPAPEROPT.dwStyle[edx],WPSTYLE_CENTER

    pAD->SetWallpaper(OFFSET DesktopImg,0)

    coinvoke    pAD,IActiveDesktop,SetWallpaper,OFFSET DesktopImg,0

    coinvoke    pAD,IActiveDesktop,SetWallpaperOptions,OFFSET wpo,0

    coinvoke    pAD,IActiveDesktop,ApplyChanges,AD_APPLY_ALL

    coinvoke    pAD,IActiveDesktop,Release

    invoke  CoUninitialize
   
    invoke  ExitProcess,0

END start


The error message :

SetWallpaper.asm(41) : Error A2049: Invalid instruction operands
_VCOMINVOKE(10)[SetWallpaper.asm]: Macro called from
  SetWallpaper.asm(41): Main line code
SetWallpaper.asm: 55 lines, 1 passes, 170 ms, 0 warnings, 1 errors


Line 41 seems to be the problem :

pAD->SetWallpaper(OFFSET DesktopImg,0)

I would like test the arrow operator ( -> ) and the built-in macro _INVOKE in two different versions of the source code above.  How should I use the the _INVOKE macro to call COM methods in my example code?  Another question, can I use the structure IActiveDesktop instead of a COMINTERFACE definition while specifying the arrow operator or the _INVOKE macro?

johnsa

Hi,

I'll test out this example and see what the issue is with that line, I suspect it may be to do with using the OFFSET operator in the macro.

The pointer syntax (->) can only be used with OINTERFACE, CLASS and COMINTERFACE (internally these types are tracked as being different from regular structures and different from each other).

In the case of the ointerface or class the vtable exists inside the instance itself, where-as with com the object contains a pointer to the vtable. So the keep the syntax consistent it handles them differently by adding extra indirection in the case of COM. Using the ointerface or class with -> requires use of a vtable (OPTION VTABLE:ON) where-as for performance reasons if you have a class that you know is not going to be dynamically modified, and hence no reason to go via a vtable, with that off the call removes the extra indirection and goes straight to the method call.

I'll get back to you asap with a fix for the offset issue.


johnsa

On another note, the _V, _INVOKE and other macros that are built-in deal entirely with the OO features. COM having the extra indirection required slightly different handling so internally uses _VCOMINVOKE and _VCOM.

Assuming you don't wanted nested calls, then using _VCOMINVOKE or _INVOKE(for normal OO) is pretty straightforward as per the example in the manual and samples folder.

jj2007

Quote from: johnsa on December 11, 2017, 08:24:33 PMThe pointer syntax (->) can only be used with...

It's very unfortunate that the authors of MASM used the <> as a reserved word; same for the exclamation mark. OTOH, there was not so much choice: {any better?} ^or this^ %no good% §advocates need these§ @mail@ ...

johnsa

I know :( That's why i intentionally forced it's usage to be limited. In the normal situation with < > the tokenizer knows it's in a literal so <......-> is fine, but at least for now I'd like to keep such a major divergence from traditional asm syntax quite contained.

Vortex

Hi johnsa,

This one produces a syntax error message :

_INVOKE pAD,SetWallpaper,OFFSET DesktopImg,0

SetWallpaper.asm(41) : Error A2210: Syntax error: _INVOKE

I could not find any reference to the _VCOMINVOKE macro in the manual uasm246_ext.pdf.  No example using this macro.

Assembling the example oo2.asm, I get the following error messages :

uasm64 -win64 -c -Zp8 -Zi -Zd -Zf oo2.asm
UASM v2.46, Dec  8 2017, Masm-compatible assembler.
Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.

oo2.asm(37) : Error A2221: Missing macro argument: CVIRTUAL, parameter 2
oo2.asm(38) : Error A2221: Missing macro argument: CVIRTUAL, parameter 2
oo2.asm: 274 lines, 1 passes, 153 ms, 0 warnings, 2 errors


To fix this issue, I modified the two lines below.

OINTERFACE Entity
CVIRTUAL PrintName
CVIRTUAL SetName
ENDOINTERFACE


The corrected version :

OINTERFACE Entity
CVIRTUAL PrintName, <>
CVIRTUAL SetName, <>
ENDOINTERFACE

johnsa

You are right about oo2.asm, I must have forgot to update that sample after adding the return type to CVIRTUAL. I've updated it myside so it's correct and will be in the next package update.

_INVOKE and _I are designed to bypass the VTABLE altogether, their syntax is as follows:

_INVOKE MACRO className : REQ, method : REQ, objPtr : REQ, args : VARARG
_I MACRO className : REQ, method : REQ, objPtr : REQ, args : VARARG


_INVOKE would be for normal outer calls, and _I would be used inline.


_INVOKE MyClass, MyMethod, pObj, ......


The _V equivalents access the object through the vtable and have slightly different syntax:


_VINVOKE MACRO pInterface : REQ, Interface : REQ, Function : REQ, args : VARARG
_V MACRO pInterface : REQ, Interface : REQ, Function : REQ, args : VARARG

_VINVOKE pObj, MyClass, MyMethod, ....



I didn't include any references to VCOM or VCOMINVOKE in the documents as I didn't think anyone would call those directly / they are available.. but they're sort of "internal" to implement the COMINTERFACE and method invocation against it.

They're definitions are:


_VCOMINVOKE MACRO pInterface : REQ, Interface : REQ, Function : REQ, args : VARARG
_VCOM MACRO pInterface : REQ, Interface : REQ, Function : REQ, args : VARARG


So basically the same as the vtable based OO functions (VINVOKE and V) but they perform a double indirection.

I will update the packages shortly with fixes.

johnsa

Packages are updated, oo2.asm is fixed and the 32bit COM call issue should be fixed.

Vortex

Hi johnsa,

Thanks for the update. Here are the results of my tests.

Trying the _VCOMINVOKE macro :

_VCOMINVOKE pAD,IActiveDesktop,SetWallpaper,ADDR DesktopImg,0
_VCOMINVOKE pAD,IActiveDesktop,SetWallpaperOptions,OFFSET wpo,0
_VCOMINVOKE pAD,IActiveDesktop,ApplyChanges,AD_APPLY_ALL
_VCOMINVOKE pAD,IActiveDesktop,Release


Uasm is assembling my code without any error messages but the executable is crashing on Windows 7.

Investigating the case with the /EP option :

uasm32.exe /EP /c /coff SetWallpaper.asm

mov eax, pAD
mov eax,[eax]
invoke(_IActiveDesktop_SetWallpaperPto PTR[eax].IActiveDesktop.SetWallpaper), pAD, ADDR DesktopImg,0
mov eax, pAD
mov eax,[eax]
invoke(_IActiveDesktop_SetWallpaperOptionsPto PTR[eax].IActiveDesktop.SetWallpaperOptions), pAD, OFFSET wpo,0
mov eax, pAD
mov eax,[eax]
invoke(_IActiveDesktop_ApplyChangesPto PTR[eax].IActiveDesktop.ApplyChanges), pAD, AD_APPLY_ALL
mov eax, pAD
mov eax,[eax]
invoke(_IActiveDesktop_ReleasePto PTR[eax].IActiveDesktop.Release), pAD


The pAD parameter should not be pushed to the stack.

Disassembling the object file with objconv :

_VCOMINVOKE    pAD,IActiveDesktop,SetWallpaper,ADDR DesktopImg,0

mov     eax, dword ptr [_pAD]                   
mov     eax, dword ptr [eax]                   
push    0                                       
push    offset _DesktopImg                     
push    dword ptr [_pAD] ; <--- This line causing problem
call    dword ptr [eax+14H]


Assuming that _VCOM is equivalent to _VCOMINVOKE :

_VCOMINVOKE MACRO pInterface : REQ, Interface : REQ, Function : REQ, args : VARARG
_VCOM MACRO pInterface : REQ, Interface : REQ, Function : REQ, args : VARARG


Replacing _VCOMINVOKE  with  _VCOM :

SetWallpaper.asm(41) : Error A2210: Syntax error: _VCOM
SetWallpaper.asm(43) : Error A2210: Syntax error: _VCOM
SetWallpaper.asm(45) : Error A2210: Syntax error: _VCOM
SetWallpaper.asm(47) : Error A2210: Syntax error: _VCOM
SetWallpaper.asm: 53 lines, 1 passes, 4 ms, 0 warnings, 4 errors


Testing the arrow operator with OPTION VTABLE:ON and OPTION VTABLE:OFF

pAD->SetWallpaper(OFFSET DesktopImg,0)
pAD->SetWallpaperOptions(OFFSET wpo,0)
pAD->ApplyChanges(AD_APPLY_ALL)
pAD->Release()


pAD is again pushed to the stack :

mov eax, pAD
mov eax,[eax]
invoke(_IActiveDesktop_SetWallpaperPto PTR[eax].IActiveDesktop.SetWallpaper), pAD, OFFSET DesktopImg,0
mov eax, pAD
mov eax,[eax]
invoke(_IActiveDesktop_SetWallpaperOptionsPto PTR[eax].IActiveDesktop.SetWallpaperOptions), pAD, OFFSET wpo,0
mov eax, pAD
mov eax,[eax]
invoke(_IActiveDesktop_ApplyChangesPto PTR[eax].IActiveDesktop.ApplyChanges), pAD, AD_APPLY_ALL
mov eax, pAD
mov eax,[eax]
invoke(_IActiveDesktop_ReleasePto PTR[eax].IActiveDesktop.Release), pAD