Variant (variant) and dispatch call (IDispatch)

Source: Internet
Author: User

Variant (variant)

Variant types can theoretically store any type of data, which is why many people in Chinese call it "variants." It is strange for a programmer with a strongly typed language such as C + + to have a Variant (variant) of that type. However, for those languages that dilute the concept of the type, such as Visual Basic, the variant is their default type. In VB, if the variable is not declared with the AS statement, then the variable is variant type. For C + + programmers, the variant is simply a complex structure:

typedef/* [Wire_marshal]/struct tagvariant VARIANT;
struct tagVARIANT
{
Union
{
struct __tagvariant
{
VARTYPE VT;
WORD wReserved1;
WORD WReserved2;
WORD wReserved3;
Union
{
Longlong Llval;
LONG lval;
BYTE Bval;
Short ival;
FLOAT Fltval;
DOUBLE dblval;
Variant_bool Boolval;
_variant_bool BOOL;
SCODE SCODE;
CY Cyval;
Date date;
BSTR Bstrval;
IUnknown *punkval;
IDispatch *pdispval;
SAFEARRAY *parray;
BYTE *pbval;
Short *pival;
LONG *plval;
Longlong *pllval;
FLOAT *pfltval;
DOUBLE *pdblval;
Variant_bool *pboolval;
_variant_bool *pbool;
SCODE *pscode;
CY *pcyval;
DATE *pdate;
BSTR *pbstrval;
IUnknown **ppunkval;
IDispatch **ppdispval;
SAFEARRAY **pparray;
VARIANT *pvarval;
PVOID ByRef;
CHAR Cval;
USHORT Uival;
ULONG Ulval;
ULONGLONG Ullval;
INT intval;
UINT Uintval;
DECIMAL *pdecval;
CHAR *pcval;
USHORT *puival;
ULONG *pulval;
ULONGLONG *pullval;
INT *pintval;
UINT *puintval;
struct __tagbrecord
{
PVOID Pvrecord;
IRecordInfo *precinfo;
} __variant_name_4;
} __variant_name_3;
} __variant_name_2;
DECIMAL Decval;
} __variant_name_1;
} ;

Variant types are widely used in both interpretative and scripting languages. In the visual basic,javascript and so on body, everywhere visible its figure. But without the support of language, the variant operation is complex. Unfortunately, this is the case for C + +. This should be said to be concerned with C + + 's cautious approach to new technologies and the language that is controlled by a non-pure business company. Other languages such as Delphi, must keep pace with the times, is sure to add a variant of the built-in support.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.