以下是我用罗云彬汇编例程和另外一个例程综合出来的,但是CreateWindowEx始终返回0,几天了,崩溃。。。
.386
.model flat,stdcall
option casemap:none
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;include定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include user32.inc
include kernel32.inc
include gdi32.inc
includelib user32.lib
includelib kernel32.lib
includelib gdi32.lib
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;数据段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data
szTitle db '窗口标题',0
szMsg db '窗口消息',0
szError db '窗口创建失败',0
szClassName db "wndclass",0
.data?
hInstance dd ?
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
_WindowProc proc _hwnd:DWORD,_uMsg:DWORD,_wParam:DWORD,_lParam:DWORD
LOCAL @stPaint:PAINTSTRUCT
LOCAL @hdc
LOCAL @stRect:RECT
mov eax,_uMsg
.if eax == WM_PAINT
invoke BeginPaint,_hwnd,addr @stPaint
mov @hdc,eax
invoke GetClientRect,_hwnd,addr @stRect
invoke DrawText,@hdc,offset szMsg,lengthof szMsg,addr @stRect,DT_CENTER
invoke EndPaint,_hwnd,addr @stPaint
invoke MessageBox,NULL,offset szTitle,offset szTitle,MB_OK
.elseif eax == WM_CLOSE
invoke DestroyWindow,_hwnd
invoke PostQuitMessage,NULL
.else
invoke DefWindowProc,_hwnd,_uMsg,_wParam,_lParam
.endif
xor eax,eax
ret
_WindowProc endp
_WinMain proc hInst:DWORD,hPrevInst:DWORD,CmdLine:DWORD,CmdShow:DWORD
LOCAL @wndclass:WNDCLASSEX
LOCAL @msg:MSG
LOCAL @hwnd:HWND
;初始化窗口类
mov @wndclass.cbSize,sizeof WNDCLASSEX
mov @wndclass.style,CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
mov @wndclass.lpfnWndProc,offset _WindowProc
mov @wndclass.cbClsExtra,NULL
mov @wndclass.cbWndExtra,NULL
push hInst
pop @wndclass.hInstance
mov @wndclass.hbrBackground,COLOR_BTNFACE+1
mov @wndclass.lpszMenuName,NULL
mov @wndclass.lpszClassName,offset szClassName
invoke LoadIcon,hInst,100
mov @wndclass.hIcon,eax
invoke LoadCursor ,0,IDC_ARROW
mov @wndclass.hCursor,eax
mov @wndclass.hIconSm,0
;注册窗口类
invoke RegisterClassEx,addr @wndclass
;创建并显示窗口
invoke CreateWindowEx,NULL,addr szClassName,addr szTitle,WS_OVERLAPPEDWINDOW,200,200,600,300,NULL,NULL,hInst,NULL
.if !eax ;如果句柄为0则表示窗口创建失败
invoke MessageBox,NULL,offset szError,offset szTitle,MB_OK
ret
.endif
mov @hwnd,eax
invoke ShowWindow,@hwnd,SW_SHOWNORMAL
;更新窗口消息循环
invoke UpdateWindow,@hwnd
.while TRUE
invoke GetMessage,addr @msg,NULL,0,0
.break .if eax == 0
invoke TranslateMessage,addr @msg
invoke DispatchMessage,addr @msg
.endw
mov eax,@msg.wParam
ret
_WinMain endp
main:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke _WinMain,hInstance,NULL,NULL,SW_SHOWDEFAULT
invoke ExitProcess,0
end main
本人太菜
,高手莫笑,解答便是。
谢谢了。
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)