Conversion between char, BSTR, _ bstr_t, and ccombstr

Source: Internet
Author: User

CHAR:
To BSTR:
_ Com_util: convertstringtobstr
Allocsystemstring of cstring
To _ bstr_t:
_ Bstr_t Constructor
To ccombstr:
Ccombstr Constructor

BSTR:
To char:
_ Com_util: convertbstrtostring
To _ bstr_t:
_ Bstr_t Constructor
To ccombstr:
Ccombstr Constructor

_ Bstr_t:
To char:
Lpctstr Operator
To BSTR:
BSTR Operator
To ccombstr:
Use the BSTR operator to convert to BSTR, and then use the ccombstr constructor.

Ccombstr:
To char:
Lpctstr Operator
To BSTR:
BSTR Operator
To _ bstr_t:

Use the BSTR operator or directly take the m_str member as the _ bstr_t constructor.

Cstring:

# Include "atlbase. H"

BSTR test1 =: sysallocstring (L "test OK !!! ");
Ccombstr test;
Test. Attach (test1); // = "adsfasdfsdf ";
Uses_conversion;
Cstring STR;
STR = w2a (test );
MessageBox (STR, mb_ OK );


Because BSTR m_str, a data member in ccombstr, is public and the & operator is overloaded, it is suitable for use as a function that uses BSTR as the outgoing parameter. However, pay attention to the memory leakage problem, do not use assigned ccombstr as an outgoing Parameter

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.