_ Variant_t to cstring

Source: Internet
Author: User

1. Convert variant to cstring, or change the parameter type to _ variant_t.

 

# Include "comutil. H"
# Pragma comment (Lib, "comsupp. lib ")

Cstring 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_null: strvalue = _ T (""); break;
Case vt_empty: strvalue = _ T (""); break;
Case vt_ui1: strvalue. Format (_ T ("% d"), var. bval); break;
Case vt_i2: strvalue. Format (_ T ("% d"), var. ival); break;
Case vt_i4: strvalue. Format (_ T ("% d"), var. lval); break;
Case vt_r4: strvalue. Format (_ T ("% F"), var. fltval); break;
Case vt_r8: strvalue. Format (_ T ("% 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 (_ T ("% s"), (const tchar *) bst_t );
Break;
Case vt_date:
Cur_time = var. date;
Time_value = cur_time;
Strvalue = time_value.format (_ T ("% A, % B % d, % Y "));
Break;
Case vt_bool:
Strvalue. Format (_ T ("% d"), var. boolval );
Break;
Default: strvalue = _ T (""); break;
}

Return strvalue;
}

 

2. _ variant_t to int
Int cardstatus;
Var = precordset-> getcollect (_ T ("state "));
Cardstatus = v_i2 (& var );

 

3. _ variant_t to char *
Char p *;

P = (char *) (_ bstr_t) var;

 

4. Convert cstring to _ variant_t:
Cstring STR;
_ Variant_t var;
Var = (_ variant_t) (lpctstr) STR;

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.