flat assembler
Message board for the users of flat assembler.

Index > Windows > GetDlgItem returns null

Author
Thread Post new topic Reply to topic
extra_12345



Joined: 21 Apr 2020
Posts: 28
extra_12345
hey
i'm trying to retrieve hwnd of a text box in a dialog box but it returns zero and last error returns 1421 (0x58D) Control ID not found but i'm passing the correct id don't know why.

here's the code:

Code:
format PE GUI 4.0
entry start

include 'win32axp.inc'
include 'macro\masm.inc'
include 'misc\macro.inc'

section '.text' code readable executable

start:
invoke  GetModuleHandle,0
mov [hInst],eax
invoke DialogBoxParam,eax,100,HWND_DESKTOP,MainProc,0
invoke ExitProcess,eax

proc MainProc uses ebx esi edi,hwnd,msg,wparam,lparam

.if [msg] = WM_CLOSE

invoke  EndDialog,[hwnd],0
mov eax,1

.elseif [msg] = WM_INITDIALOG

push dword [hwnd]
pop dword [hwndm]
mov eax,1


.elseif [msg] = WM_LBUTTONDOWN

invoke SendMessage,[hwnd],WM_NCLBUTTONDOWN,HTCAPTION,NULL
mov eax,1

.elseif [msg] = WM_RBUTTONDOWN

invoke Sleep,200
invoke  EndDialog,[hwnd],0
mov eax,1

.elseif [msg] = WM_MOUSEWHEEL

mov eax,[wparam]
mov [MouseW],eax

xor eax,eax

.elseif [msg] = WM_COMMAND

 .if [wparam]  = 1000 ; button id
invoke GetDlgItem,[hwnd],2001 ;text box hwnd i'm trying to retrieve 
invoke GetLastError
invoke GetWindowTextLength,eax
 .endif

mov eax,1

.else

xor eax,eax

.endif


ret

endp

section '.data' data readable writeable


HTCAPTION = 2


hInst dd ?
hwndm dd ?

MouseW dd ?
dummy dd ?

section '.rsrc' data readable resource from 'strenc.RES'


section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',\
          user32,'USER32.DLL',\
          gdi32,'GDI32.DLL',\
          kernelbase,'KERNELBASE.DLL'

  include 'api\kernel32.inc'
  include 'api\user32.inc'
  include 'api\gdi32.inc'

import kernelbase,GetNativeSystemInfo,'GetNativeSystemInfo'         


and resource:

Code:
100 DIALOGEX 0, 0, 331, 105
  LANGUAGE LANG_NEUTRAL,SUBLANG_NEUTRAL // Language neutral
  CAPTION "String Encrypt"
  EXSTYLE 0 // 0x00000000L
  STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_SYSMENU | WS_DLGFRAME | WS_BORDER | WS_VISIBLE | WS_POPUP // 0x90C808C0L
  FONT 8, "Terminal"
BEGIN
  CONTROL "Encrypt", 1000, "button", BS_PUSHBUTTON | BS_LEFT | BS_RIGHT | BS_TOP | BS_BOTTOM | WS_TABSTOP | WS_VISIBLE | WS_CHILD, 237, 60, 60, 25
  CONTROL "", 2001, "edit", ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP | WS_VISIBLE | WS_CHILD, 27, 20, 177, 28, WS_EX_CLIENTEDGE
  CONTROL "", 2002, "edit", ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP | WS_VISIBLE | WS_CHILD, 27, 58, 177, 28, WS_EX_CLIENTEDGE
  CONTROL "", 2003, "edit", ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP | WS_VISIBLE | WS_CHILD, 238, 21, 54, 26, WS_EX_CLIENTEDGE
END
    
