I am new to unions and have a simple problem:
I have a list of MyStruct (see code below) and want to go through the list.
Is there a more effective way to know what is put into the union?
I really don?t want the uType there!
IS_ORDINAL EQU 01h
IS_UNICODE EQU 02h
MyStruct STRUCT
uType db ?
UNION
Ordinal dw 0
Unicode WCHAR 32 dup(?)
ENDS
MyStruct ENDS
I have a list of MyStruct (see code below) and want to go through the list.
Is there a more effective way to know what is put into the union?
I really don?t want the uType there!
IS_ORDINAL EQU 01h
IS_UNICODE EQU 02h
MyStruct STRUCT
uType db ?
UNION
Ordinal dw 0
Unicode WCHAR 32 dup(?)
ENDS
MyStruct ENDS
I don't know exactly what structure you want. If you could outline it in non-code, then I will convert it into MASM syntax. Also, MASM will not let you initialize items in a UNION more than once, but you don't appear to be doing that.
The structure of MyStruct is not important, it?s just a basic example with an union.
Let?s say way have:
s MyStruct <>
; Put stuff into struct
1. Check a variable (defined somewhere) to see if we have a number or a string (unicode)
2. IF result == a number, THEN s.Ordinal = number
ELSE s.Unicode = string
; Analyze struct, HERE IS THE PROBLEM
3. IF s consists of a number THEN Output(s.Ordinal)
ELSE Output(s.Unicode)
----------------------------------------------------------------
Part 3 is done easy by putting an extra variable into the struct, for example: uType = IS_ORDINAL if we have a number.
But that is messing up the structure, making it bigger.
So the optimal, wanted MyStruct would be:
MyStruct STRUCT
UNION
Ordinal dw ?
Unicode WCHAR 32 dup(?)
ENDS
ENDS
The real question is: Is there a way to tell which unionmember is used, without adding extra code?
Let?s say way have:
s MyStruct <>
; Put stuff into struct
1. Check a variable (defined somewhere) to see if we have a number or a string (unicode)
2. IF result == a number, THEN s.Ordinal = number
ELSE s.Unicode = string
; Analyze struct, HERE IS THE PROBLEM
3. IF s consists of a number THEN Output(s.Ordinal)
ELSE Output(s.Unicode)
----------------------------------------------------------------
Part 3 is done easy by putting an extra variable into the struct, for example: uType = IS_ORDINAL if we have a number.
But that is messing up the structure, making it bigger.
So the optimal, wanted MyStruct would be:
MyStruct STRUCT
UNION
Ordinal dw ?
Unicode WCHAR 32 dup(?)
ENDS
ENDS
The real question is: Is there a way to tell which unionmember is used, without adding extra code?
No. There must be some indication to examine/change this at runtime.
Thanks
I have checked some unions in a couple of inc files and discovered that there is some sort of identifyer in the structs!
I have checked some unions in a couple of inc files and discovered that there is some sort of identifyer in the structs!