From: http://expert.9cbs.net/expert/faq/faq_index.asp? Id = 188857 Variant, _variant_t and Colevariant Variant's Structure can refer to the definition of structural tagvariant in the header file VC98 / include / OAIDL.H.
For the assignment of the variant variable: first assign a value to the VT member, specify the data type, and then assign a value of the same data type in the federation, take an example: Variant Va; int a = 2001; va.vt = vt_i4; // indicate Integer data va.lval = a; // / assignment For Variant that does not immediately assign, it is best to use Void Variantinit (Variantarg Far * Pvarg); in the initialization, the nature is set to vt_empty, the following table We list VT Correspondence with common data: byte bval; // vt_ui1. Short iv; // vt_i2. Long lval; // vt_i4. Float fltval; // vt_r4. Double dblval; // vt_r8. Variant_bool boolval; // vt_bool. Scode scode; // VT_ERROR CY cyVal; // VT_CY DATE date; // VT_DATE BSTR bstrVal; // VT_BSTR DECIMAL FAR * pdecVal // VT_BYREF | VT_DECIMAL IUnknown FAR * punkVal;..... // VT_UNKNOWN IDispatch FAR * pdispVal. ; // vt_dispatch. Safearray Far * Parray; // vt_Array | *. Byte Far * Pbval; // vt_byref | vt_ui1. Short far * pival; // vt_byref | vt_i2. Long Far * PLVAL; // vt_byref | vt_i4. Float Far * pfltval; // vt_byref | vt_r4. Double Far * pdblval; // vt_byref | vt_r8. Variant_bool far * pboolval; // vt_byref | vt_bool. Scode far * pscode; // vt_byref | vt_error. Cyber * pcyval; // Vt_byref | vt_cy. Date Far * pdate; // vt_byref | vt_date. BSTR FA R * pbstrVal; // VT_BYREF | VT_BSTR IUnknown FAR * FAR * ppunkVal; // VT_BYREF | VT_UNKNOWN IDispatch FAR * FAR * ppdispVal;.. // VT_BYREF | VT_DISPATCH SAFEARRAY FAR * FAR * pparray;. // VT_ARRAY | * VARIANT. Far * pvarval; // vt_byref | vt_variant. Void far * byref; // generic byref. Char cval; // vt_i1. Unsigned short uiVal; // vt_ui2. Unsigned long ulval; // vt_ui4. Int IntVal; // vt_int. Unsigned int uintval; // vt_uint. CHAR FAR * PCVAL; // vt_byref | vt_i1. UNSIGNED SHORT FAR * PUIVAL; // vt_byref | vt_ui2. Unsigned long far * pulval; // vt_byref | vt_ui4. int far * pintval; // VT_BYREF | VT_INT. UNSIGNED INT FAR * PUINTVAL; // vt_byref | vt_uint. _Variant_t is a Variant's package class, and its assignment can use forced type conversion,