【问题标题】:x86 assembly masm32 window application stops respondingx86 程序集 masm32 窗口应用程序停止响应
【发布时间】:2012-08-31 07:06:29
【问题描述】:

我已经设法创建了一个窗口(感谢 SO!这里的每个人!),但每当它运行时,窗口就会形成,但它会立即中断并弹出一个窗口,上面写着“test.exe 已停止响应”(test.exe 已停止响应)。 exe 是程序的名称)。

代码如下:

.386 
.model flat,stdcall 
option casemap:none
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD

include \masm32\include\windows.inc 
include \masm32\include\user32.inc 
include \masm32\include\kernel32.inc 
include \masm32\include\gdi32.inc 
includelib \masm32\lib\user32.lib 
includelib \masm32\lib\kernel32.lib 
includelib \masm32\lib\gdi32.lib

 .data 
 ClassName db "SimpleWinClass",0 
 AppName  db "If you get this, it worked.",0 
 char WPARAM 20h                       

.data? 
hInstance HINSTANCE ? 
CommandLine LPSTR ?

.code 
start: 
push NULL
call GetModuleHandle 
mov    hInstance,eax 
call GetCommandLine
mov CommandLine,eax
push SW_SHOWDEFAULT
push CommandLine
push NULL
push hInstance
call WinMain
push eax
call ExitProcess

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD 
LOCAL wc:WNDCLASSEX 
LOCAL msg:MSG 
LOCAL hwnd:HWND 
mov   wc.cbSize,SIZEOF WNDCLASSEX 
mov   wc.style, CS_HREDRAW or CS_VREDRAW 
mov   wc.lpfnWndProc, OFFSET WndProc 
mov   wc.cbClsExtra,NULL 
mov   wc.cbWndExtra,NULL 
push  hInst 
pop   wc.hInstance 
mov   wc.hbrBackground,COLOR_WINDOW+1 
mov   wc.lpszMenuName,NULL 
mov   wc.lpszClassName,OFFSET ClassName 
push IDI_APPLICATION
push NULL
call LoadIcon
mov   wc.hIcon,eax 
mov   wc.hIconSm,eax 
push IDC_ARROW
push NULL
call LoadCursor
mov   wc.hCursor,eax 
lea eax, wc
push eax
call RegisterClassEx
push NULL
push hInst
push NULL
push NULL
push CW_USEDEFAULT
push CW_USEDEFAULT
push CW_USEDEFAULT
push CW_USEDEFAULT
push WS_OVERLAPPEDWINDOW
lea eax, AppName
push eax
lea eax, ClassName
push eax
push NULL
call CreateWindowEx
    mov   hwnd,eax 
push SW_SHOWNORMAL
push hwnd
call ShowWindow  
  push hwnd
  call UpdateWindow
     .WHILE TRUE 
         push 0
         push 0
         push NULL
         lea eax, msg
         push eax
         call GetMessage
         .BREAK .IF (!eax)
        lea eax, msg
        push eax
        call TranslateMessage
        lea eax, msg
        call DispatchMessage
     .ENDW 
     mov     eax,msg.wParam 
     ret 
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM 
    LOCAL hdc:HDC 
    LOCAL ps:PAINTSTRUCT

    .IF uMsg==WM_DESTROY 
    push NULL
    call PostQuitMessage
    .ELSEIF uMsg==WM_CHAR 
        push wParam 
        pop  char 
    push TRUE
    push NULL
    push hWnd
    call InvalidateRect
     .ELSEIF uMsg==WM_PAINT 
    lea eax, ps
    push eax
    push hWnd
    call BeginPaint
        mov    hdc,eax 
    push 1
    lea eax, char
    push eax
    push 0
    push 0
    push hdc
    call TextOut
    lea eax, ps
    push eax
    push hWnd
    call EndPaint
    .ELSE 
    push lParam
    push wParam
    push uMsg
    push hWnd
    call DefWindowProc
        ret 
    .ENDIF 
        xor    eax,eax 
        ret 
    push 0
    call ExitProcess
WndProc endp 
end start  

为什么它总是坏掉?我已经看到当我不输入 call ExitProcess 时也会发生同样的事情,但我有这个时间,为什么它会一直关闭?

提前致谢

【问题讨论】:

    标签: assembly x86 masm32


    【解决方案1】:

    由于您是初学者并使用 MASM,我强烈建议您不要使用推送/呼叫!!!!除了错误,不使用 INVOKE 将一无所获。

    如果你使用过调用,ml 就会发现问题。

    你是不是错过了什么?

    lea eax, msg
    call DispatchMessage
    

    你忘了push eax

    另外,为了您和其他必须阅读您的代码的人,请使用缩进样式。左边距和助记符之间通常有 4 个空格。

    【讨论】:

    • 抱歉缩进和格式化。以后我会注意的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-27
    • 1970-01-01
    • 2013-01-05
    • 2011-06-01
    • 1970-01-01
    相关资源
    最近更新 更多