Export (0) Print
Expand All

Encapsulated Unions

A union that is contained with its discriminant in a structure within is an encapsulated union. The encapsulated union is indicated by the presence of the switch keyword. This type of union is so named because the MIDL compiler automatically encapsulates the union and its discriminant in a structure for transmission during a remote procedure call.

If the union tag is missing (U1_TYPE in the example above), the compiler will generate the structure with the union field named tagged_union.

The shape of unions must be the same across platforms to ensure interconnectivity.

For a description of the form of an encapsulated union, see union.


typedef union _S1_TYPE switch (long l1) U1_TYPE 
    case 1024: 
        float f1; 
    case 2048: 
        double d2; 
} S1_TYPE; 
/* in generated header file */ 
typedef struct _S1_TYPE 
    long l1; 
        float f1; 
        double d2; 
    } U1_TYPE; 
} S1_TYPE;

For related information, see MIDL Base Types, char, [context_handle], enum, [first_is], [handle], [ignore], int, [ignore], [last_is], [length_is], [max_is], [ms_union], Nonencapsulated Unions, [ptr], [ref], [size_is], [string], struct, switch, [switch_is], [switch_type], [transmit_as], union, and [unique]



Community Additions

© 2015 Microsoft