用下面的这个函数就可以了.
CString CSelectDlg::VariantToCString(VARIANT var)
{
CString strValue;
_variant_t var_t;
_bstr_t bst_t;
time_t cur_time;
CTime time_value;
COleCurrency var_currency;
switch(var.vt)
{
case VT_EMPTY:
strValue=_T("");
break;
case VT_UI1:
rValue.Format("%d",var.bVal);
break;
case VT_I2:
strValue.Format("%d",var.iVal);
break;
case VT_I4:
strValue.Format("%d",var.lVal);
break;
case VT_R4:
strValue.Format("%f",var.fltVal);
break;
case VT_R8:
strValue.Format("%f",var.dblVal);
break;
case VT_CY:
var_currency=var;
strValue=var_currency.Format(0);
break;
case VT_BSTR:
var_t=var;
bst_t=var_t;
strValue.Format ("%s",(const char*)bst_t);
break;
case VT_NULL:
strValue=_T("");
break;
case VT_DATE:
cur_time = (long)var.date;
time_value=cur_time;
strValue=time_value.Format("%A,%B%d,%Y");
break;
case VT_BOOL:
strValue.Format("%d",var.boolVal );
break;
default:
strValue=_T("");
break;
}
return strValue;
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/jia_xiaoxin/archive/2008/08/22/2815587.aspx