i used the search function and found this:

If pointer to string is in eax

invoke lstrlen,eax

Returns lenght of string in eax.

mh okay, but how i get the pointer in eax?
i want to know the lenght of this one

invoke GetDlgItemText, hWin, IDC_EDT1, ADDR IDC_EDT1_Str, 10

invoke lstrlen,eax
mov  teststr, eax
invoke MessageBox, NULL, ADDR testString, addr testString, MB_OK

.. no success

i have also read that it returns the size, but if I do this

teststr dd 4
mov  teststr, eax

and use it in a msgbox i get no size I have an "alt" ???
Posted on 2006-07-26 13:29:08 by golden_jubilee
Well you could use the following:


invoke lstrlen, ADDR IDC_EDT1_STR
or
invoke lstrlen, OFFSET IDC_EDT1_STR


But in this case the call to lstrlen is not needed as GetDlgItemText returns the number of characters copied into the Buffer.

Unfortunately you won't be able to display the amount of letters in a MessageBox unless you convert the amount to Ascii.

Try this code:


.data
Template db "The Amount of Letters for "%s" is %i",0

.data?
IDC_EDT1_Str db 128 dup (?)
TempBuffer db 256 dup (?)

.code
invoke GetDlgItemText, hWin, IDC_EDT1, ADDR IDC_EDT1_Str, 128
invoke wsprintf, ADDR TempBuffer, ADDR Template, ADDR IDC_EDT1_Str, eax
invoke MessageBox, 0, ADDR TempBuffer, 0, MB_OK


I used an Api named wsprintf to do the conversion from dword to ascii but you could also do the conversion by itself using helper functions like dwta found in masm.lib.
Posted on 2006-07-26 13:51:41 by JimmyClif
To not bother with converting of numbers you may use SetDlgItemInt to show chars number in another edit or label on same dialog.
Posted on 2006-07-27 02:50:45 by Shoo

Template db "The Amount of Letters for "%s" is %i",0

(63) : error A2009: syntax error in expression

i think there is missing a "
Posted on 2006-07-27 02:54:47 by golden_jubilee
Oh my fault...replace it with :


Template db 'The Amount of Letters for "%s" is %i',0
Posted on 2006-07-27 04:27:51 by JimmyClif

Well you could use the following:


invoke lstrlen, ADDR IDC_EDT1_STR
or
invoke lstrlen, OFFSET IDC_EDT1_STR



Just wanted to point out that t won't work, IDC_* are constants for dialog items, not strings.
Posted on 2006-07-27 05:11:01 by f0dder
@Jimmy: you dont have to change the quote character
"The Amount of Letters for ""%s"" is %i"

@f0dder:
char IDC_EDT1_STR[128];
GetDlgItemText(hWin,IDC_EDT1,&IDC_EDT1_STR,128);

is this ok?  :P
Posted on 2006-07-27 05:41:05 by drizz
drizz: why throw in C code? Also, for assembly as well as for C, you should use sizeof instead of a hardcoded value - and it would also be nice using a constant instead of hardcoded 128 in the variable definition.

Oh, for C I'd even say "don't use sizeof, use lengthof" - easier to have the code working on both ansi and unicode that way.
Posted on 2006-07-27 05:47:31 by f0dder
f0dder, i was implying the buffer name?  :), it can be IDC_EDT1_STR if the newbie
finds it associative with control id.

ps. as for me...i never use hardcoded values, i always recommend using equates, structures, sizeof, lengthof, mask, assume,...
Posted on 2006-07-27 05:58:07 by drizz

@Jimmy: you dont have to change the quote character
"The Amount of Letters for ""%s"" is %i"


Good to know. Thanks.
Posted on 2006-07-27 06:01:20 by JimmyClif
thx  :)
Posted on 2006-07-27 11:36:15 by golden_jubilee