I have subclassed an edit box. After I use GetWindowText function and move mouse over the subclassed edit box, I got an error "The memory could not be read!". Where a problem is?
format PE GUI 4.0
entry start
include 'win32ax.inc'
section '.data' data readable writeable
wnd_class db 'pro_wnd',0
wc WNDCLASS 0,WndProc,0,0,0,0,0,COLOR_BTNFACE+1,0,wnd_class
msg MSG
text db ?
DefEditProc dd ?
hButton dd ?
hEdit dd ?
section '.code' code readable executable
start:
invoke GetModuleHandle,0
mov [wc.hInstance],eax
invoke LoadIcon,0,IDI_APPLICATION
mov [wc.hIcon],eax
invoke LoadCursor,0,IDC_ARROW
mov [wc.hCursor],eax
invoke RegisterClass,wc
invoke CreateWindowEx,0,wnd_class,"Window",WS_VISIBLE + WS_DLGFRAME + WS_SYSMENU,100,100,300,200,0,0,[wc.hInstance],0
message_loop:
invoke GetMessage,msg,NULL,0,0
or eax,eax
jz exit
invoke TranslateMessage,msg
invoke DispatchMessage,msg
jmp message_loop
exit:
invoke ExitProcess,[msg.wParam]
proc WndProc hwnd,wmsg,wparam,lparam
cmp [wmsg],WM_CREATE
je wm_create
cmp [wmsg],WM_COMMAND
je wm_command
cmp [wmsg],WM_DESTROY
je wm_destroy
jmp def_wndproc
wm_command:
cmp [wparam],BN_CLICKED shl 16 + 1
je button_click
ret
button_click:
invoke GetWindowTextLength,[hEdit]
inc eax
invoke GetWindowText,[hEdit],text,eax
invoke MessageBox,[hwnd],text,"",MB_OK
jmp def_wndproc
wm_create:
invoke CreateWindowEx,0,"BUTTON","Button",WS_CHILD + WS_VISIBLE,110,90,70,23,[hwnd],1,0,0
mov [hButton],eax
invoke CreateWindowEx,0,"EDIT","text",WS_CHILD + WS_VISIBLE + WS_BORDER + ES_AUTOHSCROLL,110,60,70,22,[hwnd],0,0,0
mov [hEdit],eax
invoke SetWindowLong,[hEdit],GWL_WNDPROC,EditProc
mov [DefEditProc],eax
jmp def_wndproc
wm_destroy:
invoke PostQuitMessage,0
ret
def_wndproc:
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
ret
endp
proc EditProc hwnd,wmsg,wparam,lparam
cmp [wmsg],WM_CHAR
je wm_char
jmp def_editproc
wm_char:
cmp [wparam],VK_BACK
jne def_editproc
ret
def_editproc:
invoke CallWindowProc,[DefEditProc],[hwnd],[wmsg],[wparam],[lparam]
ret
endp
section '.idata' import data readable writable
library kernel,'kernel32.dll', \
user,'user32.dll'
import kernel, GetModuleHandle, 'GetModuleHandleA', \
ExitProcess, 'ExitProcess'
import user, MessageBox,'MessageBoxA', \
SetWindowText,'SetWindowTextA', \
GetWindowText,'GetWindowTextA', \
GetWindowTextLength,'GetWindowTextLengthA', \
SetWindowLong,'SetWindowLongA', \
CallWindowProc,'CallWindowProcA', \
DefWindowProc,'DefWindowProcA', \
LoadIcon,'LoadIconA', \
LoadCursor,'LoadCursorA', \
RegisterClass,'RegisterClassA', \
GetMessage,'GetMessageA', \
TranslateMessage,'TranslateMessage', \
DispatchMessage,'DispatchMessageA', \
CreateWindowEx,'CreateWindowExA', \
PostQuitMessage,'PostQuitMessage'