请求各位大哥给出utf8到unicode的算法,在下先表示谢了

解决方案 »

  1.   

    int LdapUTF8ToUnicode(
      LPCSTR lpSrcStr, 
      int cchSrc, 
      LPWSTR lpDestStr, 
      int cchDest
    );哥们用这个API函数吧,直接转
      

  2.   

    另附说明Parameters
    lpSrcStr 
    [in] Pointer to a null-terminated UTF-8 string to convert. 
    cchSrc 
    [in] Specifies the number of characters in the lpSrcStr string. 
    lpDestStr 
    [out] Pointer to a buffer that receives the converted Unicode string. 
    cchDest 
    [in] Specifies the size, in characters, of the lpDestStr buffer. 
    Return Values
    The return value is the number of characters written to the lpDestStr buffer.If the lpDestStr buffer is too small, GetLastError returns ERROR_INSUFFICIENT_BUFFER.Requirements
    Windows NT/2000/XP: Included in Windows NT 4.0 SP4 and later.
    Redistributable: Requires Active Directory Client Extension on Windows 95/98.
    Header: Declared in Winldap.h.
    Library: Use Wldap32.lib
      

  3.   

    MultiByteToWideChar就行了UTF8是MultiByte
      

  4.   

    UTF8 是 Unicode 的变种,MultiByteToWideChar不能转吧。如果是在Window上用可以直接用1楼兄弟给出的API,
    但要include 头文件 Winldap.h, 并且在项目属性里添加 Wldap32.lib的链接,或是直接用#pragma comment( lib, "Winldap" )声明 
      

  5.   

    如果不用API,vcbase上有段转换算法,直接给你转贴过来了,或许有用WCHAR* CXmlProcess::UTF_8ToUnicode(char *ustart)  //把UTF-8转换成Unicode
    {
    char char_one;
    char char_two;
    char char_three;
    int Hchar;
    int Lchar;
    char uchar[2];
    WCHAR *unicode;
    CString string_one;
    CString string_two;
    CString string_three;
    CString combiString;
    char_one = *ustart;
    char_two = *(ustart+1);
    char_three = *(ustart+2);
    string_one.Format("%x",char_one);
    string_two.Format("%x",char_two);
    string_three.Format("%x",char_three);
    string_three = string_three.Right(2);
    string_two = string_two.Right(2);
    string_one = string_one.Right(2);
    string_three = HexToBin(string_three.Left(1))+HexToBin(string_three.Right(1));
    string_two = HexToBin(string_two.Left(1))+HexToBin(string_two.Right(1));
    string_one = HexToBin(string_one.Left(1))+HexToBin(string_one.Right(1));
    combiString = string_one +string_two +string_three;
    combiString = combiString.Right(20);
    combiString.Delete(4,2);
    combiString.Delete(10,2);
    Hchar = BinToInt(combiString.Left(8));
    Lchar = BinToInt(combiString.Right(8));
    uchar[1] = (char)Hchar;
    uchar[0] = (char)Lchar;
    unicode = (WCHAR *)uchar;
    return unicode;
    }
      

  6.   

    int wNum = MultiByteToWideChar(CP_UTF8, 0, pStr, -1,  NULL, 0);
    WCHAR pWstr = new WCHAR[wNum +1];
    MultiByteToWideChar(CP_UTF8, 0, pStr, -1,  pWstr , wNum);