封裝聯集

內結構中包含其辨別的等位是封裝的等位。 封裝的等位是由 switch 關鍵字的存在所表示。 這個類型的等位因此命名,因為 MIDL 編譯器會自動將等位及其辨別封裝在結構中,以便在遠端程序呼叫期間傳輸。

如果上述範例中遺漏聯集標記 (U1_TYPE) ,編譯器將會使用名為 tagged_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; 
    union 
    { 
        float f1; 
        double d2; 
    } U1_TYPE; 
} S1_TYPE;

如需相關資訊,請參閱MIDL 基底類型char[coNtext_handle]列舉[first_is][handle]、[ignore]、int、[ignore]、[last_is]、[length_is][max_is][ms_union]Nonencapsulated Unions、[ptr][ref][size_is][string]、structswitch[switch_is]、[switch_type]、[transmit_as]union[unique]