C/C++

C++ 编码转换UTF8转GB2312,Ansi转Unicode,Unicode转Ansi

Utf8ToGb(char*);

AnsiToUnicode(char* ansi,UINT CP);

UnicodeToAnsi(char* Unicode,UINT CP)

void Utf8ToGb(char* ansi)
	{
		char *strSrc;
		char *szRes;
		int i = MultiByteToWideChar(CP_UTF8, 0, ansi, -1, NULL, 0);
		strSrc = new char[i*2];
		MultiByteToWideChar(CP_UTF8, 0, ansi, -1, (LPWSTR)strSrc, i);
		printf("%s",strSrc);
		i = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)strSrc, -1, NULL, 0, NULL, NULL);
		szRes = new char[i*2];
		WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)strSrc, -1, szRes, i, NULL, NULL);
		printf("%s",szRes);
		//ansi = szRes;
		strcpy(ansi,szRes);
	}
	void AnsiToUnicode(char* ansi,UINT CP)
	{
		if (CP == 0)
			CP = CP_UTF8;
		int i = MultiByteToWideChar(0, 0, ansi, -1, NULL, 0);
		char *Unicode;
		Unicode = new char[i*2];
		MultiByteToWideChar(CP, 0, ansi, -1, (LPWSTR)Unicode, i);
		strcpy(ansi,Unicode);
	}
	void UnicodeToAnsi(char* Unicode,UINT CP)
	{
		if (CP == 0)
			CP = 0;
		int i = WideCharToMultiByte(0, 0, (LPCWSTR)Unicode, -1, NULL, 0, 0, 0);
		char *ansi;
		ansi = new char[i*2];
		WideCharToMultiByte(CP, 0, (LPCWSTR)Unicode, -1, ansi, i*2, 0, 0);
		strcpy(Unicode,ansi);
	}
?

Image

0 条评论

发表评论

你需要登录后才可进行发表