wchar_t *UTF8ToUnicode(const char* pu8, int utf8Len)
{
int nLen = MultiByteToWideChar(CP_UTF8, 0, pu8, utf8Len, NULL, 0);
if (nLen <=0)
{
return NULL;
}
wchar_t *uncode;
uncode = new wchar_t[nLen+1];
int nRtn = MultiByteToWideChar(CP_UTF8, 0, pu8, utf8Len, uncode, nLen);
if(nRtn != nLen)
{
delete []uncode;
return NULL;
}
uncode[nLen]=0;
return uncode;
}
char* UnicodeToUTF8(wchar_t* pun, int uLen)
{
// convert an widechar string to utf8
int utf8Len = WideCharToMultiByte(CP_UTF8, 0, pun, uLen, NULL, 0, NULL, NULL);
if (utf8Len<=0)
{
return NULL;
}
char *pu8;
pu8 = new char[utf8Len+1];
int nRtn = WideCharToMultiByte(CP_UTF8, 0, pun, uLen, pu8, utf8Len, NULL, NULL);
if (nRtn != utf8Len)
{
delete []pu8;
return NULL;
}
pu8[utf8Len]=0;
return pu8;
}