CString 转换到 char* 缓冲区

来源:互联网 发布:孙尚香 知乎 编辑:程序博客网 时间:2024/05/21 21:35

//  http://blog.sina.com.cn/s/blog_6a6094d501011o7e.html   CString 转 char 的引用
  { //  CString2Char(openWndInfo.UseSceneName, apOption.useSceneName, openWndInfo.UseSceneName.GetLength()*2+1);
   CString str = openWndInfo.UseSceneName;

   //注意:以下n和len的值大小不同,n是按字符计算的,len是按字节计算的
   int n = str.GetLength();     // n = 14, len = 18

   //获取宽字节字符的大小,大小是按字节计算的
   int len = WideCharToMultiByte(CP_ACP,0,str,str.GetLength(),NULL,0,NULL,NULL);  

   //宽字节编码转换成多字节编码
   WideCharToMultiByte(CP_ACP,0,str,str.GetLength(), apOption.useSceneName,len,NULL,NULL);   
   WideCharToMultiByte(CP_ACP,0,str,str.GetLength() + 1 , apOption.useSceneName,len + 1 ,NULL,NULL);

   apOption.useSceneName[len+1] = '/0';   //多字节字符以'/0'结束 
  } 

 

引用原文:  http://blog.sina.com.cn/s/blog_6a6094d501011o7e.html

 

原创粉丝点击