I have a string that I declared like this:
yname db 20h dup (0)
and I populate it like this:
invoke GetDlgItemTextA, hWnd, IDC_EDIT1, offset yname, 49
Now what I would like to do is SAVE this to another variable. I declared a buffer like this:
namebuffer dd ?
How do I get yname into namebuffer? I have tried M2M, I have tried using the EAX register - nothing. I am missing something simple here I believe.
Thanks!
Giovanni
yeah, this is not visual basic.
To copy a string into another one you can do this:
yname db 20h dup (0)
namebuffer db 20h dup (0)
invoke GetDlgItemTextA, hWnd, IDC_EDIT1, offset yname, 49
invoke lstrcpy, addr namebuffer, addr yname
Or if it is just to create a pointer to the first buffer:
yname db 20h dup (0)
namebuffer dd 0
mov eax,offset yname
mov namebuffer,eax
ahhhhhh lstrcpy.. i knew i missed something.
thanks so much.
QuoteI have a string that I declared like this:
yname db 20h dup (0)
and I populate it like this:
invoke GetDlgItemTextA, hWnd, IDC_EDIT1, offset yname, 49
You are reserving only 32 bytes for the "yname" variable, and then you allow the "GetDlgItemTextA" function to write as many as 49 characters at that location. That could trash some of your other data if IDC_EDIT1 contains more than 31 characters.
Raymond
Good catch. Would this just truncate the data or cause an error?
If the string is too large, GetDlgItemTextA may try to write where it can't (producing an access violation) or where it shouldn't (overwrite the content of the following variables or code in memory) or both.
Giovanni,
There is a procedure in the MASM32 library called szCopy that will do the copy task for you and you have the source available to see how its done.
A couple of tricks,
Allocate the buffer to receive the data from the API call in the UNinitialised data section. You keep the EXE file smaller this way.
.data?
buffer db 256 dup (?)
You can use code like this to do the copy to a buffer,
invoke szCopy,ADDR source,ADDR buffer