flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Heap > What you think about such syntax

Author
Thread Post new topic Reply to topic
ProMiNick



Joined: 24 Mar 2012
Posts: 101
Location: Russian Federation, Sochi

What you think about such syntax


Code:

; Template for program using standard Win32 headers

format PE GUI 4.0
entry start

include 'win32w.inc'

struc ptr [val] { common . dd ? }
macro ptr [val] {   dd ? }

struc HNDL [val] { common . dd ? }
macro HNDL [val] {   dd ? }

; for x64 they would be same

;struc ptr [val] { common . dq ? }
;macro ptr [val] {   dq ? }

;struc HNDL [val] { common . dq ? }
;macro HNDL [val] {   dq ? }

struct WNDCLASS2
  style         dd ?
  lpfnWndProc   ptr *proc actually we can write here almost everithing exept curved braces and unclosed quote
  cbClsExtra    dd ?
  cbWndExtra    dd ?
  hInstance     HNDL
  hIcon         HNDL
  hCursor       HNDL
  hbrBackground HNDL
  lpszMenuName  ptr *string
  lpszClassName ptr *string
ends

struct PROPSHEETPAGE2
  dwSize        dd ?
  dwFlags       dd ?
  hInstance     HNDL ; dq aligned
  union
    pszTemplate ptr *string ; dq aligned
    pResource   ptr *resID
  ends
  union
    hIcon       HNDL        ; dq aligned
    pszIcon     ptr *string ; dq aligned
  ends
  pszTitle      ptr *string ; dq aligned
  pfnDlgProc    ptr *proc   ; dq aligned
  lParam        dd ?        ;,?  - needed for alignment
  pfnCallback   ptr *proc   ; dq aligned
  pcRefParent   ptr all after word "ptr" ignored and it only for readability purposes; dq aligned
ends

struct PROPSHEETHEADER2
  dwSize        dd ?
  dwFlags       dd ?
  hwndParent    HNDL ; dq aligned
  hInstance     HNDL ; dq aligned
  union
    hIcon       HNDL ; dq aligned
    pszIcon     ptr *string  ; dq aligned
  ends
  pszCaption    ptr *string  ; dq aligned
  nPages        dd ?   ;,?  - needed for alignment
  union
    pStartPage  ptr *resID or ptr *string  ; dq aligned
    nStartPage  dd ?
  ends
  ppsp          ptr *PROPSHEETPAGE[] ; dq aligned
  pfnCallback   ptr *proc  ; dq aligned
ends

section '.text' code readable executable

  start:

        invoke  GetModuleHandle,0
        mov     [wc.hInstance],eax
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClass,wc
        test    eax,eax
        jz      error

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

  msg_loop:
        invoke  GetMessage,msg,NULL,0,0
        cmp     eax,1
        jb      end_loop
        jne     msg_loop
        invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
        jmp     msg_loop

  error:
        invoke  MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK

  end_loop:
        invoke  ExitProcess,[msg.wParam]

proc WindowProc uses ebx esi edihwnd,wmsg,wparam,lparam
        cmp     [wmsg],WM_DESTROY
        je      .wmdestroy
  .defwndproc:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     .finish
  .wmdestroy:
        invoke  PostQuitMessage,0
        xor     eax,eax
  .finish:
        ret
endp

section '.data' data readable writeable

  _class TCHAR 'FASMWIN32',0
  _title TCHAR 'Win32 program template',0
  _error TCHAR 'Startup failed.',0
  ;used new syntax defined WNDCLASS2
  wc WNDCLASS2 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class

  msg MSG

section '.idata' import data readable writeable

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

  include 'api\kernel32.inc'
  include 'api\user32.inc'



disadvantage: 1 labeled ptr or HNDL per line (I think not critical, but macros are compact & fast)
disadvantage: always uninitialized (they actually for defining structures for crosscompatibility of includes for x86 & x64, when will needed to use initialized value there are dd & dq).

I have a question about alignment of windows standard structures: structures theyself aligned about 4 or 8 byte boundary? can I use standart alignment macro inside definition of structure members? Or I should write new one that take as alignment base not start of section, but start of structure itself?

_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
Post 21 Jan 2018, 00:21
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15387
Location: Monstropolis

Re: What you think about such syntax


ProMiNick wrote:
I have a question about alignment of windows standard structures: structures theyself aligned about 4 or 8 byte boundary? can I use standart alignment macro inside definition of structure members? Or I should write new one that take as alignment base not start of section, but start of structure itself?

The fasm native "align" directive doesn't work correctly within the struct macros. You will have to write your own with db or rb referenced from the start of the the structure.
Post 21 Jan 2018, 02:31
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 can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2017, Tomasz Grysztar.