Link to home
Start Free TrialLog in
Avatar of MarkSteward
MarkSteward

asked on

Initialising a STRUCT with DUPs in MASM

I'd like to initialise a STRUCT with a DUP(<>) in it, in particular:

MyTokenPrivileges TOKEN_PRIVILEGES <>

Anyone who's done a reasonable amount of work with MASM on Windows structures should be able to provide the answer here.  In the past I've had to define these structures as bytes instead of properly, but I really want to know the correct way of doing it, as I use MASM a lot, and it's driving me mad!

Sample code (STRUCTs from Hutch's MASM32):


 ANYSIZE_ARRAY equ 1
 LUID STRUCT
   LowPart   DWORD      ?
   HighPart  DWORD      ?
 LUID ENDS
 LUID_AND_ATTRIBUTES STRUCT
   Luid LUID <>
   Attributes dd ?
 LUID_AND_ATTRIBUTES ENDS
 TOKEN_PRIVILEGES STRUCT
   PrivilegeCount DWORD      ?
   Privileges LUID_AND_ATTRIBUTES ANYSIZE_ARRAY dup(<>)
 TOKEN_PRIVILEGES ENDS

 ; Nested STRUCTs are no problem
 ASampleLuidAndAttributes LUID_AND_ATTRIBUTES <<0, 0>, 0>

 ; Nor are DUP()s with normal types:
 _GUID STRUCT
   Data1           DWORD ?
   Data2           WORD ?
   Data3           WORD ?
   Data4           BYTE 8 dup (?)
 _GUID ENDS
 InitialisedGUID _GUID <0, 0, 0, <0c0h, 0, 0, 0, 0, 0, 0, 46h>>

 ; But how do I initialise this with PrivilegeCount = 1?
 MyTokenPrivileges TOKEN_PRIVILEGES <>
 ; I think it should be:
 ;  MyTokenPrivileges TOKEN_PRIVILEGES <1, < <<0, 0>, 0> >>
 ; (i.e. one set of <> for the DUP, as in _GUID,
 ;  and then the normal syntax for a LUID_AND_ATTRIBUTES structure inside).
 ; It returns error A2177: nested structure improperly initialized


And I don't want to change the line to Privileges LUID_AND_ATTRIBUTES <> (although that works).

Thanks to anyone who knows how to do this without resorting to a byte array or initialising it at runtime,
    Mark
Avatar of y2ksw
y2ksw

Privileges ANYSIZE_ARRAY dup ( LUID_AND_ATTRIBUTES <?> )
Avatar of MarkSteward

ASKER

Sorry, I'll have to ask for refund.  I'll post a new question if I ever find out a solution.

Cheers,
    Mark
ARGggh.  Just found it.

http://support.microsoft.com/default.aspx?scid=kb;en-us;94912

inner_struct STRUCT
   w1 DW ?
inner_struct ENDS
outer_struct STRUCT
   s1 inner_struct 2 DUP ({})
outer_struct ENDS

tst1 outer_struct {{{1},{2}}}   ; This line generates an error message
; tst2 outer_struct {{}}        ; This line is allowed

Refund and PAQ, please.

Thanks all,
    Mark
PAQed - no points refunded (of 500)

Computer101
E-E Admin
Why?  Because it was a stupid question?  Or too many points to refund?
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Not worried about the points, just wanted a reason.  Thanks very much.  Sorry about the confusion.

Mark