【框架-MFC】CString转Char*

来源:互联网 发布:淘宝店推广平台 编辑:程序博客网 时间:2024/05/22 03:43
//////////////////////////////////////////////////////////////////////////void CMatManager::GetBuffer(const CString &strSource,char *pStrTemp){    int pathLength=strSource.GetLength();    for(int i=0; i<pathLength; i++)    {       * pStrTemp=strSource.GetAt(i);        pStrTemp++;    }     * pStrTemp='\0';}void test(){char p[256];CString sValue;GetBuffer(sValue,p);}//////////////////////////////////////////////////////////////////////////void CSheet::GetBuffer(const CString &strSource,char *pStrTemp)  {      DWORD dwNum = WideCharToMultiByte(CP_OEMCP,NULL,strSource,-1,NULL,0,NULL,FALSE);WideCharToMultiByte (CP_OEMCP,NULL,strSource,-1,pStrTemp,dwNum,NULL,FALSE);pStrTemp[dwNum]=0;  }  <pre name="code" class="cpp">(MBSC) 多字节char * Topchar(const CString &strSource)  {    char* pStrTemp = new char[strSource.GetLength()] ;#ifdef _UNICODE //UnicodeDWORD dwNum = WideCharToMultiByte(CP_OEMCP,NULL,strSource,-1,NULL,0,NULL,FALSE);WideCharToMultiByte (CP_OEMCP,NULL,strSource,-1,pStrTemp,dwNum,NULL,FALSE);pStrTemp[dwNum]=0;  #elif//MBCS 工程强转 pStrTemp = (LPSTR)(LPCTSTR)strSource;#endifreturn pStrTemp;}