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.
; ============================================================================================
; 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.