TCHAR 转换为char

来源:互联网 发布:java项目开发ppt 编辑:程序博客网 时间:2024/05/28 17:06
 

转自: http://blog.pfan.cn/lym51/51055.html

void Wide2Bytes(char* pBytes,TCHAR* pWide)

{

         int nLen = WideCharToMultiByte(CP_ACP,0,pWide,-1,NULL,0,NULL,NULL);

         // get need convert length

          int i = (int)wcslen(pWide)*sizeof(TCHAR);

          // get need new memory size

           pBytes = new char[i+1];

           if (!pBytes) // if fail then new again

           {

                    pBytes = new char[i+1];

           }

           if(!pBytes) { return; }

          WideCharToMultiByte(CP_ACP,0,pWide,-1,pBytes,nLen,NULL,NULL);

 }

原创粉丝点击