flat assembler
Message board for the users of flat assembler.

Index > Windows > simple window crushes

Author
Thread Post new topic Reply to topic
Nomad



Joined: 08 Oct 2004
Posts: 4
Nomad 08 Oct 2004, 08:18
hi to all
I'm newbie in FASM (yesterday migrated from MASM because I want to study OpenGL, but in MASM it's very uncomfortable)

but when I'm trying to create simples window, my program crushes! Sad
maybe I make some mistakes in FASM-specific syntax?? please, give me advice

here's my program, where's error??

Code:
format PE GUI 4.0
entry start
      include 'include\win32a.inc'

        section '.data' data readable writeable
          hwnd   dd   ?
          hInst  dd   ?

          wc    WNDCLASSEX
          msg   MSG

          szClassName   db   'newclass', 00
          szAppName     db   'FASM', 00

        section '.code' code readable executable
start:
          xor eax, eax
          invoke GetModuleHandle, eax
          mov [hInst],eax
          mov [wc.hInstance], eax
          xor eax, eax
          invoke LoadIcon, eax, IDI_WARNING
          mov [wc.hIcon], eax
          xor eax, eax
          invoke LoadCursor, eax, IDC_HELP
          mov [wc.hCursor], eax
          mov [wc.style], CS_OWNDC
          xor eax, eax
          mov [wc.lpfnWndProc],WinProc
          mov [wc.cbClsExtra], eax
          mov [wc.cbWndExtra], eax
          mov [wc.hbrBackground], COLOR_WINDOW + 01
          mov [wc.lpszMenuName], eax
          mov [wc.lpszClassName], szClassName
          invoke RegisterClassEx, wc

          xor eax, eax
          invoke CreateWindowEx, eax, szClassName, szAppName, WS_VISIBLE or WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN or\
                                 WS_CLIPSIBLINGS, eax, eax, 800, 600, eax, eax, [hInst], eax
          mov [hwnd], eax

msg_loop:
          xor eax, eax
          invoke GetMessage, msg, eax, eax, eax
          test eax,eax
            jz end_loop
          invoke TranslateMessage, msg
          invoke DispatchMessage, msg
            jmp msg_loop
end_loop:
          invoke ExitProcess, [msg.wParam]


proc WinProc, wnd,wmsg,wparam,lparam
        push    ebx esi edi
        cmp     [wmsg], WM_DESTROY
        je      wmDestroy
  defwndproc:
        invoke  DefWindowProc,[wnd],[wmsg],[wparam],[lparam]
        jmp     finish
  wmDestroy:
        invoke  PostQuitMessage,00
        xor     eax,eax
  finish:
        pop     edi esi ebx
          ret
    endp

         ;....
        ;import DLLs...
    

and even this useless program crushes with reason:

The instruction at 0x0006FE1B referenced memory at 0x0000003A. The memory cpuld not be "written".

Sad
Post 08 Oct 2004, 08:18
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 08 Oct 2004, 08:50
Two corrections are needed:

1) Initialize cbSize field of WNDCLASSEX before calling RegisterClassEx:
Code:
mov [wc.cbSize],sizeof.WNDCLASSEX    


2) Use "return" macro instead of "ret" to exit the procedure.
Post 08 Oct 2004, 08:50
View user's profile Send private message Visit poster's website Reply with quote
Nomad



Joined: 08 Oct 2004
Posts: 4
Nomad 08 Oct 2004, 09:22
cbSize was initializied, I forgot to type it here

uhu, problem was in RET opcode
thank you
Post 08 Oct 2004, 09:22
View user's profile Send private message Reply with quote
Nomad



Joined: 08 Oct 2004
Posts: 4
Nomad 08 Oct 2004, 09:29
err.. another problem
there is no DEVMODE structure...
MASM implementation doesn't match.. how to add this struct?
Post 08 Oct 2004, 09:29
View user's profile Send private message Reply with quote
Nomad



Joined: 08 Oct 2004
Posts: 4
Nomad 08 Oct 2004, 15:36
well, I tryed to add this structure by myself, but it don't want to work ;(
here's begin:

Code:
 struct DEVMODE
  .dmDeviceName    db   32 dup(?)
  .dmSpecVersion    dw   ?
  .dmDriverVersion   dw   ?
;....
    

and so on
but compiler gives me an error:
Extra characters on line: DEVMODE.dmDeviceName db 32 dup(?)
how to avoid this?
Post 08 Oct 2004, 15:36
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 08 Oct 2004, 15:53
Use
Code:
.dmDeviceName rb 32    
instead.
Post 08 Oct 2004, 15:53
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.