flat assembler
Message board for the users of flat assembler.

Index > Windows > Problem with : Local hwnd

Author
Thread Post new topic Reply to topic
Elektron



Joined: 18 Jun 2010
Posts: 5
Elektron
I tried to change template and is not compiling.
Translated to FASM tutorials link not working.
Code:
; Template for program using standard Win32 headers

format PE GUI 4.0
entry start

include 'win32wx.inc'

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

;INVOKE ShowWindow, HWND,SW_SHOWNORMAL
 ;       INVOKE UpdateWindow, hwnd

  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 edi, hwnd,wmsg,wparam,lparam
local ps:PAINTSTRUCT
local hwnd HWND;***This porduce compile error***
        cmp     [wmsg],WM_DESTROY
        je      .wmdestroy
  .defwndproc:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     .finish
  .wmpaint:
                invoke BeginPaint,[hwnd],ADDR ps
                mov    hdc,eax
            call ScrConv
            inc score_int32
            invoke EndPaint,hdc,ADDR ps
  .wmdestroy:
        invoke  PostQuitMessage,0
        xor     eax,eax
  .finish:
        ret
ScrConv:
        mov     eax, (score_int32)
        mov     ecx, 4             ;Se isto for alterado ,alterar a intrução seg.
        lea     ebx, [ecx+6]
lp:
        xor     edx, edx
        div     ebx
        add     edx, 48
        mov     [score_str+ecx-1], dl   
      loop      lp

        ret
endp

section '.data' data readable writeable

  _class TCHAR 'FASMWIN32',0
  _title TCHAR 'Win32 program template',0
  _error TCHAR 'Startup failed.',0

  wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class

  msg MSG

score_int32 dd 999
score_str db "CAFECAFE",0
color dd 0
section '.bss' readable writeable
hwnd dd ?

section '.idata' import data readable writeable

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

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

Thanks for your time.
Post 18 Jun 2010, 07:07
View user's profile Send private message Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
i'm between ';;' marks Smile, the code looks not finished
Code:
; Template for program using standard Win32 headers

format PE GUI 4.0 
entry start 

include 'win32wx.inc' 

section '.text' code readable executable
;;
;ps PAINTSTRUCT
;wnd dd ?
;;

  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 

;INVOKE ShowWindow, HWND,SW_SHOWNORMAL 
 ;       INVOKE UpdateWindow, hwnd 

  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] 

;1(return) 2(push ebp) 3   4   5
proc WindowProc uses ebx esi edi, hwnd,wmsg,wparam,lparam
;;
;local .ps:PAINTSTRUCT,\ ; prepend "." before var name to make it visible inside the proc only
;      .hwnd:DWORD,\
;      .hi:BYTE          ; still .hi:byte will produce an error: a macro is responsible for it
;                        ; as for me it's better to use handstyle
sub esp,sizeof.PAINTSTRUCT+4
label .ps  at ebp-5*4-sizeof.PAINTSTRUCT
label .wnd at ebp-5*5-sizeof.PAINTSTRUCT
;;
        cmp     [wmsg],WM_DESTROY
        je      .wmdestroy
        ;;
        cmp     [wmsg],WM_PAINT
        je      .wmpaint
        ;;
  .defwndproc: 
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam] 
        jmp     .finish 
  .wmpaint:
        ;;
        lea     eax,[.ps]
        push    eax                 ;addr smth = lea edx,[smth], so we save ti:me
        push    eax
        invoke  BeginPaint,[hwnd]
        call    ScrConv
        inc     [score_int32]       ;you might wanted square braces
        invoke  EndPaint,[hwnd]
        jmp     .finish
        ;;
  .wmdestroy:
        invoke  PostQuitMessage,0 
        xor     eax,eax 
  .finish: 
        ret 
ScrConv: 
        mov     eax, [score_int32] ;you might wanted square braces
        mov     ecx, 4             ;Se isto for alterado ,alterar a intrucao seg. 
        lea     ebx, [ecx+6] 
