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:
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