Convert BSTR to lpstr

Source: Internet
Author: User
Method 1: Use convertbstrtostring. For example:

# Include
# Pragma comment (Lib, "comsupp. lib ")
Int _ tmain (INT argc, _ tchar * argv []) {
BSTR bstrtext =: sysallocstring (L "test ");
Char * lpsztext2 = _ com_util: convertbstrtostring (bstrtext );
Sysfreestring (bstrtext); // release after use
Delete [] lpsztext2;
Return 0;
}

Method 2: Use the _ bstr_t value assignment operator to overload. For example:

_ Bstr_t B = bstrtext;
Char * lpsztext2 = B;

Char * To BSTR

Method 1: Use API functions such as sysallocstring. For example:

BSTR bstrtext =: sysallocstring (L "test ");
BSTR bstrtext =: sysallocstringlen (L "test", 4 );
BSTR bstrtext =: sysallocstringbytelen ("test", 4 );

Method 2: Use colevariant or _ variant_t. For example:

// Colevariant strvar ("this is a test ");
_ Variant_t strvar ("this is a test ");
BSTR bstrtext = strvar. bstrval;

Method 3: Use _ bstr_t, which is the simplest method. For example:

BSTR bstrtext = _ bstr_t ("this is a test ");

Method 4: Use ccombstr. For example:

BSTR bstrtext = ccombstr ("this is a test ");

Or

Ccombstr BSTR ("this is a test ");
BSTR bstrtext = BSTR. m_str;

Method 5: Use convertstringtobstr. For example:

Char * lpsztext = "test ";
BSTR bstrtext = _ com_util: convertstringtobstr (lpsztext); Method 1: Use convertbstrtostring. For example:

# Include
# Pragma comment (Lib, "comsupp. lib ")
Int _ tmain (INT argc, _ tchar * argv []) {
BSTR bstrtext =: sysallocstring (L "test ");
Char * lpsztext2 = _ com_util: convertbstrtostring (bstrtext );
Sysfreestring (bstrtext); // release after use
Delete [] lpsztext2;
Return 0;
}

Method 2: Use the _ bstr_t value assignment operator to overload. For example:

_ Bstr_t B = bstrtext;
Char * lpsztext2 = B;

Char * To BSTR

Method 1: Use API functions such as sysallocstring. For example:

BSTR bstrtext =: sysallocstring (L "test ");
BSTR bstrtext =: sysallocstringlen (L "test", 4 );
BSTR bstrtext =: sysallocstringbytelen ("test", 4 );

Method 2: Use colevariant or _ variant_t. For example:

// Colevariant strvar ("this is a test ");
_ Variant_t strvar ("this is a test ");
BSTR bstrtext = strvar. bstrval;

Method 3: Use _ bstr_t, which is the simplest method. For example:

BSTR bstrtext = _ bstr_t ("this is a test ");

Method 4: Use ccombstr. For example:

BSTR bstrtext = ccombstr ("this is a test ");

Or

Ccombstr BSTR ("this is a test ");
BSTR bstrtext = BSTR. m_str;

Method 5: Use convertstringtobstr. For example:

Char * lpsztext = "test ";
BSTR bstrtext = _ com_util: convertstringtobstr (lpsztext );

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.