lp: 
        xor     edx, edx 
        div     ebx 
        add     edx, 48 
        mov     [score_str+ecx-1], dl    
      loop      lp 

        ret 
endp 

section '.data' data readable writeable 

  _class TCHAR 'FASMWIN32',0 
  _title TCHAR 'Win32 program template',0 
  _error TCHAR 'Startup failed.',0 

  wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class 

  msg MSG 

score_int32 dd 999 
score_str db "CAFECAFE",0 
color dd 0 
section '.bss' readable writeable 
hwnd dd ? 

section '.idata' import data readable writeable 

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

  include 'api\kernel32.inc' 
  include 'api\user32.inc' 
  include 'api\gdi32.inc'
    
Post 18 Jun 2010, 08:36
View user's profile Send private message Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
to my mind enter,%sizeof.all_vars%,0 would be better instead of standard push ebp + mov ebp,esp: looks smart + variables follow ebp(so easy to count manually)
Post 18 Jun 2010, 08:41
View user's profile Send private message Reply with quote
Elektron



Joined: 18 Jun 2010
Posts: 5
Elektron
Thank you edemko.
The code know compile but trying to execute, windows tells the exe is not ok and not attempt to execute.
Post 18 Jun 2010, 12:42
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
With your original source replace the WindowProc with this:
Code:
proc WindowProc uses ebx esi edi, hwnd,wmsg,wparam,lparam
local ps:PAINTSTRUCT,\
      hdc: DWORD

        cmp     [wmsg],WM_DESTROY
        je      .wmdestroy
  .defwndproc:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     .finish
  .wmpaint:
                invoke BeginPaint,[hwnd], addr ps
                mov    [hdc],eax
            call ScrConv
            inc [score_int32]
            invoke EndPaint,[hdc], addr ps
  .wmdestroy:
        invoke  PostQuitMessage,0
        xor     eax,eax
  .finish:
        ret
ScrConv:
        mov     eax, (score_int32)
        mov     ecx, 4             ;Se isto for alterado ,alterar a intrução seg.
        lea     ebx, [ecx+6]
lp:
        xor     edx, edx
        div     ebx
        add     edx, 48
        mov     [score_str+ecx-1], dl   
      loop      lp

        ret
endp    
Post 18 Jun 2010, 15:36
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Elektron,

Are you trying to convert score_int32 offset instead of its value?
Post 18 Jun 2010, 18:51
View user's profile Send private message Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
i press F9 and see the window
OS = WinXp sp3 prof
Post 18 Jun 2010, 19:26
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
edemko,

That's good, your vision isn't impaired then. Wink
There isn't any output done (yet, I suppose).
Post 19 Jun 2010, 01:06
View user's profile Send private message Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
edemko wrote:

prepend "." before var name to make it visible inside the proc only

i'm sorry for "the yellow press": it concerns labels only
barld wrote:

There isn't any output done (yet, I suppose).

there is
Post 19 Jun 2010, 04:55
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
edemko wrote:
there is
Oh really? Which line is supposed to be related to it?

Wait a minute. I thought you wrote "and see the window" in the sense "it doesn't show anything except basic window, just as the original template does". I'd better not read between lines. ;-)
Post 19 Jun 2010, 06:46
View user's profile Send private message Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
i meant there was output executable and the window template it created - a thing Electron had asked
Smile:
Post 19 Jun 2010, 07:00
View user's profile Send private message Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
still Electron said Windows had refused executable launching and ours one WinXpSp3 did not
Post 19 Jun 2010, 07:02
View user's profile Send private message Reply with quote
Elektron



Joined: 18 Jun 2010
Posts: 5
Elektron
I am using windows Vista.
Only locodelassembly´s code run here.
Anyway thank you all for the replies.
Sorry for the my delayed reply but i am busy reading fasm documentation and intel manuals.
My nick is Elektron not Electron.
Post 26 Jun 2010, 11:29
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.

Powered by rwasa.