News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Structures, Indirect Reference

Started by raleeper, January 02, 2010, 04:05:07 PM

Previous topic - Next topic

raleeper

I would like to reference the fields of a structure indirectly, for example, by loading ebx with the address of the structure, and then the field by, eg.,

   mov   ebx, OFFSET lpwin
   mov   edx, [ebx.wdt]   or
   mov   edx, [ebx].wdt

These are the declarations:

lwstr   STRUC      ;Lfile Window STRucture
bkc   DD   ?      ; 0 BacKground Color
txc   DD   ?      ; 4 TeXt Color
hp   DD   ?      ; 8 Horizontal Position
vp   DD   ?      ;10 Vertical Position
hgt   DD   ?      ;14 HeiGhT
wdt   DD   ?      ;18 WiDTh
bad   DD   lwma      ;1C Buffer ADdress   LWMAin
lwstr   ENDS

lpwin   lwstr   <4040,   0,   40,   20,   6,   10,   dwbuf>

The MASM32 Reference implies that this can be done.

     You must refer to structure members in the format

     structurename.membername or with a pointer to a structure followed
     by the .membername tag.

But the mov edx instructions above give "symbol undefined: wdt", while mov edx, [lpwin.wdt] works OK.

What am I doing wrong?

Thanks,
Robert

redskull

Add:

assume ebx:PTR lwstr

before you do the reference.  Note that you'll have to 'assume nothing' when you want to use it for something else

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

jj2007

Robert,
Assume works fine, but even simpler is the syntax
mov eax, [ebx.RECT.left]
mov eax, [ebx.RECT.top]
etc

raleeper

Thanks.

That works fine.


Quote from: jj2007 on January 02, 2010, 05:55:57 PM
Robert,
Assume works fine, but even simpler is the syntax
mov eax, [ebx.RECT.left]
mov eax, [ebx.RECT.top]
etc