flat assembler
Message board for the users of flat assembler.

Index > Windows > Win64 headers

Author
Thread Post new topic Reply to topic
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8354
Location: Kraków, Poland
Tomasz Grysztar 16 Sep 2006, 22:25
Thanks to the 64-bit test machine I've got from HyperVista I was finally able to do some real-time Win64 development. I improved and/or corrected some of my earlier preparations and with the latest fasmw finally the preliminary headers for Win64 come. There are no extended headers yet, so you can choose only from WIN64A.INC and WIN64W.INC for now. Also there are only structures/constants for KERNEL/USER libraries available, and many of them are still yet to be tested.

Below are two examples, the 64-bit versions of the standard TEMPLATE.ASM and USECOM.ASM examples from fasmw package. I perhaps will include them in future packages among the 32-bit examples, too.

Note that "fastcall" macro and "invoke", which is based on it, does allocate and de-allocate stack each time you use it. This tends to make unoptimized code, so you may prefer to call the function manually; see this thread for the details on development of those macros.

64-bit version of TEMPLATE.ASM:
Code:
format PE64 GUI 5.0
entry start

include 'win64a.inc'

section '.data' data readable writeable

  _title db 'Win64 program template',0
  _class db 'FASMWIN64',0

  wc WNDCLASSEX sizeof.WNDCLASSEX,0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class,NULL

  msg MSG

section '.code' code readable executable

  start:
        sub     rsp,8           ; Make stack dqword aligned

        invoke  GetModuleHandle,0
        mov     [wc.hInstance],rax
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],rax
        mov     [wc.hIconSm],rax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],rax
        invoke  RegisterClassEx,wc

        invoke  CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,128,128,256,192,NULL,NULL,[wc.hInstance],NULL

  msg_loop:
        invoke  GetMessage,msg,NULL,0,0
        or      eax,eax
        jz      end_loop
        invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
        jmp     msg_loop

  end_loop:
        invoke  ExitProcess,[msg.wParam]

proc WindowProc uses rbx rsi rdi, hwnd,wmsg,wparam,lparam

; Note that first four parameters are passed in registers,
; while names given in the declaration of procedure refer to the stack
; space reserved for them - you may store them there to be later accessible
; if the contents of registers gets destroyed. This may look like:
;       mov     [hwnd],rcx
;       mov     [wmsg],edx
;       mov     [wparam],r8
;       mov     [lparam],r9

        cmp     edx,WM_DESTROY
        je      wmdestroy
  defwndproc:
        invoke  DefWindowProc,rcx,rdx,r8,r9
        jmp     finish
  wmdestroy:
        invoke  PostQuitMessage,0
        xor     eax,eax
  finish:
        ret

endp

section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',\
          user32,'USER32.DLL'

  include 'apia\kernel32.inc'
  include 'apia\user32.inc'    

64-bit version of USECOM.ASM:
Code:
; Component Object Model usage demonstration

format PE64 GUI 5.0
entry start

include 'win64a.inc'

struc GUID def
 {
   match d1-d2-d3-d4-d5, def
    \{
      .Data1 dd 0x\#d1
      .Data2 dw 0x\#d2
      .Data3 dw 0x\#d3
      .Data4 db 0x\#d4 shr 8,0x\#d4 and 0FFh
      .Data5 db 0x\#d5 shr 40,0x\#d5 shr 32 and 0FFh,0x\#d5 shr 24 and 0FFh,0x\#d5 shr 16 and 0FFh,0x\#d5 shr 8 and 0FFh,0x\#d5 and 0FFh
    \}
 }

interface ITaskBarList,\
           QueryInterface,\
           AddRef,\
           Release,\
           HrInit,\
           AddTab,\
           DeleteTab,\
           ActivateTab,\
           SetActiveAlt

CLSCTX_INPROC_SERVER        = 0x1
CLSCTX_INPROC_HANDLER       = 0x2
CLSCTX_LOCAL_SERVER         = 0x4
CLSCTX_INPROC_SERVER16      = 0x8
CLSCTX_REMOTE_SERVER        = 0x10
CLSCTX_INPROC_HANDLER16     = 0x20
CLSCTX_INPROC_SERVERX86     = 0x40
CLSCTX_INPROC_HANDLERX86    = 0x80
CLSCTX_ESERVER_HANDLER      = 0x100
CLSCTX_NO_CODE_DOWNLOAD     = 0x400
CLSCTX_NO_CUSTOM_MARSHAL    = 0x1000
CLSCTX_ENABLE_CODE_DOWNLOAD = 0x2000
CLSCTX_NO_FAILURE_LOG       = 0x4000
CLSCTX_DISABLE_AAA          = 0x8000
CLSCTX_ENABLE_AAA           = 0x10000
CLSCTX_FROM_DEFAULT_CONTEXT = 0x20000

ID_EXIT = IDCANCEL
ID_SHOW = 100
ID_HIDE = 101

IDD_COMDEMO = 1

section '.data' data readable writeable

 CLSID_TaskbarList GUID 56FDF344-FD6D-11D0-958A-006097C9A090
 IID_ITaskbarList GUID 56FDF342-FD6D-11D0-958A-006097C9A090

 ShellTaskBar ITaskBarList

