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" ???
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" ???
Well you could use the following:
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:
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.
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.
To not bother with converting of numbers you may use SetDlgItemInt to show chars number in another edit or label on same dialog.
Template db "The Amount of Letters for "%s" is %i",0
(63) : error A2009: syntax error in expression
i think there is missing a "
Oh my fault...replace it with :
Template db 'The Amount of Letters for "%s" is %i',0
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.
@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
"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
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.
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.
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,...
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,...
@Jimmy: you dont have to change the quote character
"The Amount of Letters for ""%s"" is %i"
Good to know. Thanks.
thx :)