鱼C论坛

 找回密码
 立即注册
查看: 3257|回复: 6

Win32 汇编例程问题?

[复制链接]
发表于 2016-8-27 11:19:11 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
例程源码:编译成功,发现一个问题就是 在关闭的时候,主进程没有结束。用W32Dasm  反汇编检查了,好像没有问题。但实在想不出是哪个地方出了问题,好像是在call _WinMain之后没有返回调用 invoke ExitProcess,NULL导致,但_WinMain进程结束前都没有少ret 返回。

请鱼油们帮忙想下是哪里出了问题


  1. ;************first window**************
  2. ;copyright by yang 20160821
  3. ;======================================

  4.         .386
  5.         .model flat,stdcall
  6.         option casemap:none

  7. include                windows.inc
  8. include                 gdi32.inc
  9. includelib         gdi32.lib
  10. include                 user32.inc
  11. includelib        user32.lib
  12. include                kernel32.inc
  13. includelib        kernel32.lib


  14.         .data?
  15. hInstance                dd ?
  16. hWinMain                dd ?
  17.        
  18.         .const
  19. szClassName                db 'MyClass',0
  20. szCaptionMain        db 'MyWindow',0
  21. szText                        db 'This is my first Window!',0
  22.        
  23.        
  24.         .code
  25. ;**************************************************
  26. ;窗口过程消息处理
  27. ;**************************************************       
  28. _ProcWinMain        proc uses ebx edi esi,hWnd,uMsg,wParam,lParam
  29.                                 local        @stPs:PAINTSTRUCT   
  30.                                 local        @stRect:RECT
  31.                                 local        @hDc:HDC
  32.                                
  33.                                 mov         eax,uMsg
  34.                                
  35.                                 .if                eax == WM_PAINT
  36.                                                 invoke        BeginPaint,hWnd,addr @stPs
  37.                                                 mov                @hDc,eax
  38.                                                
  39.                                                 invoke        GetClientRect,hWnd,addr @stRect
  40.                                                 invoke        DrawText, @hDc , addr szText,-1,\
  41.                                                                 addr @stRect,\
  42.                                                                 DT_SINGLELINE or DT_CENTER or DT_VCENTER
  43.                                                 invoke        EndPaint,hWnd,addr @stPs
  44.                                 .elseif        eax ==WM_CLOSE
  45.                                                 invoke        DestroyWindow,hWinMain
  46.                                                 invoke        PostQuitMessage,NULL
  47.                                 .else
  48.                                                 invoke        DefWindowProc,hWnd,uMsg,wParam,lParam
  49.                                                 ret
  50.                                 .endif
  51.                                 xor         eax,eax
  52.                                 ret
  53. _ProcWinMain endp

  54. ;*************************************************
  55. ;_WinMain proc
  56. ;*************************************************
  57. _WinMain        proc
  58.                         local        @stWndClass:WNDCLASSEX
  59.                         local        @stMsg:MSG
  60.                        
  61.                         invoke        GetModuleHandle,NULL
  62.                         mov                hInstance,eax
  63.                        
  64.                         invoke        RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
  65. ;*************************************************
  66. ;注册窗口类
  67. ;*************************************************
  68.                         invoke        LoadCursor,0,IDC_ARROW
  69.                         mov                @stWndClass.hCursor,eax
  70.                         push        hInstance
  71.                         pop                @stWndClass.hInstance
  72.                         mov                @stWndClass.cbSize,sizeof WNDCLASSEX
  73.                         mov         @stWndClass.style,CS_HREDRAW or CS_VREDRAW
  74.                         mov         @stWndClass.hbrBackground,COLOR_WINDOW+1
  75.                         mov         @stWndClass.lpszClassName,offset szClassName
  76.                         mov         @stWndClass.lpfnWndProc,offset _ProcWinMain ;
  77.                         invoke        RegisterClassEx,addr @stWndClass
  78. ;****************************************************
  79. ;建立窗口,显示窗口
  80. ;****************************************************
  81.                         invoke        CreateWindowEx,WS_EX_CLIENTEDGE ,\
  82.                                         offset szClassName,offset szCaptionMain,\
  83.                                         WS_TILEDWINDOW,0,0,300,200,NULL,NULL,hInstance,NULL
  84.                         mov                hWinMain,eax
  85.                         invoke        ShowWindow,hWinMain,SW_SHOWNORMAL
  86.                         invoke        UpdateWindow,hWinMain
  87. ;*****************************************************
  88. ;消息循环
  89. ;*****************************************************
  90.                         .while TRUE
  91.                                         invoke         GetMessage,addr @stMsg,hWinMain,0,0
  92.                                         .break .if eax == WM_QUIT
  93.                                         invoke        TranslateMessage,addr @stMsg
  94.                                         invoke        DispatchMessage,addr @stMsg
  95.                         .endw
  96.                
  97.                         ret
  98. _WinMain        endp
  99.        
  100.        
  101.        
  102.        
  103.        
  104.        
  105.                
  106. start:
  107.                
  108.                 call _WinMain
  109.                 invoke ExitProcess,NULL

  110.        
  111.        
  112.        
  113.        
  114.        
  115.                 end start
