flat assembler
Message board for the users of flat assembler.

flat assembler > Examples and Tutorials > Universal 64 bit GUI entry

Author
Thread Post new topic Reply to topic
TightCoderEx



Joined: 14 Feb 2013
Posts: 58
Location: Alberta
Just thought I would share what I think to be a universal entry point to 64 bit GUI applications. There are a few things that I'm beginning to focus on, some due to response on recent posts.


    1: Cleaner formatting of source.
    2: Focus on code rather than saving bytes.
    3: More detail in documenting.

You'll probably notice that I've dropped using INVOKE. It's just a personal preference that I like there to be as much a one to one correlation between object and source as possible. There shouldn't be any need to put anything else in here as what the initialization process can't handle, messages like WM_ACTIVATE and the like can.

Code:
; ============================================================================================
; Universal entry point to 64 bit GUI applications.                              ; 005D =  93
; --------------------------------------------------------------------------------------------

  Begin:
        enter   sizeof.MSG, 0                   ; frame for MSG structure.
        mov     rbx, rsp                        ; Establish base pointer to MSG.
        or      [rbx + MSG.wParam], -1          ; Set default app return value.

    ; If InitApp fails, CF = 1 and procedure will have invoked some sort of error dialog.

        call    InitApp                         ; Startup app outside event driven processes.
        jc      .Done

        sub     rsp, 32                         ; Frame for pump API's

   @@:  xor      r9,  r9                        ; wMsgFilterMax
        mov      r8,  r9                        ; wMsgFilterMin
        mov     rdx,  r9                        ; hWnd
        mov     rcx, rbx                        ; lpMsg
        call    [GetMessage]
        or      eax, eax
        jz      .Done - 4                       ; App done, leave and kill pumps frame.

        inc     eax                             ; Bump to ZF = 1 if return was -1.
        jnz     @F

    ; Extended error handling in so much as error dialog is more informative and procedure
    ; displays GetLastError.

        push    MB_OK + MB_ICONSTOP             ; MessageBox response.
        push    .Done - 4                       ; Probably don't need to cleanup proc frame.
        jmp     ExtErr                          ; Show error and bail from app.

   @@:  mov     rcx, rbx                        ; lpMsg
        call    [TranslateMessage]
        mov     rcx, rbx                        ; lpMsg
        call    [DispatchMessage]
        jmp     @B

        add     rsp, 32                         ; Kill API frame.

  .Done:
        mov     rcx, [rbx + MSG.wParam]         ; Retrieve value returned by pump.
        leave                                   ; Kill procedure frame.
        jmp     [ExitProcess]                   ; Ends calling proc and all its threads.

    

Subsequent posts will detail what ExtErr does, but can be eliminated quite easily by taking those lines of code out, or maybe just commenting them out.
Post 01 Jul 2013, 16:59
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2791
Location: dank orb
"add rsp, 32" is completely superfluous as LEAVE is the same as:
Code:
mov rsp,rbp
pop rbp    

_________________
¯\(°_o)/¯ unlicense.org
Post 01 Jul 2013, 17:10
View user's profile Send private message Visit poster's website Reply with quote
TightCoderEx



Joined: 14 Feb 2013
Posts: 58
Location: Alberta
Yes is it, which prompts this version with an 7 byte saving.

The corresponding
Code:
        sub     rsp, 32
    
removed and replaced with
Code:
        enter   sizeof.MSG + 32, 0              ; frame for MSG structure.
        lea     rbx, [rbp - sizeof.MSG]         ; Establish base pointer to MSG.
    
Post 01 Jul 2013, 18:12
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.