Author Topic: [SOLVED]DialogBoxParam pops the dialog but i cannot close it  (Read 389 times)

Mikl__

  • Member
  • *****
  • Posts: 1263
Re: [SOLVED]DialogBoxParam pops the dialog but i cannot close it
« Reply #15 on: August 29, 2022, 09:38:57 PM »
Merhaba blue_devil!
böyle yapmayı dene
Code: [Select]
WinMainCRTStartup proc
    enter 30h,0; <---
    invoke InitCommonControls
    invoke GetModuleHandle,NULL
    invoke DialogBoxParam, eax, IDD_DIALOG, 0, addr DlgProc, NULL

    invoke ExitProcess,NULL

WinMainCRTStartup endp

TimoVJL

  • Member
  • *****
  • Posts: 1109
Re: [SOLVED]DialogBoxParam pops the dialog but i cannot close it
« Reply #16 on: August 29, 2022, 10:50:49 PM »
    invoke DialogBoxParam, eax, IDD_DIALOG, 0, addr DlgProc, NULL
only for /LARGEADDRESSAWARE:NO in x64 and not using /BASE:0x400000
But in in Windows 7 x64 this is possible and Desktop is owner of dialog
Code: [Select]
ExitProcess(DialogBoxParam(0, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)MainDlgProc, 0));
May the source be with you

Mikl__

  • Member
  • *****
  • Posts: 1263
Re: [SOLVED]DialogBoxParam pops the dialog but i cannot close it
« Reply #17 on: August 29, 2022, 11:27:53 PM »
Thanks Timo!
I forgot that rax is possibly equal 0x140000000

bluedevil

  • Member
  • **
  • Posts: 160
  • Binary Grinder
    • SCTZine
Re: [SOLVED]DialogBoxParam pops the dialog but i cannot close it
« Reply #18 on: August 29, 2022, 11:30:50 PM »
STACKFRAME macro is interesting. If i use STACKFRAME macro at the very beginning like in the examples of Mikl__ code compiles but does not run.

Final workaround -maybe- I put STACKFRAME macro just before DlgProc and everything is fine.
Code: [Select]
    OPTION DOTNAME                          ; required for macro files
    option casemap:none                     ; case sensitive

; _____________________________________________________________________________
; MASM64 macros
    include \masm64\macros64\vasily.inc     ; main macro file
    include \masm64\macros64\macros64.inc   ; auxillary macro file

; _____________________________________________________________________________
; include files
    include \masm64\include64\win64.inc     ; main include file
    include \masm64\include64\kernel32.inc
    include \masm64\include64\user32.inc
    include \masm64\include64\comctl32.inc
    ;STACKFRAME                              ; create a default stack frame
; _____________________________________________________________________________
; libraries
    includelib \masm64\lib64\user32.lib
    includelib \masm64\lib64\kernel32.lib
    includelib \masm64\lib64\comctl32.lib


   
; _____________________________________________________________________________
; constant variables
.const
    ; Main Dialog
    IDD_DIALOG EQU 1000
; _____________________________________________________________________________
; initialized variables
.data


.code

WinMainCRTStartup proc hInstance:HINSTANCE, hPrevInstance:HINSTANCE, lpCmdLine:LPSTR, nCmdShow:DWORD

    invoke InitCommonControls
    invoke DialogBoxParam,hInstance, IDD_DIALOG, 0, addr DlgProc, NULL

    invoke ExitProcess,NULL

WinMainCRTStartup endp

STACKFRAME
DlgProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

    ;LOCAL hWnd:HWND
    ;LOCAL uMsg:UINT
    ;LOCAL wParam:WPARAM
    ;LOCAL lParam:LPARAM
   
    ;mov     hWnd,rcx
;mov uMsg,edx
;mov     wParam,r8
;mov     lParam,r9

.if uMsg==WM_INITDIALOG
        ; code that runs before dialog shows up
.elseif uMsg==WM_COMMAND
        ; code of controls, buttons, checkboxes...
.elseif uMsg==WM_CLOSE
invoke EndDialog,hWnd,0
ret
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret

DlgProc endp

end

Why it doesn't work if i write STACKFRAME at the beginning(look above code, i have commented it out)

Now look Mikl__'s tute03 code. The STACKFRAME macro is above and everything works fine:
Code: [Select]
    OPTION DOTNAME                          ; required for macro files
    option casemap:none                     ; case sensitive

    include \masm64\include64\win64.inc     ; main include file
    include \masm64\macros64\vasily.inc     ; main macro file
    include \masm64\macros64\macros64.inc   ; auxillary macro file

    STACKFRAME                              ; create a default stack frame

    ;include \masm64\m64lib\m64lib.inc       ; include file for m64lib library

    ; ------------------------
    ; system API include64 files
    ; ------------------------
    include \masm64\include64\kernel32.inc
    include \masm64\include64\user32.inc

    ;includelib \masm64\m64lib\m64lib.lib    ; m64lib library

    ; ------------------------
    ; system API library files
    ; ------------------------
    includelib \masm64\lib64\kernel32.lib
    includelib \masm64\lib64\user32.lib

