BSTR与char*转换
来源:互联网 发布:ps4连接不了网络 编辑:程序博客网 时间:2024/05/23 02:01
BSTR转换成char*
方法一,使用ConvertBSTRToString。例如:
#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); // 用完释放
delete[] lpszText2;
return 0;
}
方法二,使用_bstr_t的赋值运算符重载。例如:
_bstr_t b = bstrText;
char* lpszText2 = b;
char*转换成BSTR
方法一,使用SysAllocString等API函数。例如:
BSTR bstrText = ::SysAllocString(L"Test");
BSTR bstrText = ::SysAllocStringLen(L"Test",4);
BSTR bstrText = ::SysAllocStringByteLen("Test",4);
方法二,使用COleVariant或_variant_t。例如:
//COleVariant strVar("This is a test");
_variant_t strVar("This is a test");
BSTR bstrText = strVar.bstrVal;
方法三,使用_bstr_t,这是一种最简单的方法。例如:
BSTR bstrText = _bstr_t("This is a test");
方法四,使用CComBSTR。例如:
BSTR bstrText = CComBSTR("This is a test");
或
CComBSTR bstr("This is a test");
BSTR bstrText = bstr.m_str;
方法五,使用ConvertStringToBSTR。例如:
char* lpszText = "Test";
BSTR bstrText = _com_util::ConvertStringToBSTR(lpszText);
#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); // 用完释放
delete[] lpszText2;
return 0;
}
方法二,使用_bstr_t的赋值运算符重载。例如:
_bstr_t b = bstrText;
char* lpszText2 = b;
char*转换成BSTR
方法一,使用SysAllocString等API函数。例如:
BSTR bstrText = ::SysAllocString(L"Test");
BSTR bstrText = ::SysAllocStringLen(L"Test",4);
BSTR bstrText = ::SysAllocStringByteLen("Test",4);
方法二,使用COleVariant或_variant_t。例如:
//COleVariant strVar("This is a test");
_variant_t strVar("This is a test");
BSTR bstrText = strVar.bstrVal;
方法三,使用_bstr_t,这是一种最简单的方法。例如:
BSTR bstrText = _bstr_t("This is a test");
方法四,使用CComBSTR。例如:
BSTR bstrText = CComBSTR("This is a test");
或
CComBSTR bstr("This is a test");
BSTR bstrText = bstr.m_str;
方法五,使用ConvertStringToBSTR。例如:
char* lpszText = "Test";
BSTR bstrText = _com_util::ConvertStringToBSTR(lpszText);
- BSTR与char*转换
- BSTR、_bstr_t与CString、char *转换
- char * bstr CComBSTR 转换
- BSTR转换成char*
- BSTR转换成char*
- BSTR 和 char * 转换
- BSTR、char*和CString转换
- BSTR、char*和CString转换
- char * 和 BSTR的转换
- BSTR、char*和CString转换
- BSTR、char*和CString转换
- BSTR、char*和CString转换
- BSTR、char*和CString转换
- BSTR、char*和CString转换
- BSTR、char*和CString转换
- BSTR、char*和CString转换
- BSTR、char*和CString转换
- BSTR、char*和CString转换
- 黑马程序员_高新技术_代理
- no sapjco3 in java.library.path异常处理办法
- error C2146: syntax error : missing ';'
- c++基础
- 利用virtualbox的虚拟串口调试内核
- BSTR与char*转换
- 10 个需要了解的 Linux 网络和监控命令
- 用Visual Studio 2008开发IE BHO (浏览器帮助对象)之一
- 完美编程vim配置
- 快速加载properties文件
- linux 流量监控 ---iptraf的安装及使用
- HDU 4484 Hailstone HOTPO (简单模拟题)
- Intellij IDEA开发第一个android应用教程
- IIS原理