Garthower
Joined: 21 Apr 2006
Posts: 158
Location: Ukraine
|
I had a problem with use of dialogue windows from resources in PE64. The window is not created, GetLastError returns an error 58Ch - "The window is not a valid dialog window". Here a code of the program and resource file.
Assembler code:
format PE64 GUI
entry start
include 'C:\fasm\INCLUDE\MACRO\STRUCT.INC'
IDC_ARROW = 32512
CS_VREDRAW = 00001h
CS_HREDRAW = 00002h
COLOR_WINDOW = 5
WM_DESTROY = 0002h
struct POINT
x dd ?
y dd ?
ends
struct MSG
hWnd dq ?
umsg dq ?
wparam dq ?
lparm dq ?
time dq ?
pt POINT
ends
struct WNDCLASSEX
cbSize dd ?
style dd ?
lpfnWndProc dq ?
cbClsExtra dd ?
cbWndExtra dd ?
hInstance dq ?
hIcon dq ?
hCursor dq ?
hbrBackground dq ?
lpszMenuName dq ?
lpszClassName dq ?
hIconSm dq ?
ends
;-- ----------------------------------------------------------------------------
section '.code' code readable executable
start:
lea rdi,[wc.hInstance]
xor rcx,rcx
call [GetModuleHandleA]
stosq
mov rcx,rax
xor rdx,rdx
call [LoadIconA]
stosq
xor rcx,rcx
mov rdx,IDC_ARROW
call [LoadCursorA]
stosq
mov rcx,wc
call [RegisterClassExA]
sub rsp,30h
mov rcx,[wc.hInstance]
mov rdx,DlgName
xor r8,r8
mov r9,WndProc
mov qword [rsp+20h],0
call [CreateDialogParamA]
add rsp,30h
or rax,rax
jz .Exit_Prog
lea rsi,[Message]
.Next_Msg:
xor r9,r9
xor r8,r8
xor rdx,rdx
mov rcx,rsi
call [GetMessageW]
or rax,rax
jz .Exit_Prog
mov rcx,rsi
call [TranslateMessage]
mov rcx,rsi
call [DispatchMessageW]
jmp .Next_Msg
.Exit_Prog:
call [GetLastError]
mov ecx,eax
call [ExitProcess]
;..............................................................................
WndProc:
;hwnd equ rcx
;wmsg equ rdx
;wparam equ r8
;lparam equ r9
sub rsp,5*8
cmp rdx,WM_DESTROY
jz Destroy
;..............................................................................
Exit_Proc_Def:
call [DefWindowProcW]
Exit_Proc:
add rsp,5*8
ret
;##############################################################################
Destroy:
xor rcx,rcx
call [PostQuitMessage]
xor rax,rax
jmp Exit_Proc
;------------------------------------------------------------------------------
section '.data' data readable writeable
ClassName db 'Test_Class',0
DlgName db 'TestDlg',0
wc_start:
wc WNDCLASSEX wc_end-wc_start,CS_HREDRAW or CS_VREDRAW,WndProc,0,0,0,0,0,COLOR_WINDOW,0,ClassName,0
wc_end:
;------------------------------------------------------------------------------
section '.bss' data writeable
Message MSG
;------------------------------------------------------------------------------
section '.idata' import data readable writeable
dd 0,0,0,RVA kernel_name,RVA kernel_table
dd 0,0,0,RVA user_name,RVA user_table
dd 0,0,0,0,0
kernel_table:
ExitProcess dq RVA _ExitProcess
GetModuleHandleA dq RVA _GetModuleHandleA
GetLastError dq RVA _GetLastError
dq 0
user_table:
MessageBoxA dq RVA _MessageBoxA
CreateDialogParamA dq RVA _CreateDialogParamA
LoadIconA dq RVA _LoadIconA
LoadCursorA dq RVA _LoadCursorA
RegisterClassExA dq RVA _RegisterClassExA
DefWindowProcW dq RVA _DefWindowProcW
PostQuitMessage dq RVA _PostQuitMessage
GetMessageW dq RVA _GetMessageW
TranslateMessage dq RVA _TranslateMessage
DispatchMessageW dq RVA _DispatchMessageW
dq 0
kernel_name db 'KERNEL32.DLL',0
user_name db 'USER32.DLL',0
_ExitProcess dw 0
db 'ExitProcess',0
_GetModuleHandleA dw 0
db 'GetModuleHandleA',0
_MessageBoxA dw 0
db 'MessageBoxA',0
_CreateDialogParamA dw 0
db 'CreateDialogParamA',0
_LoadIconA dw 0
db 'LoadIconA',0
_LoadCursorA dw 0
db 'LoadCursorA',0
_RegisterClassExA dw 0
db 'RegisterClassExA',0
_DefWindowProcW dw 0
db 'DefWindowProcW',0
_PostQuitMessage dw 0
db 'PostQuitMessage',0
_GetMessageW dw 0
db 'GetMessageW',0
_TranslateMessage dw 0
db 'TranslateMessage',0
_DispatchMessageW dw 0
db 'DispatchMessageW',0
_GetLastError dw 0
db 'GetLastError',0
;------------------------------------------------------------------------------
section '.rsrc' resource from 'test.res' readable writeable
Resource file:
TestDlg DIALOGEX 0,0,226,135
FONT 8,"MS Serif",0,0
CLASS "Test_Class"
STYLE DS_MODALFRAME | DS_3DLOOK | DS_CONTEXTHELP | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX
BEGIN
END
For compilation of a code I used FASM 1.67.7, for compilation of a resource file I tried two variants - GoRC 0.90 and BRCC32 5.0, result the same. In what a mistake? Can be FASM link program with a mistake? The most surprising that messages are processed by procedure of a window, and at processing does not arise any errors. But after processing message WM_MOVE the further messages don't reach procedure and there is an exit from procedure CreateDialogParamA.
Last edited by Garthower on 29 Aug 2006, 15:37; edited 1 time in total
|