utf-8 转 UNICODE
要在程序中实现 utf-8 到 UNICODE 的转换。找了一段代码,有一句调不通,望高手指教。
谢谢。 上代码
CString CTestXmlDlg::UTF8ToString(const char *i_pszSource)
{
if(NULL == i_pszSource)
return "";
CString csTemp = "";
WCHAR *pwstrGroupName = NULL;
try
{
if(strlen(i_pszSource) == 0)
return "";
int iBufferLength = strlen(i_pszSource) * 2;
pwstrGroupName = new WCHAR[iBufferLength];
memset(pwstrGroupName, 0, sizeof(WCHAR) * iBufferLength);
int iConverted = LdapUTF8ToUnicode(i_pszSource, strlen(i_pszSource), pwstrGroupName, sizeof(WCHAR) * iBufferLength);
if(GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
// AfxMessageBox("缓冲区太小。");
delete []pwstrGroupName;
return "";
}
char *pszTemp = _com_util::ConvertBSTRToString(pwstrGroupName); //有问题??????!!!!
csTemp = pszTemp;
delete pszTemp;
}
catch(CMemoryException *pe)
{
// AfxMessageBox("内存错误,UTF8字符串无法转换为Unicode字符串。");
pe->ReportError();
}
catch(...)
{
// AfxMessageBox("UTF8字符串无法转换为Unicode字符串。");
// AfxMessageBox(i_pszSource);
}
if(pwstrGroupName)
delete []pwstrGroupName;
return csTemp;
}