c++ widestring
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
/*
* convert to wide string
*/
wchar_t *ConvertWideChar(char *cstr)
{
int WLen = MultiByteToWideChar(CP_ACP, 0,cstr, -1,NULL,0);
wchar_t * buffer = new wchar_t[WLen+1];
int RetWLen = MultiByteToWideChar(CP_ACP, 0,cstr, -1,buffer,WLen);
buffer[WLen] = '\0';
return buffer;
}
/*
* convert to mutibyte string
*/
char *ConvertMutiString(wchar_t *buffer)
{
int MLen =WideCharToMultiByte(CP_ACP, 0,buffer, -1,NULL, 0, NULL, NULL);
char* MultiBte = new char[MLen+1];
int RetMLen = WideCharToMultiByte( CP_ACP, 0,buffer,-1,MultiBte,MLen,NULL,NULL);
MultiBte[MLen]='\0';
return MultiBte;
}
* convert to wide string
*/
wchar_t *ConvertWideChar(char *cstr)
{
int WLen = MultiByteToWideChar(CP_ACP, 0,cstr, -1,NULL,0);
wchar_t * buffer = new wchar_t[WLen+1];
int RetWLen = MultiByteToWideChar(CP_ACP, 0,cstr, -1,buffer,WLen);
buffer[WLen] = '\0';
return buffer;
}
/*
* convert to mutibyte string
*/
char *ConvertMutiString(wchar_t *buffer)
{
int MLen =WideCharToMultiByte(CP_ACP, 0,buffer, -1,NULL, 0, NULL, NULL);
char* MultiBte = new char[MLen+1];
int RetMLen = WideCharToMultiByte( CP_ACP, 0,buffer,-1,MultiBte,MLen,NULL,NULL);
MultiBte[MLen]='\0';
return MultiBte;
}