Post 12 Feb 2022, 11:32
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 480
Location: Russia
macomics
Code:
invoke GetDlgItem,[hwnd],2001 ;text box hwnd i'm trying to retrieve 
; invoke GetLastError
invoke GetWindowTextLength,eax    
or
Code:
invoke GetDlgItem,[hwnd],2001 ;text box hwnd i'm trying to retrieve 
push eax
invoke GetLastError
invoke GetWindowTextLength    
Post 12 Feb 2022, 11:42
View user's profile Send private message Reply with quote
extra_12345



Joined: 21 Apr 2020
Posts: 28
extra_12345
yeah i know that the problem is :
invoke GetDlgItem,[hwnd],2001
returns 0 and getlasterror returns = 1421 (0x58D) - Control ID not found
Post 12 Feb 2022, 13:23
View user's profile Send private message Reply with quote
FlierMate



Joined: 21 Jan 2021
Posts: 213
Location: Malaysia
FlierMate
I am newbie to Win32Dlg but after comparing with tutorial & example code, your code actually work but I need to modify the resource file.

Code:
 .if [wparam]  = 1000 ; button id
invoke GetDlgItem,[hwnd],2001 ;text box hwnd i'm trying to retrieve 
;invoke GetLastError
;invoke GetWindowTextLength,eax
invoke  GetWindowText,eax,Buffer,255
invoke MessageBox,[hwnd],Buffer,'',MB_OK
 .endif    


Code:
section '.data' data readable writeable

Buffer rb 255    


I could not find "misc\macro.inc". And below is my modification to your resource section:

Code:
section '.rsrc' resource data readable

 directory RT_DIALOG,dialogs

  resource dialogs,\
           100,LANG_NEUTRAL+SUBLANG_NEUTRAL,demonstration
  dialog demonstration,'String Encrypt',0, 0, 331, 105,DS_MODALFRAME or DS_CENTER or WS_SYSMENU or WS_DLGFRAME or WS_BORDER or WS_VISIBLE or WS_POPUP
    dialogitem 'BUTTON','Encrypt',1000,237, 60, 60, 25,BS_PUSHBUTTON + BS_LEFT + BS_RIGHT + BS_TOP + BS_BOTTOM + WS_TABSTOP + WS_VISIBLE + WS_CHILD
    dialogitem 'EDIT','',2001, 27, 20, 177, 28,ES_LEFT + ES_AUTOHSCROLL + WS_TABSTOP + WS_VISIBLE + WS_CHILD
    dialogitem 'EDIT','',2002, 27, 58, 177, 28,ES_LEFT + ES_AUTOHSCROLL + WS_TABSTOP + WS_VISIBLE + WS_CHILD
    dialogitem 'EDIT','',2003, 238, 21, 54, 26,ES_LEFT + ES_AUTOHSCROLL + WS_TABSTOP + WS_VISIBLE + WS_CHILD
  enddialog      
    


After clicking the "Encrypt" button, a message box will pop up showing the text content of top left text box (2001).

Sorry if this is not helpful.


Description: Running on Wine
Filesize: 7.86 KB
Viewed: 1296 Time(s)

Screenshot_2022-02-12_23-04-28.png


Post 12 Feb 2022, 15:13
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 480
Location: Russia
macomics
extra_12345 wrote:
yeah i know that the problem is :
invoke GetDlgItem,[hwnd],2001
returns 0 and getlasterror returns = 1421 (0x58D) - Control ID not found
Then attach a binary file or a resource file (*.RES). It is worth checking the structure of windows in the dialog created in your resource. Although you can do it yourself using a program similar to Spy++.
You can do without it. Just use the EnumChildWindows function to find all child windows. Next, check the parameters:
Code:
  invoke EnumChildWindows, [hwnd], EnumCheckProc, NULL

...

proc EnumCheckProc, ..., hChild, lParam
  invoke GetWindowLong, [hChild], GWL_ID
  cmp eax, 2001
...
    
Post 12 Feb 2022, 18:19
View user's profile Send private message Reply with quote
Walter



Joined: 26 Jan 2013
Posts: 151
Walter
This works for me. Something to do with resource file?

Image[/img]