复制代码

firstwindows.txt

2.96 KB, 下载次数: 0

win32asm

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2016-8-27 11:24:04 | 显示全部楼层
  1. _ProcWinMain        proc uses ebx edi esi,hWnd,uMsg,wParam,lParam
  2.                                 local        @stPs:PAINTSTRUCT   
  3.                                 local        @stRect:RECT
  4.                                 local        @hDc:HDC
  5.                                
  6.                                 mov         eax,uMsg
  7.                                
  8.                                 .if                eax == WM_PAINT
  9.                                                 invoke        BeginPaint,hWnd,addr @stPs
  10.                                                 mov                @hDc,eax
  11.                                                
  12.                                                 invoke        GetClientRect,hWnd,addr @stRect
  13.                                                 invoke        DrawText, @hDc , addr szText,-1,\
  14.                                                                 addr @stRect,\
  15.                                                                 DT_SINGLELINE or DT_CENTER or DT_VCENTER
  16.                                                 invoke        EndPaint,hWnd,addr @stPs
  17.                                 .elseif        eax ==WM_CLOSE
  18.                                                 invoke        PostQuitMessage,NULL
  19.                                                 invoke        DestroyWindow,hWinMain
  20.                                                 invoke         ExitProcess,NULL                      ;在这里加入,才可以完全退出程序
  21.                                 .else
  22.                                                 invoke        DefWindowProc,hWnd,uMsg,wParam,lParam
  23.                                                 ret
  24.                                 .endif
  25.                                 xor         eax,eax
  26.                                 ret
  27. _ProcWinMain endp
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-8-27 12:03:37 | 显示全部楼层
找到原因
GetMessage:

Return value
Type: Type: BOOL
If the function retrieves a message other than WM_QUIT, the return value is nonzero.
If the function retrieves the WM_QUIT message, the return value is zero.

;*****************************************************
;消息循环
;*****************************************************
                        .while TRUE
                                        invoke         GetMessage,addr @stMsg,hWinMain,0,0
                                        ;.break .if eax == WM_QUIT
                                        .break         .if          eax == 0
                                        invoke        TranslateMessage,addr @stMsg
                                        invoke        DispatchMessage,addr @stMsg
                        .endw
               
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-8-27 12:54:53 | 显示全部楼层
如果   加入判断 WM_CLOSE  和  WM_DESTROY   为什么消息循环不能退出??????
好像 PostQuitMessage 没有执行一样
_ProcWinMain        proc uses ebx edi esi,hWnd,uMsg,wParam,lParam
                                local        @stPs:PAINTSTRUCT   
                                local        @stRect:RECT
                                local        @hDc:HDC
                               
                                mov         eax,uMsg
                               
                                .if                eax == WM_PAINT
                                                invoke        BeginPaint,hWnd,addr @stPs
                                                mov                @hDc,eax
                                               
                                                invoke        GetClientRect,hWnd,addr @stRect
                                                invoke        DrawText, @hDc , addr szText,-1,\
                                                                addr @stRect,\
                                                                DT_SINGLELINE or DT_CENTER or DT_VCENTER
                                                invoke        EndPaint,hWnd,addr @stPs
                                .elseif        eax == WM_CLOSE
                                                invoke         MessageBox,hWinMain,offset szQuitText,offset \
                                                                szCaptionMain,MB_OKCANCEL
                                                .if                eax == IDOK
                                                                invoke        DestroyWindow,hWinMain
                                                                ret
                                                .endif
                                .elseif        eax == WM_DESTROY
                                                invoke        PostQuitMessage,NULL
                                                ret
                                .else
                                                invoke        DefWindowProc,hWnd,uMsg,wParam,lParam
                                                ret
                                .endif
                                xor         eax,eax
                                ret
_ProcWinMain endp
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-8-27 13:22:17 | 显示全部楼层

改了,,还是一样没有退出循环,
这是怎么回事????
请帮忙!!!!!!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-8-27 13:51:50 | 显示全部楼层
;*****************************************************
;消息循环
;*****************************************************
                        .while TRUE
                                         ; invoke         GetMessage,addr @stMsg,hWinMain,0,0
                                        ;.break .if eax == WM_QUIT
                                        invoke         GetMessage,addr @stMsg,NULL,0,0
                                        .break         .if          eax == 0
                                        invoke        TranslateMessage,addr @stMsg
                                        invoke        DispatchMessage,addr @stMsg
                        .endw

把  NULL 改成 程 序 句柄  hInstance  程序运行报错!窗口句柄可以用但在DestroyWindow 之后,GetMessage 无法改得 窗口的消息,所以消息循环就不能退出!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-12 12:45

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表