Author Topic: ml64 and GoLink  (Read 379 times)

Vortex

  • Member
  • *****
  • Posts: 1710
ml64 and GoLink
« on: October 05, 2016, 05:55:59 AM »
ml64 object modules can be linked with GoLink :

Code: [Select]
\masm32\bin64\ml64.exe /c Window.asm
\goasm\golink /entry start Window.obj kernel32.dll user32.dll

No import libraries are required. Specifying the correct DLLs instructs GoLink to resolve the external symbols.

Code: [Select]
include \masm32\include64\masm64rt.inc

.data

ClassName   db "WndClass",0
AppName     db "Window",0

.data?

hInstance   QWORD ?
CommandLine QWORD ?

.code

start PROC

    invoke GetModuleHandle,NULL
    mov    hInstance,rax
    invoke GetCommandLineA
    mov    CommandLine,rax
    invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
    invoke ExitProcess,rax

start ENDP

WinMain PROC hInst:QWORD,hPrevInst:QWORD,CmdLine:QWORD,CmdShow:QWORD

    LOCAL wc:WNDCLASSEX
    LOCAL msg:MSG
    LOCAL hwnd:QWORD

    mov    wc.cbSize,SIZEOF WNDCLASSEX
    mov    wc.style,CS_HREDRAW or CS_VREDRAW
    mov    rax,OFFSET WndProc
    mov    wc.lpfnWndProc,rax

    xor    rax,rax
    mov    wc.cbClsExtra,eax
    mov    wc.cbWndExtra,eax
    mov    wc.hInstance,rcx
    mov    wc.hbrBackground,COLOR_WINDOW+1
    mov    wc.lpszMenuName,rax

    mov    rax,OFFSET ClassName
    mov    wc.lpszClassName,rax
    invoke LoadIcon,NULL,IDI_APPLICATION
    mov    wc.hIcon,rax
    mov    wc.hIconSm,rax
    invoke LoadCursor,NULL,IDC_ARROW
    mov    wc.hCursor,rax
    invoke RegisterClassEx,ADDR wc

    invoke CreateWindowEx,0,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
           CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,0,0,\
           hInst,0
    mov    hwnd,rax

    invoke ShowWindow,hwnd,SW_SHOWNORMAL
    invoke UpdateWindow,hwnd

msgloop:

     invoke GetMessageA,ADDR msg,NULL,0,0
     test   rax,rax
     jz     exit
     
     invoke TranslateMessage,ADDR msg
     invoke DispatchMessageA,ADDR msg
     jmp    msgloop

exit:

    mov     rax,msg.wParam
    ret

WinMain ENDP

WndProc PROC hWnd:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD

    cmp     edx,WM_DESTROY
    jne     DefWndProc

    invoke  PostQuitMessage,NULL
    jmp     EndWndProc

DefWndProc:

;   invoke  DefWindowProc,rcx,rdx,r8,r9

    call    DefWindowProc       ; small trick to call DefWindowProc wihout invoke
                                ; as rcx,rdx,r8 and r9 are already initialized
    ret

EndWndProc:

    xor rax,rax
    ret

WndProc ENDP

END