参考:
https://blog.csdn.net/u011135902/article/details/50544678
//编码转换
//多字符集(包括ascii) 转 Unicode
WCHAR *mbcs2unicode(const char *mbcsstr)
{
int nByte;
WCHAR *unicodestr;
int codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
nByte = MultiByteToWideChar(codepage, 0, mbcsstr, -1, NULL, 0);
unicodestr = (WCHAR *)malloc(nByte * 2);
if (unicodestr == 0)
{
return 0;
}
nByte = MultiByteToWideChar(codepage, 0, mbcsstr, -1, unicodestr, nByte);
if (nByte == 0)
{
free(unicodestr);
unicodestr = 0;
}
return unicodestr;
}
//Unicode 转 utf-8
char *unicode2utf8(const WCHAR *unicodestr)
{
int nByte;
char *utf8str;
nByte = WideCharToMultiByte(CP_UTF8, 0, unicodestr, -1, 0, 0, 0, 0);
utf8str = (char*)malloc(nByte);
if (utf8str == 0)
return 0;
nByte = WideCharToMultiByte(CP_UTF8, 0, unicodestr, -1, utf8str, nByte, 0, 0);
if (nByte == 0)
{
free(utf8str);
utf8str = 0;
}
return utf8str;
}