Convert variant to cstring

Source: Internet
Author: User

Use the following function.
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;
}

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/jia_xiaoxin/archive/2008/08/22/2815587.aspx

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.