UNICODE Change to ASCII.
If your Use com, your should change char* to BSTR, and if get value must change BSTR to char*,All this thing _bstr_t can do for you.
If your Use com, your should change char* to BSTR, and if get value must change BSTR to char*,All this thing _bstr_t can do for you.
LPCOLESTR szFromBSTR;
szFromBSTR=bstrstr;
int nLen;
nLen=WideCharToMultiByte(CP_ACP,0,szFromBSTR,-1,NULL,NULL,NULL,NULL)
LPSTR szNewStdString;//这是转换的结果变量
szNewStdString=(char)malloc(nLen);
WideCharToMultiByte(CP_ACP,0,szFromBSTR,-1,szNewStrString,nLen,NULL,NULL);2,
如果使用_bstr_t , 问题就很轻松!
#include<comdef.h>BSTR bsYourString;
....
_bstr_t bstrYourString = bsYourString;CString str = (LPCTSTR)bstrYourString;
or
LPCTSTR lpszStr = (LPCTSTR)bstrYourString; 3,
#include"comutil.h"
{
char sz[]="hello";
_bstr_t b;
b = _com_util::ConvertStringToBSTR(sz);
char * p = _com_util::ConvertBSTRToString(b);
} BSTR是一个带长度前缀的字符串,主要由操作系统来管理的,所以要用api.主要用来和VB打交道的(VB里的string就是指它)要操作它的API函数有很多,具体可以去查一下msdn.比如SysAllocString,SysFreeString等等.vc里封装它的类如_bstr_t,及ATL中的CComBSTR等.一个 BSTR 由头部和字符串组成,头部包含了字符串的长度信息,字符串中可以包含嵌入的 null 值。BSTR 是以指针的形式进行传递的。
(指针是一个变量,包含另外一个变量的内存地址,而不是数据。) BSTR 是 Unicode 的,即每个字符需要两个字节。
BSTR 通常以两字节的 null 字符结束。#include <comdef.h>
VARIANT v1,v2;
_variant_t vt1(v1,true);
_variant_t vt2(v2,true);
_bstr_t bstradd = (_bstr_t)vt1+(_bstr_t)vt2;
_variant_t vtadd(bstradd);
VARIANT vadd = vtadd.Detach();
/*use vadd*/
VariantClear(&vadd);
wstr是宽字符,以双字节表示一个字符
bstr是为了与原先的basic字符兼容,它的最前面的4个字节为其长度,以'\0'结束
ansi就是我们常用的字符集
UTF-8是UCS Transformation Form – 8 的缩写。即ISO/IEC 10646-1和Unicode的变形显现形式的一种UTF-16是UCS Transformation Form – 16 的缩写。即ISO/IEC 10646-1和Unicode的变形显现形式的一种。它的目的是维持双八位的形式、同时也用一些特殊的双八位表示非基本多文种平面的一些字符。
这种C++语法清解释一下,谢谢!
_Doc::put_Text(BSTR newVal);
_Doc::get_Text(BSTR *pVal);
_Doc::PutText(_bstr_t newVal);
_bstr_t _Doc::GetText(void);You can use as:
_bstr_t bstr("Hello!");
_Doc::PutText(bstr); CString strText;
strText =(char *)_Doc::GetText();