flat assembler
Message board for the users of flat assembler.

Index > Windows > registering local WNDCLASSEX - invalid value

Author
Thread Post new topic Reply to topic
Franc[e]sco



Joined: 22 Jan 2012
Posts: 2
Franc[e]sco 22 Jan 2012, 17:03
Hello, I'm trying to learn some fasm by making a win32 GUI. Everything went smooth until I decided to make my WNDCLASS local to WinMain proc. Even with the addr operator it wont compile:

line 72: pushd addr ..var?Tw

Source:
Code:
format PE GUI 4.0
entry start

include 'win32w.inc'

; Data
section '.data' data readable writeable

   _name TCHAR 'HelloWnd', 0
   _hwnd dd ?

   WinMain dd _WinMain

; Code
section '.code' code readable executable
start:
   invoke GetModuleHandle, 0
   mov ebx, eax
   invoke GetCommandLine
   invoke WinMain, ebx, NULL, eax, SW_SHOWDEFAULT
   invoke ExitProcess, eax

proc WndProc uses ebx, hwnd, msg, wParam, lParam
   mov ebx, [msg]
   cmp ebx, WM_CLOSE
   je .close
   cmp ebx, WM_DESTROY
   je .destroy
   jmp .default

 .close:
   invoke DestroyWindow, [hwnd]
   mov eax, 0
   jmp .quit

 .destroy:
   invoke PostQuitMessage, 0
   mov eax, 0
   jmp .quit

 .default:
   invoke DefWindowProc, [hwnd], [msg], [wParam], [lParam]
   ; WINAPI return values are already stored in eax

 .quit:
   ret
endp

proc _WinMain uses ebx, hInstance, hPrevInstance, lpCmdLine, nCmdShow
   local msg:MSG
   local wc:WNDCLASSEX
   locals
      szError:TCHAR rb 512
   endl

   mov eax, 0

   mov ebx, [hInstance]
   mov [wc.cbSize], sizeof.WNDCLASSEX
   mov [wc.style], 0
   mov [wc.lpfnWndProc], WndProc
   mov [wc.cbClsExtra], 0
   mov [wc.cbWndExtra], 0
   mov [wc.hInstance], ebx
   mov [wc.hIcon], NULL
   mov [wc.hCursor], NULL
   mov [wc.hbrBackground], COLOR_WINDOW+1
   mov [wc.lpszMenuName], NULL
   mov [wc.lpszClassName], _name
   mov [wc.hIconSm], NULL

   invoke RegisterClassEx, addr wc
   test eax, eax ; if true zero flag will be 0
   jnz .registered

   locals
      szRegFail TCHAR 'Window registration failed! GLE=0x%.8x', 0
   endl
   invoke GetLastError
   ccall [swprintf_s], addr szError, 512, addr szRegFail, eax
   invoke MessageBox, HWND_DESKTOP, addr szError, _name, MB_OK
   jmp .quit

 .registered:
   invoke CreateWindowEx,\
      WS_EX_CLIENTEDGE,\
      _name,\
      _name,\
      WS_OVERLAPPEDWINDOW,\
      CW_USEDEFAULT, CW_USEDEFAULT, 640, 360,\
      HWND_DESKTOP, NULL, [hInstance], NULL

   mov [_hwnd], eax
   test eax, eax
   jz .created
   locals
      szCreationFail TCHAR 'Window creation failed! GLE=0x%.8x', 0
   endl
   invoke GetLastError
   ccall [swprintf_s], addr szError, 512, addr szCreationFail, eax
   invoke MessageBox, HWND_DESKTOP, addr szError, _name, MB_OK
   jmp .quit

 .created:
   invoke ShowWindow, [_hwnd], [nCmdShow]
   invoke UpdateWindow, [_hwnd]

 .message_loop:
   invoke GetMessage, addr msg, NULL, 0, 0
   test eax, eax
   jz .message_loop_end
   invoke TranslateMessage, addr msg
   invoke DispatchMessage, addr msg
   jmp .message_loop

 .message_loop_end:
   mov eax, [msg.wParam]

 .quit:
  ret
endp

; Imports
section '.idata' import data readable writeable

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

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

   import msvcrt,\
      swprintf_s, 'swprintf_s'    


Also, just wondering: why can't I use CreateWindow since I don't need the extended stuff? It doesnt seem to exist
Post 22 Jan 2012, 17:03
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 22 Jan 2012, 17:27
The address of wc is esp-(some value) which cannot be encoded in push so try "lea eax,[wc]" and "invoke RegisterClassEx, eax", hopefully that'll fix it.
Post 22 Jan 2012, 17:27
View user's profile Send private message Reply with quote
Franc[e]sco



Joined: 22 Jan 2012
Posts: 2
Franc[e]sco 22 Jan 2012, 17:40
That fixed it! Thanks
Post 22 Jan 2012, 17:40
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1660
Location: Toronto, Canada
AsmGuru62 22 Jan 2012, 18:12
'CreateWindow' is a Win API macro, where exStyle is set to zero.
Post 22 Jan 2012, 18:12
View user's profile Send private message Send e-mail 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.