程式語言 - 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
   
Object Base, , Primer
    VirtualMethod Print
ObjectEnd
    
Object Child, , Base
    RedefineMethod Print
ObjectEnd
    
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
    invoke PrintMsg, $OfsCStr("Base Class", 10, 13)
MethodEnd
   
Method Child.Print
    invoke PrintMsg, $OfsCStr("Child Class", 10, 13)
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

編譯、執行

$ uasm -Fl -coff main.S
$ i686-w64-mingw32-ld \
    main.o -o main.exe \
    -e _start@0 \
    -L/opt/wadk/objasm/Code/Lib/32/Windows \
    -L/opt/wadk/objasm/Code/Lib/32/ObjAsm \
    -lObjMem32 \
    -lkernel32 \
    -luser32 \
    -ladvapi32 \
    -lgdi32 \
    -lopengl32 \
    -lmsvcrt

$ wine main.exe
    Base Class
    Child Class
    Child Class