|
Ассемблер в примерах - Ошибки при компиляции FASM
- Вопрос:
- Найдите ошибку в примере и исправьте, прога компилируется, но не работает, просто висит в процессах.
компилятор FASM
format pe gui 4.0
entry start
include 'C:\fasm\INCLUDE\win32a.inc'
;--------------------------------------
section '.data' data readable writeable
ClassName db "SimpleWinClass",0
AppName db "Our First Window",0
char dd 20h
hInstance dd ?
hMainWindow dd ?
;hFount dd ?
msg MSG
wc WNDCLASS
;rect RECT
;--------------------------------------
section '.code'code readable executable
start:
invoke GetModuleHandle,0
mov [hInstance],eax
invoke LoadIcon, 0,IDI_APPLICATION
mov [wc.hIcon],eax
invoke LoadCursor, 0,IDC_ARROW
mov [wc.hCursor],eax
mov [wc.style],CS_HREDRAW or CS_VREDRAW
mov [wc.lpfnWndProc],WindowProc
mov [wc.cbClsExtra],0
mov [wc.cbWndExtra],0
mov eax,[hInstance]
mov [wc.hInstance],eax
mov [wc.hbrBackground],COLOR_WINDOW+1
mov [wc.lpszMenuName],0
mov [wc.lpszClassName],ClassName
invoke RegisterClassEx,wc
invoke CreateWindowEx,0,\
ClassName,\
AppName,\
WS_OVERLAPPEDWINDOW,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
0,\
0,\
[hInstance],0
mov [hMainWindow],eax
invoke ShowWindow, [hMainWindow],SW_SHOWNORMAL
;invoke UpdateWindow,[hMainWindow]
msg_loop:
invoke GetMessage,msg,0,0,0
or eax,eax
jz end_loop
invoke TranslateMessage,msg
invoke DispatchMessage,msg
jmp msg_loop
end_loop:
invoke ExitProcess,[msg.wParam]
proc WindowProc hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
push ebx esi edi
local ps:PAINTSTRUCT, hdc:DWORD ;локальные переменные
cmp [wmsg],WM_DESTROY
je wmdestroy
cmp [wmsg],WM_CHAR
je invalid
jmp paint
invalid:
push [msg.wParam]
pop [char]
invoke InvalidateRect,[hMainWindow],0,TRUE
paint:
cmp [wmsg],WM_PAINT
je beginP
jmp defwndproc
beginP:
lea eax,[ps]
invoke BeginPaint,[hwnd],eax
mov [hdc],eax
invoke TextOut,[hdc],0,0,char,1
invoke EndPaint,[hwnd],[ps]
jmp defwndproc
wmdestroy:
invoke PostQuitMessage,0
xor eax,eax
jmp finish
defwndproc:
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
finish:
pop edi esi ebx
ret
endp
;----------------------------------------------
section '.idata' import data readable writeable
library kernel,'KERNEL32.DLL',\
user,'USER32.DLL',\
gdi,'gdi32.dll'
;include 'c:\fasm\INCLUDE\api\kernel32.inc'
;include 'c:\fasm\INCLUDE\api\user32.inc'
;include 'c:\fasm\INCLUDE\api\gdi32.inc'
import kernel,\
GetModuleHandle,'GetModuleHandleA',\
ExitProcess,'ExitProcess'
import user,\
ShowWindow,'ShowWindow',\
InvalidateRect,'InvalidateRect',\
BeginPaint,'BeginPaint',\
EndPaint,'EndPaint',\
GetClientRect,'GetClientRect',\
RegisterClassEx,'RegisterClassExA',\
CreateWindowEx,'CreateWindowExA',\
DefWindowProc,'DefWindowProcA',\
GetMessage,'GetMessageA',\
TranslateMessage,'TranslateMessage',\
DispatchMessage,'DispatchMessageA',\
LoadCursor,'LoadCursorA',\
LoadIcon,'LoadIconA',\
PostQuitMessage,'PostQuitMessage'
import gdi,\
CreateFont,'CreateFontA',\
SetBkColor,'SetBkColor',\
TextOut,'TextOutA',\
SelectObject,'SelectObject',\
SetTextColor,'SetTextColor',\
DrawText,'DrawTextA'
- Ответ:
-
читаем msdn
RegisterClass структура WNDCLASS
typedef struct {
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
} WNDCLASS, *PWNDCLASS;
RegisterClassEx структура WNDCLASSEX
typedef struct {
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
HICON hIconSm;
} WNDCLASSEX, *PWNDCLASSEX;
| |