现在有一段文字在txt文件里面 ,我需要把它读出来,转换成unicode。现在问题是可以正确读出 但是不能用unicodeMultiByteToWideChar转换成unicode(返回总是0,错误代码1113)。我发现一个怪问题:如果打开给我的1.txt后,我ctrl+a ctrl+v 然后新建一个2.txt 把内容拷贝进去之后 发现2个txt内容不相等 2.TXT 比 1.txt少了40个字节。我估计1.txt内有错误的unicodeMultiByteToWideChar不能转换的内容。现在我想知道 怎么解决上面的问题,还有,究竟是哪些字节unicodeMultiByteToWideChar是不能转换的

解决方案 »

  1.   

    1113
    ------------
    在多字节的目标代码页中,没有此 Unicode 字符可以映射到的字符。有特殊字符。
      

  2.   

    shunruo 什么样的多字节 unicode不能映射呢
    long result=MultiByteToWideChar( //计算从Ansi转换到Unicode后需要的字符数
    CP_ACP,
    MB_COMPOSITE|MB_ERR_INVALID_CHARS,
    (char*)m_TEXTCHARS, //要转换的Ansi字符串
    -1,
    LP,
    m_WIDECHARLEN
    );
    if(result==0)
    {
    DWORD aa=GetLastError();
    ::AfxMessageBox(_T("MultiByteToWideChar出错!"));
    return 0;
    }
    result = MultiByteToWideChar(CP_ACP,0,(char*)m_TEXTCHARS,-1,(LPWSTR)m_TEXTWCHARS,result);
      

  3.   

    正确的文章是可以转换的
    还是那个问题 “什么样的多字节   unicode不能映射呢 ”
      

  4.   

    long   result=MultiByteToWideChar(   //计算从Ansi转换到Unicode后需要的字符数 怎么没看你用result