    void CUtf8Converter::GetUnicodeStringFromUTF8_2bytes( BYTE* pBuffer, LONG lCount, std::wstring& sOutput )
    {
        WCHAR* pUnicodeString = new WCHAR[lCount + 1];
        WCHAR* pStart = pUnicodeString;

        LONG lIndex = 0;
        while (lIndex < lCount)
        {
            BYTE byteMain = pBuffer[lIndex];
            if (0x00 == (byteMain & 0x80))
            {
                // 1 byte
                *pUnicodeString++ = (WCHAR)byteMain;
                ++lIndex;
            }
            else if (0x00 == (byteMain & 0x20))
            {
                // 2 byte
                int val = 0;
                if ((lIndex + 1) < lCount)
                {
                    val = (int)(((byteMain & 0x1F) << 6) |
                                (pBuffer[lIndex + 1] & 0x3F));
                }

                *pUnicodeString++ = (WCHAR)(val);
                lIndex += 2;
            }
            else if (0x00 == (byteMain & 0x10))
            {
                // 3 byte
                int val = 0;
                if ((lIndex + 2) < lCount)
                {
                    val = (int)(((byteMain & 0x0F) << 12) |
                                ((pBuffer[lIndex + 1] & 0x3F) << 6) |
                                (pBuffer[lIndex + 2] & 0x3F));
                }

                WriteUtf16_WCHAR(val, pUnicodeString);
                lIndex += 3;
            }
            else if (0x00 == (byteMain & 0x0F))
            {
                // 4 byte
                int val = 0;
                if ((lIndex + 3) < lCount)
                {
                    val = (int)(((byteMain & 0x07) << 18) |
                                ((pBuffer[lIndex + 1] & 0x3F) << 12) |
                                ((pBuffer[lIndex + 2] & 0x3F) << 6) |
                                (pBuffer[lIndex + 3] & 0x3F));
                }

                WriteUtf16_WCHAR(val, pUnicodeString);
                lIndex += 4;
            }
            else if (0x00 == (byteMain & 0x08))
            {
                // 4 byte
                int val = 0;
                if ((lIndex + 3) < lCount)
                {
                    val = (int)(((byteMain & 0x07) << 18) |
                                ((pBuffer[lIndex + 1] & 0x3F) << 12) |
                                ((pBuffer[lIndex + 2] & 0x3F) << 6) |
                                (pBuffer[lIndex + 3] & 0x3F));
                }

                WriteUtf16_WCHAR(val, pUnicodeString);
                lIndex += 4;
            }
            else if (0x00 == (byteMain & 0x04))
            {
                // 5 byte
                int val = 0;
                if ((lIndex + 4) < lCount)
                {
                    val = (int)(((byteMain & 0x03) << 24) |
                                ((pBuffer[lIndex + 1] & 0x3F) << 18) |
                                ((pBuffer[lIndex + 2] & 0x3F) << 12) |
                                ((pBuffer[lIndex + 3] & 0x3F) << 6) |
                                (pBuffer[lIndex + 4] & 0x3F));
                }

                WriteUtf16_WCHAR(val, pUnicodeString);
                lIndex += 5;
            }
            else
            {
                // 6 byte
                int val = 0;
                if ((lIndex + 5) < lCount)
                {
                    val = (int)(((byteMain & 0x01) << 30) |
                                ((pBuffer[lIndex + 1] & 0x3F) << 24) |
                                ((pBuffer[lIndex + 2] & 0x3F) << 18) |
                                ((pBuffer[lIndex + 3] & 0x3F) << 12) |
                                ((pBuffer[lIndex + 4] & 0x3F) << 6) |
                                (pBuffer[lIndex + 5] & 0x3F));
                }

                WriteUtf16_WCHAR(val, pUnicodeString);
                lIndex += 5;
            }
        }

        *pUnicodeString++ = 0;

        sOutput.append(pStart);

        delete [] pStart;
    }
    void CUtf8Converter::GetUnicodeStringFromUTF8_2bytes( BYTE* pBuffer, LONG lCount, std::wstring& sOutput )
    {
        WCHAR* pUnicodeString = new WCHAR[lCount + 1];
        WCHAR* pStart = pUnicodeString;

        LONG lIndex = 0;
        while (lIndex < lCount)
        {
            BYTE byteMain = pBuffer[lIndex];
            if (0x00 == (byteMain & 0x80))
            {
                 
                *pUnicodeString++ = (WCHAR)byteMain;
                ++lIndex;
            }
            else if (0x00 == (byteMain & 0x20))
            {
                 
                int val = 0;
                if ((lIndex + 1) < lCount)
                {
                    val = (int)(((byteMain & 0x1F) << 6) |
                                (pBuffer[lIndex + 1] & 0x3F));
                }

                *pUnicodeString++ = (WCHAR)(val);
                lIndex += 2;
            }
            else if (0x00 == (byteMain & 0x10))
            {
                 
                int val = 0;
                if ((lIndex + 2) < lCount)
                {
                    val = (int)(((byteMain & 0x0F) << 12) |
                                ((pBuffer[lIndex + 1] & 0x3F) << 6) |
                                (pBuffer[lIndex + 2] & 0x3F));
                }

                WriteUtf16_WCHAR(val, pUnicodeString);
                lIndex += 3;
            }
            else if (0x00 == (byteMain & 0x0F))
            {
                 
                int val = 0;
                if ((lIndex + 3) < lCount)
                {
                    val = (int)(((byteMain & 0x07) << 18) |
                                ((pBuffer[lIndex + 1] & 0x3F) << 12) |
                                ((pBuffer[lIndex + 2] & 0x3F) << 6) |
                                (pBuffer[lIndex + 3] & 0x3F));
                }

                WriteUtf16_WCHAR(val, pUnicodeString);
                lIndex += 4;
            }
            else if (0x00 == (byteMain & 0x08))
            {
                 
                int val = 0;
                if ((lIndex + 3) < lCount)
                {
                    val = (int)(((byteMain & 0x07) << 18) |
                                ((pBuffer[lIndex + 1] & 0x3F) << 12) |
                                ((pBuffer[lIndex + 2] & 0x3F) << 6) |
                                (pBuffer[lIndex + 3] & 0x3F));
                }

                WriteUtf16_WCHAR(val, pUnicodeString);
                lIndex += 4;
            }
            else if (0x00 == (byteMain & 0x04))
            {
                 
                int val = 0;
                if ((lIndex + 4) < lCount)
                {
                    val = (int)(((byteMain & 0x03) << 24) |
                                ((pBuffer[lIndex + 1] & 0x3F) << 18) |
                                ((pBuffer[lIndex + 2] & 0x3F) << 12) |
                                ((pBuffer[lIndex + 3] & 0x3F) << 6) |
                                (pBuffer[lIndex + 4] & 0x3F));
                }

                WriteUtf16_WCHAR(val, pUnicodeString);
                lIndex += 5;
            }
            else
            {
                 
                int val = 0;
                if ((lIndex + 5) < lCount)
                {
                    val = (int)(((byteMain & 0x01) << 30) |
                                ((pBuffer[lIndex + 1] & 0x3F) << 24) |
                                ((pBuffer[lIndex + 2] & 0x3F) << 18) |
                                ((pBuffer[lIndex + 3] & 0x3F) << 12) |
                                ((pBuffer[lIndex + 4] & 0x3F) << 6) |
                                (pBuffer[lIndex + 5] & 0x3F));
                }

                WriteUtf16_WCHAR(val, pUnicodeString);
                lIndex += 5;
            }
        }

        *pUnicodeString++ = 0;

        sOutput.append(pStart);

        delete [] pStart;
    }