The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Nilrem on February 21, 2005, 11:40:20 PM

Title: GetDlgItemText problems.
Post by: Nilrem on February 21, 2005, 11:40:20 PM
When I am using this api I obviously have to specify the number of bytes I want to be read, now my question is how can I specify the size of the buffer just read in? For example:
invoke GetDlgItemText, hCombo, 1003, lpDropDown, sizeof lpDropDown However as I expected that results in a crash.

Edit:
Any reason why this does not work properly? lpDropDown seems to stay empty:
invoke GetDlgItemText, hCombo, 1003, offset lpDropDown, 20
Title: Re: GetDlgItemText problems.
Post by: dev_zero on February 22, 2005, 12:11:37 AM
This:
invoke GetDlgItemText, hCombo, 1003, offset lpDropDown, 20
Should be this:
invoke GetDlgItemText, hCombo, 1003, addr lpDropDown, 20
You'll have to use addr instead of offset when using invoke.
Title: Re: GetDlgItemText problems.
Post by: pbrennick on February 22, 2005, 01:21:26 AM
dev_zero,
Who told you that?  You were mislead.  Want me to post some working code?

Paul
Title: Re: GetDlgItemText problems.
Post by: raymond on February 22, 2005, 04:44:28 AM
Nilrem

How about posting that part of your code where you declare the lpDropDown and describe the 1003 for your combo.

Raymond
Title: Re: GetDlgItemText problems.
Post by: Nilrem on February 22, 2005, 10:17:16 AM
Why? I mean it works, the items are there on the drop-down menu, but upon retrieving the selection (from the drop-down menu) made it doesn't work.

Ok, here goes:


.data

lpDropDown dd 128 dup(?)
nDropDown dd 20

.const

IDD_DIALOG1 equ 101
IDC_IDCBTN1 equ 1001
IDC_BTN_ABOUT equ 1002
IDC_DROP equ 1003

.code

DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL cbi:COMBOBOXEXITEM
LOCAL buffer[256]:BYTE
LOCAL mValue:DWORD
mov eax,uMsg
;call FillMyCombo
.if (eax==WM_INITDIALOG)

;/* Combobox setup */
invoke GetDlgItem,hWin,1003
mov hCombo,eax

;/* Fill it up] */
invoke FillMyCombo
invoke UpdateWindow,hWnd

.elseif (eax==WM_COMMAND)
mov eax,wParam
.if (eax==1001) ; button pressed
invoke GetDlgItemText, hCombo, 1003, offset lpDropDown, nDropDown
invoke MessageBox,NULL,lpDropDown,lpDropDown,NULL
mov eax, offset lpDropDown
mov ecx, offset String1
.if eax==ecx
call RegistryProc
.else
;mov ecx, offset org_val
;mov edx, offset new_val
;push ecx; Save the values for later
;push edx
call SearchProc
.endif
.elseif (eax==1002) ; About button
invoke MessageBox, NULL, ADDR MsgBoxTextAbout, ADDR MsgBoxCaption, MB_OK
.endif
.endif
Title: Re: GetDlgItemText problems.
Post by: sluggy on February 22, 2005, 12:21:44 PM

invoke GetDlgItemText, hCombo, 1003, offset lpDropDown, nDropDown


Change hCombo to hWin.
And don't forget to use GetLastError, it will usually tell you exactly what the error was.
Title: Re: GetDlgItemText problems.
Post by: AeroASM on February 22, 2005, 12:29:12 PM
You should rename lpDropDown to szDropDown. That will stop you getting confused.
Title: Re: GetDlgItemText problems.
Post by: petezl on February 22, 2005, 01:02:35 PM
The reason for asking to post the whole code is to get a better picture of what your asking!
Why it is not working is the call Get and SetDlgItemText:
Should be
invoke GetDlgItemText, hDlg, 1003, offset lpDropDown, sizeof lpDropDown
invoke MessageBox,hDlg,offset lpDropDown,offset lpDropDown,NULL
:U
Peter
Title: Re: GetDlgItemText problems.
Post by: Nilrem on February 22, 2005, 01:08:59 PM
Thanks guys. What was wrong with SetDlgItemText? I'm asking because it is working as expected for me. I use hDlg because that is the dialog window not the control? I'll try the suggestions when I get home. Really appreciate the help and explanations.
Title: Re: GetDlgItemText problems.
Post by: petezl on February 22, 2005, 01:31:53 PM
Nilrem,
Ignore the SetDlgItem Text bit,  it escaped into my message in the confusion over your choice of variables.
As you probably know, there is no CB_GETTEXT so whenever I've used a ComboBox I use the CB_GETCURSEL message.
Anyway, if you need a ComboBox skeleton just ask...
Peter.
Title: Re: GetDlgItemText problems.
Post by: Nilrem on February 22, 2005, 02:16:53 PM
I can seriously use CB_GETCURSEL to get what is selected in the drop-down menu? If so which is more efficient, using that or getdlgitemtext? Can you pm me your skeleton please, it's probably better then mine (though it does work as I want it to). Once again, thanks.
Title: Re: GetDlgItemText problems.
Post by: dev_zero on March 02, 2005, 01:19:39 PM
Quote from: pbrennick on February 22, 2005, 01:21:26 AM
dev_zero,
Who told you that?  You were mislead.  Want me to post some working code?

Paul


Sorry my bad, when I see the source code now. I see that it was not an local variable.