暂时测试先只有这么多,以后会陆续将代码贴上,算是做个笔记吧
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
// TODO: 在此添加控件通知处理程序代码
//Cstring->char*
/*char* str="aaa";
CString cstr=_T("");*/
//cstr.Format(_T("%s"),str);//不使用unicode成功
//CString->char* 不支持中文
//Cstring->char*
/*char* str="aaa";
CString cstr=_T("");*/
//cstr.Format(_T("%s"),str);//不使用unicode成功
//CString->char* 不支持中文
//方法一:
CString str=_T("中文");
char* lp=(char*)str.GetBuffer(str.GetLength()); //cstring转char*,不支持中文
str.ReleaseBuffer();
//方法二
CString str=_T("中文");
char* lp=(char*)str.GetBuffer(str.GetLength()); //cstring转char*,不支持中文
str.ReleaseBuffer();
//方法二
char schar[100];
WideCharToMultiByte( CP_OEMCP, NULL, str, -1, schar, 200, NULL, FALSE );
//char*----->cstring直接用cstring的构造函数
char* p="aaaaa";
CString cstr(p);
//cstring->BSTR
CString str2("This is a test");
BSTR bstrText2 = str2.AllocSysString();
//bstr->cstring
//方法一
CString str3(bstrText2);
//方法二:
BSTR bstrText = ::SysAllocString(L"Test");
CString str4;
str4.Empty();
str4 = bstrText;
//char*----->cstring直接用cstring的构造函数
char* p="aaaaa";
CString cstr(p);
//cstring->BSTR
CString str2("This is a test");
BSTR bstrText2 = str2.AllocSysString();
//bstr->cstring
//方法一
CString str3(bstrText2);
//方法二:
BSTR bstrText = ::SysAllocString(L"Test");
CString str4;
str4.Empty();
str4 = bstrText;
如果你有更好的方法,欢迎指教!