#include <windows.h>
#include "FileOp.h"
/**
* @brief 将UTF-8编码格式的字符串转换为ANSI编码格式的字符串
* @param[in] strUTF8 输入字符串
* @param[out] strAnsi 输出字符串缓冲区
* @param[in] iLen strAnsi缓冲区的大小
*/
int Utf8ToAnsi(const char* strUTF8, char* strAnsi, int iLen)
{
int len = MultiByteToWideChar(CP_UTF8, 0,strUTF8, -1, NULL, 0);
if ( len < 1 )
{
return len;
}
wchar_t *strUnicode = (wchar_t *)malloc(sizeof(wchar_t)*len);
if ( NULL == strUnicode )
{
return -1;
}
len = MultiByteToWideChar(CP_UTF8, 0, strUTF8, -1, strUnicode, len);
if ( len < 1 )
{
free(strUnicode);
return len;
}
len = WideCharToMultiByte(CP_ACP, 0, strUnicode, -1, NULL, 0, NULL, NULL);
if ( len < 1 )
{
free(strUnicode);
return len;
}
if ( iLen < len )
{
return len;
}
len = W
UTF-8转ANSI
最新推荐文章于 2025-02-23 23:36:09 发布