Can anybody give the working win32 window application source code?
Or please tell me where is the error.
%include 'win32n.inc';
extern MessageBoxA;
import MessageBoxA user32.dll;
extern LoadIconA;
import LoadIconA user32.dll;
extern RegisterClassA;
import RegisterClassA user32.dll;
extern RegisterClassExA;
import RegisterClassExA user32.dll;
extern CreateWindowExA;
import CreateWindowExA user32.dll;
extern ShowWindow;
import ShowWindow user32.dll;
extern UpdateWindow;
import UpdateWindow user32.dll;
extern GetMessageA;
import GetMessageA user32.dll;
extern TranslateMessage;
import TranslateMessage user32.dll;
extern DispatchMessageA;
import DispatchMessageA user32.dll;
extern DefWindowProcA;
import DefWindowProcA user32.dll;
extern GetModuleHandleA;
import GetModuleHandleA kernel32.dll;
extern ExitProcess;
import ExitProcess kernel32.dll;
extern GetLastError;
import GetLastError kernel32.dll;
extern FormatMessageA;
import FormatMessageA kernel32.dll;
extern LocalFree;
import LocalFree kernel32.dll;
;====Data Segment=====================================================================
section data use32 class=data;
Caption db 'Hello', 0;
Message db 'Hello, world!', 10, 13, 0;
ErrorCaption db 'Error ', 0;
msgErrorInRegisteringClass db 'Error in registering class', 0;
ClassName db 'Assembler', 0;
WindowClass : istruc WNDCLASS
at WNDCLASS.Style, dd CS_HREDRAW | CS_VREDRAW;
at WNDCLASS.lpfnWndProc, dd WinMain;
at WNDCLASS.cbClsExtra, dd 0;
at WNDCLASS.cbWndExtra, dd 0;
at WNDCLASS.hInstance, dd 0;
at WNDCLASS.hIcon, dd 0;
at WNDCLASS.hCursor, dd 0;
at WNDCLASS.hbrBackground, dd 0;
at WNDCLASS.lpszMenuName, dd 0;
at WNDCLASS.lpszClassName, dd ClassName;
iend
WindowClassEx : istruc WNDCLASSEX
at WNDCLASSEX.cbSize, dd 48;
at WNDCLASSEX.Style, dd CS_HREDRAW | CS_VREDRAW;
at WNDCLASSEX.lpfnWndProc, dd WinMain;
at WNDCLASSEX.cbClsExtra, dd 0;
at WNDCLASSEX.cbWndExtra, dd 0;
at WNDCLASSEX.hInstance, dd 0;
at WNDCLASSEX.hIcon, dd 0;
at WNDCLASSEX.hCursor, dd 0;
at WNDCLASSEX.hbrBackground, dd COLOR_WINDOW;
at WNDCLASSEX.lpszMenuName, dd 0;
at WNDCLASSEX.lpszClassName, dd ClassName;
at WNDCLASSEX.hIconSm, dd 0;
iend
WindowMessage : istruc MSG
at MSG.hWnd, dd 0;
at MSG.Message, dd 0;
at MSG.wParam, dd 0;
at MSG.lParam, dd 0;
at MSG.Time, dd 0;
at MSG.pt, dd 0;
iend
;===Uninitialized data================================================================
section bss use32 class=data;
WindowHandle resd 1;
Error resd 1;
ErrorString resd 1;
ErrorType resd 1;
;===Code Segment======================================================================
section code use32 class=code;
..start :
;---Registering windows class---------------------------------------------------------
push DWORD 0;
call [ GetModuleHandleA ];
mov DWORD [ WindowClassEx+WNDCLASSEX.hInstance ], eax;
push DWORD WindowClassEx;
call [ RegisterClassExA ];
mov BYTE [ ErrorCaption + 6 ], '1';
test eax, eax;
jz NEAR ERROR;
;---Creating window-------------------------------------------------------------------
push DWORD 0;
call [ GetModuleHandleA ];
push LPCSTR 0;
push HINSTANCE eax;
push HMENU 0;
push HWND 0;
push INTEGER CW_USEDEFAULT;
push INTEGER CW_USEDEFAULT;
push INTEGER CW_USEDEFAULT;
push INTEGER CW_USEDEFAULT;
push DWORD WS_OVERLAPPEDWINDOW;
push LPCSTR ClassName;
push LPCSTR ClassName;
push DWORD 0;
call [ CreateWindowExA ];
mov BYTE [ ErrorCaption + 6 ], '2';
test eax, eax;
jz NEAR ERROR;
mov [ WindowHandle ], eax;
;---Showing window--------------------------------------------------------------------
push INTEGER SW_SHOW;
push HWND eax;
call [ ShowWindow ];
push HWND [ WindowHandle ];
call [ UpdateWindow ];
;---Message loop----------------------------------------------------------------------
MESSAGE_LOOP :
push UINT 0;
push UINT 0;
push HWND NULL;
push DWORD WindowMessage;
call [ GetMessageA ];
test eax, eax;
jz QUIT;
push DWORD WindowMessage;
call [ TranslateMessage ];
push DWORD WindowMessage;
call [ DispatchMessageA ];
jmp SHORT MESSAGE_LOOP;
QUIT :
push UINT NULL;
call [ ExitProcess ];
;---Error Handling--------------------------------------------------------------------
ERROR :
call [ GetLastError ];
mov [ Error ], eax;
push 0;
push 0;
push ErrorString;
push 0;
push DWORD [ Error ];
push 0;
push FORMAT_MESSAGE_ALLOCATE_BUFFER + FORMAT_MESSAGE_FROM_SYSTEM;
call [ FormatMessageA ];
push UINT MB_OK;
push LPCSTR ErrorCaption;
push LPCSTR [ ErrorString ];
push HWND NULL;
call [ MessageBoxA ];
push ErrorString;
call [ LocalFree ];
push UINT Error;
call [ ExitProcess ];
;---Main Procedure--------------------------------------------------------------------
WinMain :
%define ebp_hWnd ebp + 8;
%define ebp_Message ebp + 12;
%define ebp_wParam ebp + 16;
%define ebp_lParam ebp + 20;
cmp UINT [ ebp_Message ], WM_CREATE;
je CREATE;
cmp UINT [ ebp_Message ], WM_CLOSE;
je CLOSE;
push LPARAM [ ebp_lParam ];
push WPARAM [ ebp_wParam ];
push UINT [ ebp_Message ];
push HWND [ ebp_hWnd ];
call [ DefWindowProcA ];
;---Creating window---------------------------------------------------------------
CREATE :
jmp SHORT EXIT;
;---Closing window----------------------------------------------------------------
CLOSE :
EXIT:
leave
retn 0;
Program compiles, but after loading it writes "Wrong window descriptor" and mistake occures after calling [ CreateWindowExA ].