section '.code' code readable executable

 start:
        sub     rsp,8           ; Make stack dqword aligned

        invoke  CoInitialize,NULL
        invoke  CoCreateInstance,CLSID_TaskbarList,NULL,CLSCTX_INPROC_SERVER,IID_ITaskbarList,ShellTaskBar

        invoke  GetModuleHandle,0
        invoke  DialogBoxParam,rax,IDD_COMDEMO,HWND_DESKTOP,COMDemo,0

        cominvk ShellTaskBar,Release

        invoke  ExitProcess,0

proc COMDemo uses rbx rsi rdi, hwnd,msg,wparam,lparam
        mov     [hwnd],rcx
        cmp     edx,WM_INITDIALOG
        je      wminitdialog
        cmp     edx,WM_COMMAND
        je      wmcommand
        cmp     edx,WM_CLOSE
        je      wmclose
        xor     eax,eax
        jmp     finish
  wminitdialog:
        jmp     processed
  wmcommand:
        cmp     r8,BN_CLICKED shl 16 + ID_EXIT
        je      wmclose
        cmp     r8,BN_CLICKED shl 16 + ID_SHOW
        je      show
        cmp     r8,BN_CLICKED shl 16 + ID_HIDE
        jne     processed
  hide:
        cominvk ShellTaskBar,HrInit
        cominvk ShellTaskBar,DeleteTab,[hwnd]
        jmp     processed
  show:
        mov     rbx,[ShellTaskBar]
        comcall rbx,ITaskBarList,HrInit
        comcall rbx,ITaskBarList,AddTab,[hwnd]
        comcall rbx,ITaskBarList,ActivateTab,[hwnd]
        jmp     processed
  wmclose:
        invoke  EndDialog,[hwnd],0
  processed:
        mov     eax,1
  finish:
        ret
endp

section '.idata' import data readable

  library kernel,'KERNEL32.DLL',\
          user,'USER32.DLL',\
          ole,'OLE32.DLL'

  import kernel,\
         GetModuleHandle,'GetModuleHandleA',\
         ExitProcess,'ExitProcess'

  import user,\
         DialogBoxParam,'DialogBoxParamA',\
         EndDialog,'EndDialog'

  import ole,\
         CoInitialize,'CoInitialize',\
         CoCreateInstance,'CoCreateInstance'

section '.rsrc' resource data readable

  directory RT_DIALOG,dialogs

  resource dialogs,\
           IDD_COMDEMO,LANG_ENGLISH+SUBLANG_DEFAULT,comdemo

  dialog comdemo,'Taskbar item control',70,70,170,24,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME
    dialogitem 'BUTTON','Show',ID_SHOW,4,4,45,15,WS_VISIBLE+WS_TABSTOP
    dialogitem 'BUTTON','Hide',ID_HIDE,54,4,45,15,WS_VISIBLE+WS_TABSTOP
    dialogitem 'BUTTON','Exit',ID_EXIT,120,4,45,15,WS_VISIBLE+WS_TABSTOP
  enddialog    
Post 16 Sep 2006, 22:25
View user's profile Send private message Visit poster's website Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost 16 Sep 2006, 22:48
Thanks to HyperVista for helping further fasm.

_________________
redghost.ca
Post 16 Sep 2006, 22:48
View user's profile Send private message AIM Address MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 16 Sep 2006, 23:58
yes, thanks you both, guys. now just to have more examples. I do have 64bit machine, but only 32bit XP OS, so i can't help:|
Post 16 Sep 2006, 23:58
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost 17 Sep 2006, 00:55
vid wrote:
yes, thanks you both, guys. now just to have more examples. I do have 64bit machine, but only 32bit XP OS, so i can't help:|


Exact same here, maybe I will install a 64bit Linux if I get around to it.

_________________
redghost.ca
Post 17 Sep 2006, 00:55
View user's profile Send private message AIM Address MSN Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8354
Location: Kraków, Poland
Tomasz Grysztar 17 Sep 2006, 00:56
I am using the 120-day trial of XP x64 edition, perhaps you also could.
http://www.microsoft.com/windowsxp/64bit/facts/trial.mspx
Post 17 Sep 2006, 00:56
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 17 Sep 2006, 01:24
Same here, I'm wasting my 64-bit processor for about an year, I use very few times ubuntu 64 but I'm planning to use it more in the near future (but first changing to another 64-bit distro because I find ubuntu really bad for developing, too much unprepered). Most of the time I use a WinXP 32-bit...

Thanks to both!!
Post 17 Sep 2006, 01:24
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 17 Sep 2006, 18:35
Tomasz, 120-day trial is a mistake or you really have that time to test?

This is what my mail says:
Quote:

Version: Windows XP Professional x64 Edition, 180-day Evaluation (English)


I'm surprised that Microsoft let's me test it so long time Confused (6 months!!)
Post 17 Sep 2006, 18:35
View user's profile Send private message Reply with quote
adderek



Joined: 05 Oct 2008
Posts: 1
adderek 05 Oct 2008, 22:16
Hi !
Thanks for this post. I was fighting with that problem and was unable to solve it. I thought that everything was OK with the code - but I got WinAPI error messages 0x00000578 "ERROR_INVALID_WINDOW_HANDLE".
I should have been traced the code - then I would find out that CreateWindowEx in fact called the window procedure. But I didn't - 3 hours wasted.
And now I know that all of this was caused by this stack/registers mess when going to x86_64.

Thanks Tomku!
Post 05 Oct 2008, 22:16
View user's profile Send private message Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav 07 Oct 2008, 14:31
why don't use vmware on x86 host to run x64 guest OS?
Post 07 Oct 2008, 14:31
View user's profile Send private message 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.