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 );