1. char转wchar or tchar
WCHAR *CharToWideChar(char *str)
{
WCHAR *wstr=NULL;
int len=0;
len=MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
wstr = new WCHAR [len];
memset(wstr, 0x00, len);
MultiByteToWideChar(CP_ACP, 0, str, -1, wstr, len);
return wstr;
}
2. wchar or tchar转char
char *WideCharToChar(WCHAR *wstr)
{
int wlen=0;
char *str=NULL;
int len=0;
wlen=wcslen(wstr)&0xFFFFFFFF;
len = WideCharToMultiByte(CP_ACP, 0, wstr, wlen, NULL, 0, NULL, NULL);
str = new char [len+1];
memset(str, 0x00, len+1);
WideCharToMultiByte(CP_ACP, 0, wstr, -1, str, len, NULL, NULL);
str[len]='\0';
return str;
}