Variant OLE automation

The Variant data type is the data type for all variables.

  can contain any kind of data except fixed-length String data. 

You can use the Variant data type in place of any data type to work with data in a more flexible way. If the contents of a Variant variable are digits, they may be either the string representation of the digits or their actual value, depending on the context. 

变体类型VARIANT 其实是一个结构,结构中用一个vt成员表示数据的类型,同时真正的数据则存储在union空间中。

1.        struct VARIANT
2.        {
3.            VARTYPE vt;                     //
数据类型 
4.            union
5.            {
6.                LONG            lVal;       //VT_I4 
7.                VARIANT_BOOL    boolVal     //VT_BOOL 
8.                BSTR            bstrVal;    //VT_BSTR 
9.            }
10.    };

http://blog.csdn.net/hsqaihkl/article/details/9149081

 上面的结构为了帮助理解,实际的定义如下

typedef struct tagVARIANT {
  union {
    struct __tagVARIANT {
      VARTYPE vt;
      WORD    wReserved1;
      WORD    wReserved2;
      WORD    wReserved3;
      union {
        LONGLONG            llVal;
        LONG                lVal;

        ......

        UINT                *puintVal;
        struct __tagBRECORD {
          PVOID       pvRecord;
          IRecordInfo *pRecInfo;
        } __VARIANT_NAME_4;
      } __VARIANT_NAME_3;
    } __VARIANT_NAME_2;
    DECIMAL             decVal;
  } __VARIANT_NAME_1;
} VARIANT, *LPVARIANT, VARIANTARG, *LPVARIANTARG;

 

Variant structure

http://msdn.microsoft.com/en-us/library/windows/desktop/ms221627(v=vs.85).aspx

Variant date type

http://msdn.microsoft.com/en-us/library/office/gg251448.aspx

 COleVariant  基于  Variant

自动化技术的难点在于数据的传递。应用VARIANT type,which is a tagged union, it has a data member for the value (this is an anonymous C++ union) and a data member indicating the type of information stored in the union.

ThVARIANT type is encapsulated in the COleVariant class. The supporting CURRENCY and DATEclasses are encapsulated in the COleCurrency and COleDateTime classes.

_____OLE antomation

OLE, object linking and enbeding, 对象链接和嵌入。

OLE自动化:一个程序有计划的控制另一个程序的能力

OLE 控件: 小型的组件程序,可嵌入到另外的程序,提供自己专有的功能。

OLE文档:完善早期的混合文档功能,不但支持简单链接和嵌入,还支持在位激活和拖放

服务器: 通过特定的接口,将自己完成的一些功能,提供给使用自己的一些程序。 如绘图程序就是一个文档服务器。

automation 和OLE文档技术类似,允许一个应用程序 编程控制 另一个应用程序“自愿”提供的功能的技术,称为OLE自动化。                         前一个应用程序:自动化客户或控制器。另一个应用程序称为自动化服务器。

如VC 控制 excel. VC 是自动化客户。 excel 是服务器。

随着对OLD技术的要求越来越广泛,微软将其用新的标签代替,即 ActiveX.

参考

http://blog.csdn.net/feijj2002_/article/details/466215

_____COleSafeArray       //a,用于数组

COleSafeArray derives from the OLE VARIANT structure. The OLE SAFEARRAY member functions are available through COleSafeArray, as well as a set of member functions specifically designed for one-dimensional arrays of bytes.

COleVariant 似乎与Variant 用法差不大,但又是两个东西。

原文地址:https://www.cnblogs.com/aprilapril/p/3462961.html