I know my C\C++ obvious from my misunderstanding, but I just can't seem to get the following to work out for me....

;// In some include
TBMenuItemStruct struct DWORD
eMenuID DWORD 0 eMenuType DWORD 0
eMenuText DWORD 0
eMenuParent DWORD 0 eMenuState DWORD 0 eMenuRect RECT <0,0,0,0>
TBMenuItemStruct ENDS
GenTextRects PROTO menu_list:PTR TBMenuItemStruct

mMainMenuItemsList TBMenuItemStruct\
<\
MENU_ITEM_GAME,\
MENU_TYPE_TOPLEVEL,\
MENU_ITEM_GAME_TEXT,\
MENU_ITEM_NONE,\
MENU_STATE_UNSELECTED,\
<0,0,44,44>>,\
<\
MENU_ITEM_NONE,\
MENU_TYPE_NONE,\
MENU_ITEM_NONE,\
MENU_STATE_NONE,\
MENU_ITEM_NONE,\
<0,0,0,0>>

;// call that passes a pointer to a list of TBMenuItemStructs

invoke GenTextRects, ADDR mMainMenuItemsList

;// ok here is where the problem is ...

GenTextRects proc menu_list:PTR TBMenuItemStruct
;// this is the current max rect for the children menu items of the current group
LOCAL cur_max_rect:RECT
;// ID of the current parent menu (top level or mid level)
LOCAL cur_parent:DWORD
;// the rect of the last top level item so that the next one can be easily calculated
;// set next to it
LOCAL last_top_item_rect:RECT
LOCAL cur_item:PTR TBMenuItemStruct
;// the current menu items text length in logical units (so not view port coords but windows)
LOCAL cur_item_len:DWORD

.data
;// As the max rect for all the items in a sub menu are defined
;// This array will keep the indexs of all those found so that
;// it can quickly go back and set all their rects to the max needed
cur_sub_men_list DWORD [256]
;// simply a flag to know if the last top level rectangle is valid or not
first_top_level_set DWORD 0
.code
push esi
push ecx

;// value to index eax by for the index in the array
mov ecx, sizeof TBMenuItemStruct
;// current index in the array
mov edx, 0
;// number of bytes in the array to jump
mov eax, 0
MainLoopStart:
;// ************** HERE I MOVE ADDY OF THE NEXT STRUCT IN THE ARRAY TO ESI ********************************
mov esi, menu_list
;// ************ SAVE A COPY IN LOCAL VAR ************
mov cur_item, esi
;//************* NOW I NEED A VALUE OF ONE OF THE MEMBERS BUT I END UP WITH A JUNK VALUE ?????? *********
mov eax, [(TBMenuItemStruct PTR cur_item).eMenuType]
mov eax,
...
GenTextRects endp

Quick synompsis....

I pass a pointer to an array of structs to a function.
I put the addy to that array in a local variable
I try to access a member of the struct in the list that the local var is pointing to.
I don't get the value that is there (which is an address of the actual value).

A little help?

Thanks,
[=CC=]AmBuSH
Posted on 2001-10-04 19:21:13 by [=CC=]AMBUSH

mov cur_item, esi
;//************* NOW I NEED A VALUE OF ONE OF THE MEMBERS BUT I END UP WITH A JUNK VALUE ?????? *********
mov eax, [(TBMenuItemStruct PTR cur_item).eMenuType]
mov eax,


You are trying to treat a pointer to the struct as an actual struct. cur_item is a local and can't be used in the way you want unless you move it to a register. I don't understand why you don't use:

mov eax, [(TBMenuItemStruct PTR esi).eMenuType]
Posted on 2001-10-05 01:44:51 by gliptic
Doing it that way is fine. I guess I still don't see why you can do it with a register and not a LOCAL var. I was only storing it there for readability really. There wasn't any real functional reason for it.
Posted on 2001-10-05 16:39:28 by [=CC=]AMBUSH
The reason you can't use a local is because it expands to:

mov eax, [(TBMenuItemStruct PTR (ebp-???)).eMenuType]

And then it further expands to:

mov eax,

And that's the same as treating the local as the actual struct.
You have to dereference the pointer to a register before you can use it. In your case, it's not needed since you already have the pointer in ESI.

Sorry, if I can explain it very well.
Posted on 2001-10-08 01:00:36 by gliptic