To define struct array of EVENTMSG, the code in MS visual C++ is:

EVENTMSG EventArr[1000]; 


I know I can do it in masm32 as:


EventArr EVENTMSG <>
EventArr1 EVENTMSG <>
EventArr2 EVENTMSG <>
EventArr3 EVENTMSG <>
....
EventArr999 EVENTMSG <>


but I think there maybe a easy way, such as a macro, to do it?

Thanks
Posted on 2005-08-24 03:32:29 by purpleendurer
Give this a blast.

    .data?
      rctarr RECT 1024 dup (<?>)

Declaring the array is the easy part. To access a member structure, you must know the length of the structure and use an index that is multiplied by the structure length. If you are just scanning through the array of structures.

I can think of far nicer ways to do this using allocated memory. If you are using MASM32, have a look at the procedure in the masm32 library,

create_array proc acnt:DWORD,asize:DWORD

Make the array size parameter the length of your structure and if this is not an even number padd the size up to the next division by 4 so all of the memory remains aligned and then read and write to the array of structures using normal methods for structures using a register.
Posted on 2005-08-24 04:41:13 by hutch--
A structure is simply a memory buffer of a certain size that allows you to use names to access invidual elements within the buffer. So in reality when you declare an EVENTMSG strucutre all you are doing is setting aside 20 bytes of memory, the compiler uses a structure to address individual bytes, words or dwords within that memory block. So in reality you can just allocate enough space to hold the 1000 structures...

All of the following have the same end result...

ArrayEVENTMSG DB 20000 DUP (?)
ArrayEVENTMSG DB (SIZEOF EVENTMSG * 1000) DUP (?)
ArrayEVENTMSG EVENTMSG 1000 DUP (<?>)


They will allocate the necessary amount of memory to hold 1000 EVENTMSG structures. To access the array you can use a base+offset method as follows.

; load the index of the structure that you want
mov eax,
; calculate the offset
mov ecx,SIZEOF EVENTMSG
mul ecx
mov edi, offset ArrayEVENTMSG
; now get an element in the nIndex structure of the array...
mov eax,


Note that if you are simply stepping through sequentially you can accomplish the same thing by simply adding the size of the structure to the base each time...

mov edi, offset ArrayEVENTMSG
mov ebx,0
@@:
mov eax,
; do your thing here
add ebx, SIZEOF EVENTMSG
cmp ebx, (SIZEOF EVENTMSG*1000)
jle @B


In some cases (not this one) you can use scaling to avoid the calculation of the offset to the array entry. But it will only work with sizes of 2,4 or 8...

mov eax, 
mov eax,

Posted on 2005-08-24 07:23:37 by donkey
Thanks hutch-- and donkey very much...

Yes, A structure or a array is simply a memory buffer
I know it in dos-asm :)
buy forgot it in win-asm :sad:

I recall it now...
Posted on 2005-08-24 10:20:14 by purpleendurer