Description:
Download
Filename: strenc.zip
Filesize: 72.77 KB
Downloaded: 86 Time(s)

Post 12 Feb 2022, 19:28
View user's profile Send private message Reply with quote
extra_12345



Joined: 21 Apr 2020
Posts: 28
extra_12345
thanks for the help ,yeah i think definitely it has something to do with my resource files.
i've used EnumChildWindows and a debugger to check the hwnd of the controls in the EnumChildProc callback function and surprisingly it returned 0xFFFF07D3 instead of just 0x07D3 for the text box dunno why.
Post 12 Feb 2022, 23:27
View user's profile Send private message Reply with quote
extra_12345



Joined: 21 Apr 2020
Posts: 28
extra_12345
macomics wrote:
extra_12345 wrote:
yeah i know that the problem is :
invoke GetDlgItem,[hwnd],2001
returns 0 and getlasterror returns = 1421 (0x58D) - Control ID not found
Then attach a binary file or a resource file (*.RES). It is worth checking the structure of windows in the dialog created in your resource. Although you can do it yourself using a program similar to Spy++.
You can do without it. Just use the EnumChildWindows function to find all child windows. Next, check the parameters:
Code:
  invoke EnumChildWindows, [hwnd], EnumCheckProc, NULL

...

proc EnumCheckProc, ..., hChild, lParam
  invoke GetWindowLong, [hChild], GWL_ID
  cmp eax, 2001
...
    


sorry i forgot,here's the resource file.


Description:
Download
Filename: strenc.rar
Filesize: 240 Bytes
Downloaded: 81 Time(s)

Post 12 Feb 2022, 23:30
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 480
Location: Russia
macomics
I can guess that you are using a 16-bit resource generator. Though on new computers, they are in theory no longer launched. At a minimum, window IDs are created with the 0xFFFF bit extension.


Description:
Filesize: 74.33 KB
Viewed: 1242 Time(s)

strenc.png


Post 13 Feb 2022, 00:18
View user's profile Send private message Reply with quote
extra_12345



Joined: 21 Apr 2020
Posts: 28
extra_12345
wow never thought of that,thanks,btw is there any good resource generator that i could use to generate 32 bit resource file?
Post 13 Feb 2022, 01:25
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 480
Location: Russia
macomics
extra_12345 wrote:
wow never thought of that,thanks,btw is there any good resource generator that i could use to generate 32 bit resource file?
The fasm1 kit for Windows already has macros for generating resources. To use them, include the MACRO/RESOURCE.INC file. See the example given by FlierMate.
FlierMate wrote:
Code:
section '.rsrc' resource data readable

 directory RT_DIALOG,dialogs

  resource dialogs,\
           100,LANG_NEUTRAL+SUBLANG_NEUTRAL,demonstration
  dialog demonstration,'String Encrypt',0, 0, 331, 105,DS_MODALFRAME or DS_CENTER or WS_SYSMENU or WS_DLGFRAME or WS_BORDER or WS_VISIBLE or WS_POPUP
    dialogitem 'BUTTON','Encrypt',1000,237, 60, 60, 25,BS_PUSHBUTTON + BS_LEFT + BS_RIGHT + BS_TOP + BS_BOTTOM + WS_TABSTOP + WS_VISIBLE + WS_CHILD
    dialogitem 'EDIT','',2001, 27, 20, 177, 28,ES_LEFT + ES_AUTOHSCROLL + WS_TABSTOP + WS_VISIBLE + WS_CHILD
    dialogitem 'EDIT','',2002, 27, 58, 177, 28,ES_LEFT + ES_AUTOHSCROLL + WS_TABSTOP + WS_VISIBLE + WS_CHILD
    dialogitem 'EDIT','',2003, 238, 21, 54, 26,ES_LEFT + ES_AUTOHSCROLL + WS_TABSTOP + WS_VISIBLE + WS_CHILD
  enddialog     
Post 13 Feb 2022, 01:47
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.