.data
    ClassName   db "SimpleWin64Class", 0      ; the name of our window class
    AppName     db "Our First Window", 0    ; the name of our window

.data?
    hIcon       dq ?
    hCursor     dq ?

;OPTION PROLOGUE:rbpFramePrologue
;OPTION EPILOGUE:rbpFrameEpilogue
.code

WinMainCRTStartup proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
   
    LOCAL wc:WNDCLASSEX
    LOCAL msg:MSG
    LOCAL hwnd:HWND
   
    invoke  LoadIcon,hInst,IDI_APPLICATION
    mov     hIcon, rax
    invoke  LoadCursor,hInst,IDC_ARROW
    mov     hCursor, rax
   
    mov     wc.cbSize, sizeof WNDCLASSEX
    mov     wc.style, CS_HREDRAW or CS_VREDRAW
    lea     rdi, WndProc
    mov     wc.lpfnWndProc, rdi;offset WndProc
    mov     wc.cbClsExtra, 0
    mov     wc.cbWndExtra, 0
    mov     wc.hInstance, 0;hInst
    mov     rax, hIcon
    mov     wc.hIcon, rax;hIcon
    mov     rbx, hCursor
    mov     wc.hCursor, rbx;hCursor
    mov     wc.hbrBackground, COLOR_WINDOW + 1
    mov     wc.lpszMenuName, 0
    lea     rdi, ClassName
    mov     wc.lpszClassName, rdi;offset ClassName
    mov     wc.hIconSm, rax;hIcon
    invoke  RegisterClassEx, addr wc
   
    invoke  CreateWindowEx,NULL,addr ClassName,addr AppName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,0,NULL
    mov     hwnd, rax
   
    invoke  ShowWindow,hwnd, SW_SHOWNORMAL
    invoke  UpdateWindow,hwnd
   
    .while TRUE
        invoke GetMessage,addr msg, NULL,0,0
        .if (rax == 0)
            .break
        .endif
        invoke TranslateMessage,addr msg
        invoke  DispatchMessage,addr msg
    .endw
   
    mov     rax, msg.wParam
    ret

WinMainCRTStartup endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
   
    .if uMsg==WM_CLOSE
        invoke MessageBox,hWnd,addr ClassName, addr AppName,MB_OK
        invoke ExitProcess,NULL
    .elseif uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.endif
xor eax,eax
    ret

WndProc endp

end
..Dreams make the future
But the past never lies..
BlueDeviL // SCT
My Code Site:
BlueDeviL Github

Mikl__

  • Member
  • *****
  • Posts: 1263
Re: [SOLVED]DialogBoxParam pops the dialog but i cannot close it
« Reply #19 on: August 29, 2022, 11:43:38 PM »
Merhaba bluedevil !
This works for me
Code: [Select]
.code
WinMainCRTStartup proc
enter 30h,0
invoke InitCommonControls
invoke GetModuleHandle,NULL
invoke DialogBoxParam,rax, IDD_DIALOG,0,addr DlgProc,NULL

invoke ExitProcess,NULL
WinMainCRTStartup endp

DlgProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
mov     hWnd,rcx
mov     uMsg,edx
mov     wParam,r8
mov     lParam,r9

.if uMsg==WM_INITDIALOG
        ; code that runs before dialog shows up
.elseif uMsg==WM_COMMAND
        ; code of controls, buttons, checkboxes...
.elseif uMsg==WM_CLOSE
invoke EndDialog,hWnd,0               
.else
xor eax,eax
                leave
retn
.endif
mov eax,TRUE
        leave
retn
DlgProc endp
« Last Edit: August 30, 2022, 10:12:30 AM by Mikl__ »

TimoVJL

  • Member
  • *****
  • Posts: 1109
Re: [SOLVED]DialogBoxParam pops the dialog but i cannot close it
« Reply #20 on: August 30, 2022, 02:34:08 AM »
This works for me
Code: [Select]
WinMainCRTStartup proc
LOCAL shadow[4] : QWORD ; create shadow space
    invoke InitCommonControls
    invoke GetModuleHandle,NULL
    invoke DialogBoxParam,rax,IDD_DIALOG,0,addr DlgProc,NULL
    invoke ExitProcess,NULL
WinMainCRTStartup endp
align 8
DlgProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL shadow[4] : QWORD ; create shadow space
mov     hWnd,rcx
mov     uMsg,edx
mov     wParam,r8
mov     lParam,r9

.if uMsg==WM_INITDIALOG
        ; code that runs before dialog shows up
.elseif uMsg==WM_COMMAND
        ; code of controls, buttons, checkboxes...
.elseif uMsg==WM_CLOSE
; invoke EndDialog,hWnd,0
; invoke EndDialog,rcx,0
invoke EndDialog,,0
.else
xor eax,eax
ret
.endif
mov eax,TRUE
ret
DlgProc endp
poasm users might remember this.
May the source be with you