_variant_t 到 CString 转换

数据类型转换函数

CString CZjyDlg::VariantToString(VARIANT var)

{

CString strValue;

         _variant_t var_t;

         _bstr_t bstr_t;

         time_t cur_time;

         CTime time_value;

         COleCurrency var_currency;

         switch(var.vt)

         {

         case VT_EMPTY:

         case VT_NULL:strValue=_T("");break;

         case VT_UI1:strValue.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;

                   bstr_t=var_t;

                   strValue.Format("%s",(const char *)bstr_t);break;

         case VT_DATE:

                   cur_time=var.date;

                   time_value=cur_time;

                   strValue.Format("%A,%B,%d,%Y");break;

         case VT_BOOL:strValue.Format("%d",var.boolVal);break;

         default:strValue=_T("");break;

         }

         return strValue;

}




 来自: http://www.cppblog.com/ivenher/articles/2289.html
posted @ 2007-10-11 22:54  yfcomeon  阅读(1166)  评论(0编辑  收藏  举报