注册 登录
编程论坛 汇编论坛

win32位汇编程序出错,望调试

神龙赖了 发布于 2013-03-31 01:01, 938 次点击
程序代码:
                    .386
                    .model flat,stdcall
                    option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;
  Include 文件定义
;
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include    windows.inc
include    gdi32.inc
includelib gdi32.lib
include    user32.inc
includelib user32.lib
include    kernel32.inc
includelib kernel32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;
  数据段
;
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                           .data?
hInstance                  dd        ?
hWinMain                   dd        ?

                           .const
szClassName                db        "MyClass",0
szCaption                  db        "My first Window !",0
szText                     db        "Win32 Assembly, Simpel and powerful !",0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;
  代码段
;
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                           .code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;
  窗口过程
;
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcWinMain                proc      hWnd,uMsg,wParam,lParam
                            local     @stPs:PAINTSTRUCT
                            local     @stRect:RECT
                            local     @hDc
                           
                            mov       eax,uMsg
;***********************************************************************************************
                           .if        eax == WM_PAINT
                                      invoke    BeginPaint,hWnd,addr @stPs
                                      mov       @hDc,eax
                                      invoke    GetClientRect,@hDc,addr @stRect
                                      invoke    DrawText,@hDc,offset szText,-1,addr @stRect,\
                                      DT_SINGLELINE or DT_CENTER or DT_VCENTER
                           
                                      invoke    EndPaint,hWnd,addr @stPs
;***********************************************************************************************
                           
                           .elseif    eax == WM_CLOSE
                                      invoke    DestroyWindow,hWnd
                                      invoke    PostQuitMessage,NULL
;************************************************************************************************

                           .else
                                      invoke     DefWindowProc,hWnd,uMsg,wParam,lParam
                                      ret
                           .endif
;*************************************************************************************************
                             xor      eax,eax
                             ret
                           
_ProcWinMain   endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_WinMain                    proc
                            local     @stWndClass:WNDCLASSEX
                            local     @stMsg:MSG
                           
                            invoke    GetModuleHandle,NULL
                            mov       hInstance,eax
                            invoke    RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
;*************************************************************************************************
;
  注册窗口类
;
*************************************************************************************************
                            invoke    LoadCursor,0,IDC_ARROW
                            mov       @stWndClass.hCursor,eax
                            push      hInstance
                            pop       @stWndClass.hInstance
                            mov       @stWndClass.cbSize,sizeof WNDCLASSEX
                            mov       @stWndClass.style,CS_HREDRAW or CS_VREDRAW
                            mov       @stWndClass.lpfnWndProc, offset _ProcWinMain
                            mov       @stWndClass.hbrBackground,COLOR_WINDOW + 1
                            mov       @stWndClass.lpszClassName, offset szClassName
                            invoke    RegisterClassEx,addr @stWndClass
;*************************************************************************************************
;
  建立并显示窗口
;
*************************************************************************************************
                            invoke    CreateWindowEx, WS_EX_CLIENTEDGE, offset szClassName,\
                                                      offset szCaption,WS_OVERLAPPEDWINDOW,100,100,600,400,\
                                                      NULL,NULL,hInstance,NULL
                            mov       hWinMain,eax
                            invoke    ShowWindow,hWinMain,SW_SHOWNORMAL
                            invoke    UpdateWindow,hWinMain
;*************************************************************************************************
;
  消息循环
;
*************************************************************************************************
                            .while    TRUE
                                      invoke GetMessage,addr @stMsg,NULL,0,0
                                      .break .if eax == 0
                                      invoke TranslateMessage,addr @stMsg
                                      invoke DispatchMessage,addr @stMsg
                            .endw
                            ret
                           
_WinMain                              endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


start:
                             call     _WinMain
                             invoke   ExitProcess,NULL
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

                             end start
运行后窗口过程中的WM_PAINT没有得到输出,求调试,此贴绝非水贴,除去打酱油的十到二十分外其余分一律给解题人(话说偶真的熬不住了,还要生地会考压力大,这种错误可能查找的时间不多,所以SOS啊...)
7 回复
#2
zklhp2013-03-31 09:19
建议您以学业为重 搬砖太忙没时间看 等大牛罢
#3
神龙赖了2013-03-31 11:09
求大牛......
#4
Agdmeg2013-03-31 12:29
GetClientRect参数不对。
 
.if        eax == WM_PAINT
    invoke    BeginPaint,hWnd,addr @stPs
    mov       @hDc,eax
    invoke    GetClientRect,hWnd,addr @stRect
    invoke    DrawText,@hDc,offset szText,-1,addr @stRect,\
        DT_SINGLELINE or DT_CENTER or DT_VCENTER
    invoke    EndPaint,hWnd,addr @stPs

[ 本帖最后由 Agdmeg 于 2013-3-31 12:31 编辑 ]
#5
信箱有效2013-03-31 12:52
送快件太忙
#6
神龙赖了2013-03-31 13:25
回复 4楼 Agdmeg
找到错误了,thanks感谢,结贴料....
agdmeg你对32位汇编有点了解吗?我看的罗云兵的书但是有些地方不太详细啊
是不是得先看看其他书籍?
#7
信箱有效2013-03-31 16:28
该上学就认真上学哇 以后考个好学校是正事。
参数错证明是你自己打的 不是复制的
BeginPaint获取HDC GetClientRect获取RECT 都需要HWND当参数
你把HDC传给GetClientRect,虽然在编译连接运行都没问题,但实际
上会有ERROR_INVALID_WINDOW_HANDLE错误。
正常的RECT形如{0.,0.,588.,369.}
你这得到的是类似{0.,8192106.,3997696.,3997696.}这样错误的,
DrawText在这样的RECT上画,当然看不到了。
这么简单短小的东东 都不愿意耐心的和书本或者源码对比找错,又何必费劲手打代码
不过能手打这么一段,也不容易了。
#8
Agdmeg2013-03-31 18:55
C语言对你学其他很多语言都有帮助,然后就可以了解16位汇编,也不用太深入,主要是了解电脑内部工作原理,这些学好了再学WIn32汇编会比较容易
1