I read the chapter of this community's book about strings. Most of the information was on various methods of finding the length of a string. Does anyone have a tutorial on the most basic use of a string? In masm32 I declare strings like this:

.data?
myString1 db ?
myString2 db ?

But from what I can work out using my still limmited knowledge of assembler is that these two variables are declared as bytes (since their length is still unknown). This means that the address of myString2 is equal to the address of myString1+1 (I guess).

This causes problems for me. If I use GetWindowText and assign the returned string to myString1 and then do the same thing with another string and assign that to myString2 then all but the first byte of mystring1 is overwritten with contents of myString2. At least thats what appears to be happening. I may be completely wrong. In any case does anyone have a tutorial which deals with this issue. I'm also not sure how to deal with buffers with regards to the aforementioned API.

Cheers :alright:
Posted on 2003-12-08 05:31:56 by DeX
Strings are supposed to be an array of bytes (or word for unicode). So technically your example is not a string. Use something like the following:



.data?
string1 db 64 dup (?)
string2 db 32 dup (?)
.code
...
invoke GetWindowText, hwnd, offset string1, 64
Posted on 2003-12-08 05:35:01 by roticv
When declaring a string in the BSS section you are generally declaring a buffer. You must set the legnth of the buffer with the DUP operator:

String1 db 256 DUP (?)
String2 db 256 DUP (?)

Will reserve 256 bytes for String1, String2 will begin at OFFSET String1+256
Posted on 2003-12-08 05:35:49 by donkey
there are two things you want to know

1. Strings
2. Buiffers

strings in masm are ascii strings each character of the size of a byte. you can do unicode in masm but it is painful. there is the L macro by ernie at his website which might help if you wanted unicode strings. theres also a macro by four-f or somebody with a name similar to that in the algorigthms and code forum.

strings are initialized data
buffers for strings are uninitialized placeholders for runtime initialization of data

i may be wrong here since i too am a newbie but basically there is no such data type as string. its just a sequence of bytes. the latter buffer is dynamic and its length is what determines how long a string you can fill in it. (dont forget the ending 0 for win32) i forget it a lot ;)
Posted on 2003-12-08 06:02:36 by evil__donkey