The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: george999 on November 17, 2007, 08:03:39 PM

Title: array
Post by: george999 on November 17, 2007, 08:03:39 PM
I want to put an array in edit box.But when i invoke SetDlgItemText,hWin,1000,array it put only first item.

item0    dd "1",0
item1    dd "2",0
item2    dd "3",0
       

array DWORD item0,item1, item2,0
...
invoke SetDlgItemText,hWin,1000,array

How can I put all  array in edit box ?


Title: Re: array
Post by: donkey on November 17, 2007, 08:22:29 PM
QuoteSetDlgItemText....

lpString
[in] Pointer to the null-terminated string that contains the text to be copied to the control.

Since your first item is null terminated the API assumes that the end of the first element is the end of the string to add. SetDlgItemTxt is not designed to handle arrays of strings only a single string. To put the array in you will have to write a routine that reads the array and writes it to the text box one at a time.

Donkey
Title: Re: array
Post by: ragdog on November 17, 2007, 09:18:24 PM
hi


use this


.const
item0    equ "1"
item1    equ "2"
item2    equ "3"

.data
array db item0,item1, item2,0




greets
ragdog
Title: Re: array
Post by: MichaelW on November 18, 2007, 12:56:53 AM
George,

Items that are to be displayed as text (strings) would normally be defined with DB instead of DD. MASM will return an error if you try to assign a string longer than 4 bytes to a DWORD, and for shorter strings MASM will reverse the order of the bytes, and encode nulls for any byte not defined. For example:

item1 dd “1�,0

Would be encoded as:

31000000h, 00000000h

So even if you left off the null termination there would still be a null byte to terminate the string after the “1�.

Also, to display the array as text with each element on a separate line, you could terminate all but the last element with a CRLF, something like this:

item0 db “1�,13,10
item1 db “2�,13,10
item2 db “3�,0

Title: Re: array
Post by: george999 on November 18, 2007, 03:57:58 AM
item1 dd “1�,0

Would be encoded as:

31000000h, 00000000h

So even if you left off the null termination there would still be a null byte to terminate the string after the “1�.


and if i put it in binary?

item0          db  00110001b

How will be encoded?
Title: Re: array
Post by: george999 on November 18, 2007, 04:05:09 AM
In binary it's working... :lol
Title: Re: array
Post by: Mark Jones on November 18, 2007, 04:30:19 AM
Quote from: george999 on November 18, 2007, 03:57:58 AM
item1 dd “1�,0
and if i put it in binary?

item0          db  00110001b


Hello, note that "00110001b" could be a hexadecimal number... to explicitly define a number as binary, use the "y" post-fix, i.e. 00110001y