bool RenderFile(const char * inFile)
{
   int len;
   WCHAR szFilePath[MAX_PATH];
   //把传入的文件名转换成宽字符串
   len=MultiByteToWideChar(CP_ACP,0,inFile,-1,szFilePath,MAX_PATH); //len为什么一直为1......//这里略掉N多行代码,我的感觉是上面哪句没有转换成功,所以一直不会返回true
if(...)
  return true;return false;  // 正常是不会执行这一句的,因为}
//--------------bool test(const CString  &strSourceFile)
{ //Unicode模式下,把CString  转换成Char
    wchar_t *wchar;
CString str=strSourceFile;
wchar=str.GetBuffer();
str.ReleaseBuffer();
size_t convertedChars=0;
size_t sizeInBytes=((str.GetLength()+1)*2);
char *p=(char *)malloc(sizeInBytes);
wcstombs_s(&convertedChars,p,sizeInBytes,wchar,sizeInBytes);   

if (!RenderFile(p))//这里总为false
{  
MessageBox(__T("出错了"),__T("系统提示"),MB_ICONWARNING);
return false;
}
         return true;
}

解决方案 »

  1.   

    使用 CW2A() 和 CA2W() 就是了。
      

  2.   

    先写一个函数 , CStringW => CStringA 的以后复用就可以了,
      

  3.   

    你不是问过吗?现在的问题是你传进来的 const char * inFile,到底是什么格式的?从你的描述上看,你传进来的可能就是unicode的了。
      

  4.   

    是unicode格式的,以前问过了,但还不太明白,前段时间赶着工程所以一直没有继续学习 vc2005的字符串转换
      

  5.   

    又研究了一下,终于搞定 了,用GetString就OK,谢谢各位关注