News:

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

Main Menu

A tool to implement Interface

Started by TouEnMasm, August 27, 2020, 05:55:56 AM

Previous topic - Next topic

TouEnMasm

Hello,
This tool do the hard work to implement an interface,he generate:
* The prototypes
* the table of vectors
* The procs
He give a very few code in comment
can work in 32 or 64 with not too much problem

Run it,and give "NamedInterface,Fullpath.SDK"        ( The Interface must be described in the header)

example:
Quote
IClassFactory,h:\sdkrc100\um\unknwn.sdk

output:
Quote
.const
comment µ
  -----------  QueryInterface sample code --------
   .if ppvObject != 0
      mov rdi,ppvObject
      mov QWORD ptr [rdi], 0
   .endif
   .if riid != 0 && ppvObject != 0
      call compare
      .if rcx == 0
         mov rdi,ppvObject
         lea R11,Com_Data.ppv
         mov [rdi],R11
         mov retour,S_OK
         invoke _imp_IFileDialogEvents_AddRef,R11 ;sinon return E_NOINTERFACE
      .endif
   .endif
Finde_imp_IFileDialogEvents_QueryInterface:
   mov rax,retour
   ret
   compare:
   mov rsi,riid
   lea rdi,IID_IFileDialogEvents
   mov rcx,sizeof GUID
   repz cmpsb
   retn
   --------- AddRef sample code ---------
            mov R11,_THIS_
         inc DWORD ptr [R11+8]   ;8 size ppv
      xor rax,rax
      mov eax,DWORD ptr [R11+8]
      mov retour,rax
--------- Release sample code ---------
            mov R11,_THIS_
         dec DWORD ptr [R11+8]   ;8 size ppv
      xor rax,rax
      mov eax,DWORD ptr [R11+8]
      mov retour,rax
   -------- Init interface -------
      lea R11,objInterface.ppv
      mov ppvInterface,R11
      Interface AddRef ;not Required
      µ

COMOBJECT  STRUCT
   ; interface object
   ppv      DQ      ?   ;always first
   ; object data
   count      DD      ?
;made what you want here
COMOBJECT  ENDS

_imp_IClassFactory_QueryInterface   PROTO  _THIS_:XMASM ,riid:XMASM ,ppvObject:XMASM
_imp_IClassFactory_AddRef   PROTO       _THIS_:XMASM
_imp_IClassFactory_Release   PROTO       _THIS_:XMASM
_imp_IClassFactory_CreateInstance   PROTO  _THIS_:XMASM ,pUnkOuter:XMASM ,riid:XMASM ,ppvObject:XMASM
_imp_IClassFactory_LockServer   PROTO       _THIS_:XMASM , :XMASM
.data
vtbl_IClassFactory      dq   _imp_IClassFactory_QueryInterface
                     dq   _imp_IClassFactory_AddRef
                     dq   _imp_IClassFactory_Release
                     dq   _imp_IClassFactory_CreateInstance
                     dq   _imp_IClassFactory_LockServer

objIClassFactory   COMOBJECT      <vtbl_IClassFactory,0>
   ppvIClassFactory      dq 0
.code
;##############################################################################################
_imp_IClassFactory_QueryInterface    PROC  _THIS_:XMASM ,riid:XMASM ,ppvObject:XMASM
         Local  retour:XMASM
      mov retour,S_OK ;


         mov rax,retour
            ret
_imp_IClassFactory_QueryInterface         ENDP
;##############################################################################################
_imp_IClassFactory_AddRef    PROC       _THIS_:XMASM
         Local  retour:XMASM
      mov retour,S_OK ;


         mov rax,retour
            ret
_imp_IClassFactory_AddRef         ENDP
;##############################################################################################
_imp_IClassFactory_Release    PROC       _THIS_:XMASM
         Local  retour:XMASM
      mov retour,S_OK ;


         mov rax,retour
            ret
_imp_IClassFactory_Release         ENDP
;##############################################################################################
_imp_IClassFactory_CreateInstance    PROC  _THIS_:XMASM ,pUnkOuter:XMASM ,riid:XMASM ,ppvObject:XMASM
         Local  retour:XMASM
      mov retour,S_OK ;


         mov rax,retour
            ret
_imp_IClassFactory_CreateInstance         ENDP
;##############################################################################################
_imp_IClassFactory_LockServer    PROC       _THIS_:XMASM , :XMASM
         Local  retour:XMASM
      mov retour,S_OK ;


         mov rax,retour
            ret
_imp_IClassFactory_LockServer         ENDP




Fa is a musical note to play with CL

LiaoMi

Hi TouEnMasm,

is it possible to convert classes in the same way ?!

TouEnMasm

Hello,
I think you want to speak of C++ classes who use a very similar writing with Indirect addressing ?.
Goal will be to have a translate of them in asm.
It seems to me possible , manually,with a few work,to do that on not too much complex ones.
But this need further manual samples before to automatise that.

Fa is a musical note to play with CL