#include "stdafx.h"
int UnicodeToChar(char *Unicode, char *ASCText, unsigned short UnicodeLength)
{
int nwlen = 0;
int tlength = WideCharToMultiByte(CP_ACP,0,LPCWSTR(Unicode),UnicodeLength,0,0,0,FALSE);
wchar_t *pUnicode = new wchar_t[UnicodeLength];
while(nwlen<UnicodeLength)
{
pUnicode[nwlen] = (Unicode[2*nwlen]<<8)+(Unicode[2*nwlen+1]);
nwlen++;
}
tlength = WideCharToMultiByte(CP_ACP,0,pUnicode,UnicodeLength,ASCText,tlength,NULL,NULL);
return tlength;
}
//tlength is the unicode length in widechar;
int CharToUnicode(char *ASCText, char *Unicode, unsigned short ASCLength)
{
int nwlen = 0;
int tlength = MultiByteToWideChar(CP_ACP,0,ASCText,ASCLength,0,0);
wchar_t* pUnicode = new wchar_t[tlength];
tlength = MultiByteToWideChar(CP_ACP,0,ASCText,ASCLength,(LPWSTR)pUnicode,tlength);
while(nwlen<tlength)
{
Unicode[2*nwlen]=HIBYTE(pUnicode[nwlen]);
Unicode[2*nwlen+1]=LOBYTE(pUnicode[nwlen]);
nwlen++;
}
delete [] pUnicode;
return tlength;
}
WideCharToMultiByte与MultiByteToWideChar转化
最新推荐文章于 2021-12-28 10:26:26 发布