So, When I assemble this code, I get no errors. It flies through the build. However, when I go to execute this code, it does not display the window. I am unsure of why. I have tried invoking messageboxes at the start or WinMain, but it seems it's not getting called, because the MessageBox does not show up. However, I am actually calling the WinMain function. But it seems to not be running.
Any help would be great,
Thanks!
.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
WinMain PROTO :HINSTANCE, :HINSTANCE, :LPSTR, :DWORD
WinProc PROTO :HWND, :UINT, :WPARAM, :LPARAM
.data
ClassName db "MAIN_CLASS", 0
MainTitle db "A Window in Assembly!", 0
ErrorText db "Fatal Error, the program will now close...", 0
ErrorTitle db "Fatal Error", 0
.data?
hInstance HINSTANCE ?
.code
start:
WinProc PROC hWnd:HWND, message:UINT, wParam:WPARAM, lParam:LPARAM
cmp message, WM_DESTROY
je DO_DESTROY
cmp message, WM_CLOSE
je DO_CLOSE
jmp DO_DEFAULT
DO_DESTROY:
invoke PostQuitMessage, 0
jmp DO_END
DO_CLOSE:
invoke DestroyWindow, addr hWnd
jmp DO_END
DO_DEFAULT:
invoke DefWindowProc, hWnd, message, wParam, lParam
ret
jmp DO_STOP
DO_END:
xor eax, eax
ret
DO_STOP:
WinProc ENDP
WinMain PROC hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWORD
local wc:WNDCLASSEX
local msg:MSG
local hWnd:HWND
mov wc.cbSize, SIZEOF WNDCLASSEX
mov wc.style, 0
mov wc.lpfnWndProc, offset WinProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground, COLOR_WINDOW + 1
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, offset ClassName
invoke LoadIcon, NULL, IDI_APPLICATION
mov wc.hIcon, eax
mov wc.hIconSm, eax
invoke LoadCursor, NULL, IDC_ARROW
mov wc.hCursor, eax
invoke RegisterClassEx, addr wc
cmp eax, 0
je SHOW_ERROR
invoke CreateWindowEx,
WS_EX_CLIENTEDGE,
addr ClassName,
addr MainTitle,
WS_OVERLAPPEDWINDOW,
50,
50,
600,
300,
NULL,
NULL,
hInst,
NULL
mov hWnd, eax
cmp hWnd, NULL
je SHOW_ERROR
invoke ShowWindow, hWnd, CmdShow
invoke UpdateWindow, hWnd
message_loop:
invoke GetMessage, addr msg, addr hWnd, 0, 0
cmp eax, 0
je message_loop_end
invoke TranslateMessage, addr msg
invoke DispatchMessage, addr msg
jmp message_loop
message_loop_end:
mov eax, msg.wParam
ret
jmp STOP
SHOW_ERROR:
invoke MessageBox, NULL, addr ErrorText, addr ErrorTitle, MB_OK
jmp RET_ZERO
RET_ZERO:
mov eax, 0
ret
STOP:
WinMain ENDP
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke WinMain, hInstance, NULL, NULL, 0
invoke ExitProcess, eax
end start
Thanks again!