flat assembler
Message board for the users of flat assembler.

Index > Windows > I can't use constants

Author
Thread Post new topic Reply to topic
Make-Grafik



Joined: 01 Dec 2013
Posts: 2
Make-Grafik
Hello people!
I'm 16 years old and live in Germany.
My english isn't so god.
Sorry for wrong selected words and grammar. =)

I declare in line 181 to 189 constants with "equ".
But the FASM compiler show me errors.
I can't use the constants...

Here is my code (a little bit long ^^):
Code:
; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
format PE GUI
; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
section '.text' code readable executable
  push ebp
  mov ebp, esp

  push dword 0
  call [GetModuleHandleA]
  mov [hInstance], eax

  push dword IDC_CROSS
  push dword 0
  call [LoadCursorA]
  mov [hCursor], eax

  ;;;;; WND CLASS ;;;;;
  sub esp, SIZEOF_WNDCLASS

  mov dword [esp + 0], 3
  mov dword [esp + 4], WndProc
  mov dword [esp + 8], 0
  mov dword [esp +12], 0

  mov eax, [hInstance]
  mov dword [esp +16], eax
  mov dword [esp +20], 0

  mov eax, [hCursor]
  mov dword [esp +24], eax
  mov dword [esp +28], COLOR_APPWORKSPACE
  mov dword [esp +32], 0
  mov dword [esp +36], AppName

  push dword esp
  call [RegisterClassA]

  ;;;;; CREATEWINDOW ;;;;;
  push dword 0
  push dword [hInstance]
  push dword 0
  push dword 0
  push dword 250
  push dword 500
  push dword 100
  push dword 100
  push dword 0xcf0000
  push dword WindowTitle
  push dword AppName
  push dword 0x040000
  call [CreateWindowExA]

  mov [hWnd], eax
  push dword 1
  push dword [hWnd]
  call [ShowWindow]

  ;;;;; EDIT ;;;;;
  push dword 0
  push dword [hInstance]
  push dword 2
  push dword [hWnd]
  push dword 180
  push dword 275
  push dword 5
  push dword 5
  push dword 0x50201045
  push dword 0
  push dword szEditClass
  push dword 0x00000200
  call [CreateWindowExA]

  mov [hEdit1], eax
  push dword 1
  push dword [hEdit1]
  call [ShowWindow]

  push dword txtSample
  push dword [hEdit1]
  call [SetWindowTextA]

  ;;;;; BUTTON ;;;;;
  push dword 0
  push dword [hInstance]
  push dword 1
  push dword [hWnd]
  push dword 20
  push dword 275
  push dword 187
  push dword 5
  push dword 0x50001000
  push dword 0
  push dword szButtonClass
  push dword 0
  call [CreateWindowExA]

  mov [hButton1], eax
  push dword 1
  push dword [hButton1]
  call [ShowWindow]

  push dword txtButton
  push dword [hButton1]
  call [SetWindowTextA]

  ;;;;;;;;;;

  push dword MB_ICONSTOP
  call [MessageBeep]

  ;;;;; MESSAGELOOP ;;;;;
  sub esp, SIZEOF_MSG
  mov [wMsg], esp

  MessageLoop:
    push dword 0
    push dword 0
    push dword 0
    push dword [wMsg]
    call [GetMessageA]

    test eax, eax
    jz ExitMessageLoop

    push dword [wMsg]
    call [TranslateMessage]
    push dword [wMsg]
    call [DispatchMessageA]

    jmp MessageLoop

  ExitMessageLoop:
    add esp, SIZEOF_MSG

    push dword [hWnd]
    call [DestroyWindow]

    push dword [hInstance]
    push dword AppName
    call [UnregisterClassA]

    add esp, SIZEOF_WNDCLASS
    pop ebp

  ;;;;; EXIT ;;;;;
  push 0
  call [ExitProcess]

  ;;;;; WNDPROC ;;;;;
  WndProc:
    mov eax, [esp +8]
    cmp eax, WM_DESTROY
    jne WndProcNext
    push dword 0
    call [PostQuitMessage]

    WndProcNext:
      push dword [esp +16]
      push dword [esp +16]
      push dword [esp +16]
      push dword [esp +16]
      call [DefWindowProcA]

  ret 16
; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
section '.data' data readable writeable
  AppName       db 'ASMGUI', 0
  WindowTitle   db 'FASM Window Demo', 0
  hInstance     dd 0
  hCursor       dd 0
  hWnd          dd 0
  wMsg          dd 0
  hEdit1        dd 0
  szEditClass   db 'EDIT', 0
  szButtonClass db 'BUTTON', 0
  txtButton     db 'Button Control', 0
  txtSample     db 'A Editcontrol. Make-Grafik like!', 0
  hButton1      dd 0
  hDC           dd 0

  COLOR_APPWORKSPACE equ 12
  SIZEOF_WNDCLASS    equ 40
  SIZEOF_MSG         equ 28
  WM_DESTROY         equ 0x02
  WM_CREATE          equ 0x01
  DASDING            equ 0.5
  IDC_CROSS          equ 0x7f03
  MB_ICONSTOP        equ 0x10
  DEFAULT            equ 0
; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
section '.idata' import data readable writeable
  dd 0, 0, 0, rva Kernel32, rva _Kernel32
  dd 0, 0, 0, rva User32, rva _User32
  dd 0, 0, 0, 0, 0


  Kernel32 db 'Kernel32.dll', 0
  _Kernel32:
    ExitProcess      dd rva _ExitProcess
    GetModuleHandleA dd rva _GetModuleHandleA
  dd 0

  _ExitProcess dw 0
    db 'ExitProcess', 0

  _GetModuleHandleA dw 0
    db 'GetModuleHandleA', 0


  User32 db 'User32.dll', 0
  _User32:
    LoadCursorA      dd rva _LoadCursorA
    RegisterClassA   dd rva _RegisterClassA
    UnregisterClassA dd rva _UnregisterClassA
    CreateWindowExA  dd rva _CreateWindowExA
    DestroyWindow    dd rva _DestroyWindow
    ShowWindow       dd rva _ShowWindow
    GetMessageA      dd rva _GetMessageA
    TranslateMessage dd rva _TranslateMessage
    DispatchMessageA dd rva _DispatchMessageA
    DefWindowProcA   dd rva _DefWindowProcA
    PostQuitMessage  dd rva _PostQuitMessage
    MessageBeep      dd rva _MessageBeep
    SetWindowTextA   dd rva _SetWindowTextA
  dd 0

  _LoadCursorA dw 0
    db 'LoadCursorA', 0

  _RegisterClassA dw 0
    db 'RegisterClassA', 0

  _UnregisterClassA dw 0
    db 'UnregisterClassA', 0

  _CreateWindowExA dw 0
    db 'CreateWindowExA', 0

  _DestroyWindow dw 0
    db 'DestroyWindow', 0

  _ShowWindow dw 0
    db 'ShowWindow', 0

  _GetMessageA dw 0
    db 'GetMessageA', 0

  _TranslateMessage dw 0
    db 'TranslateMessage', 0

  _DispatchMessageA dw 0
    db 'DispatchMessageA', 0

  _DefWindowProcA dw 0
    db 'DefWindowProcA', 0

  _PostQuitMessage dw 0
    db 'PostQuitMessage', 0

  _MessageBeep dw 0
    db 'MessageBeep', 0

  _SetWindowTextA dw 0
    db 'SetWindowTextA', 0
; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +
section '.reloc' fixups data readable discardable
; ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ +    


I hope you can help me. =)
PS: I learn asm yet.

Dear Make-Grafik
Post 01 Dec 2013, 03:30
View user's profile Send private message Reply with quote
Kenneth



Joined: 16 Nov 2005
Posts: 38
Location: United States of America
Kenneth
You must use equ or the define directive to define a symbolic constant before you use it. You can also just use '=' instead of equ which makes it an assembly time constant and you can define it anywhere in the source.
Code:
  ;change equ to =
COLOR_APPWORKSPACE = 12
  SIZEOF_WNDCLASS    = 40
  SIZEOF_MSG         = 28
  WM_DESTROY         = 0x02
  WM_CREATE          = 0x01
  DASDING            = 0.5
  IDC_CROSS          = 0x7f03
  MB_ICONSTOP        = 0x10
  DEFAULT            = 0    

Compiles and runs fine.
Post 01 Dec 2013, 04:20
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Make-Grafik



Joined: 01 Dec 2013
Posts: 2
Make-Grafik
Ah =D
Thank you!
Post 01 Dec 2013, 13:08
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.