程式語言 - ObjAsm - 如何取得Object Template Address



取得方式

mov esi, offset $ObjTmpl(XXX)

main.asm

%include @Environ(OBJASM_PATH)\Code\Macros\Model.inc
SysSetup OOP, WIN32, ANSI_STRING
   
MakeObjects Primer
  
    .const 
Object Base, , Primer
    VirtualMethod Print
ObjectEnd
   
Object Child, , Base
    RedefineMethod Print
ObjectEnd
   
    .code
PrintMsg proc uses esi, szInfo : POINTER
    local r : DWORD
    local dwLen : DWORD

    mov dwLen, $invoke(strlen, szInfo)
    invoke GetStdHandle, STD_OUTPUT_HANDLE
    mov esi, eax
    invoke WriteConsole, esi, szInfo, dwLen, addr r, NULL
    ret
PrintMsg endp

Method Base.Print
    jmp @f
    szBaseInfo db "Base Class",10,0
@@:

    invoke PrintMsg, addr szBaseInfo
MethodEnd
  
Method Child.Print
    jmp @f
    szChildInfo db "Child Class",10,0
@@:

    invoke PrintMsg, addr szChildInfo
MethodEnd

start proc
    SysInit
    mov esi, offset $ObjTmpl(Base)
    OCall esi::Base.Print

    mov esi, offset $ObjTmpl(Child)
    OCall esi::Child.Print

    mov esi, offset $ObjTmpl(Child)
    OCall esi::Base.Print
    SysDone
    invoke ExitProcess, 0
start endp
   
end

P.S. Link:c:\objasm\Code\Lib\32\Windows\msvcrt.lib

結果

Base Class
Child Class
Child Class