COleVariant olevarint;
const VARIANT* variant;
m_pRecordSet->GetFieldValue("abc",oldvarint);
variant=(LPCVARIANT)olevarint;
if(variant->vt & VT_BYREF) //这是什么意思?
{
   ...
}
switch(variant->vt)//? {
case VT_I2://什么意思?
strTemp.Format("%d",variant->iVal);
break;
case VT_ERROR:
strTemp.Empty();
break;
case VT_I4:
strTemp.Format("%d",variant->lVal);
break; }

解决方案 »

  1.   

    if(variant->vt & VT_BYREF) //这是什么意思? --- 去这个OLe变量的类型
    {
       ...
    }
    switch(variant->vt)//? {
    case VT_I2://什么意思?------------ 说明是类型为 VT_I2,实际就是2字节的整形数
    strTemp.Format("%d",variant->iVal);
    break;
    case VT_ERROR:
    strTemp.Empty();
    break;
    case VT_I4:
    strTemp.Format("%d",variant->lVal);
    break; }
      

  2.   

    COleVariant( )   Creates an empty COleVariant object, VT_EMPTY.
    COleVariant( varSrc )   Copies an existing VARIANT or COleVariant object. The variant type is retained.
    COleVariant( pSrc )   Copies an existing VARIANT or COleVariant object. The variant type is retained.
    COleVariant( lpszSrc )   Copies a string into the new object, VT_BSTR (UNICODE).
    COleVariant( lpszSrc, vtSrc )   Copies a string into the new object. The parameter vtSrc must be VT_BSTR (UNICODE) or VT_BSTRT (ANSI).
    COleVariant( strSrc )   Copies a string into the new object, VT_BSTR (UNICODE).
    COleVariant( nSrc )   Copies an 8-bit integer into the new object, VT_UI1.
    COleVariant( nSrc, vtSrc )   Copies a 16-bit integer (or Boolean value) into the new object. The parameter vtSrc must be VT_I2 or VT_BOOL.
    COleVariant( lSrc, vtSrc )   Copies a 32-bit integer (or SCODE value) into the new object. The parameter vtSrc must be VT_I4, VT_ERROR, or VT_BOOL.
    COleVariant( curSrc )   Copies a COleCurrency value into the new object, VT_CY.
    COleVariant( fltSrc )   Copies a 32-bit floating-point value into the new object, VT_R4.
    COleVariant( dblSrc )   Copies a 64-bit floating-point value into the new object, VT_R8.
    COleVariant( dateSrc )   Copies a COleDateTime value into the new object, VT_DATE.
    COleVariant( arrSrc )   Copies a CByteArray object into the new object, VT_EMPTY.
    COleVariant( lbSrc )   Copies a CLongBinary object into the new object, VT_EMPTY.
      

  3.   

    if(variant->vt & VT_BYREF) //这是什么意思?
    {
       ...
    }
    能不能举例子说明一下上面语句的意思?
    当variant被赋一个float--4。00后,variant->vt存放什么?VT_BYREF又是作甚么用的?
      

  4.   

    if(variant->vt & VT_BYREF) //这是什么意思?
    {
       ...
    }
    它们为什么要按位与呢?
      

  5.   

    ole 变量是一个对象,它可以存放许多类型的数据,相当于通用的
    但是在实际的系统和情况下,具体的数据时,是不一样的.
    所以它指明了很多存储的地方和方式. 而只有一种是有效的
    有效的这一种,正式指明了它当前是什么,比如他可以存放整形
    和浮点,但一个时候,它只能放一样有效,那么,为了你正确的取得
    具体是什么有效,就用 .vt 来说明了,所以需要根据 .vt 来判断
    当前的实际类型,取得数据。
       大概的意思和原理就是这样,至于为什么要 按位与,实际就是
    判断它是不是那种类型而已。