Posted on 2009-04-07 23:33
魔のkyo 阅读(667)
评论(0) 编辑 收藏 引用
//宽字符转多字节
string WideToMutilByte(const wstring& _src)
{
int nBufSize = WideCharToMultiByte(GetACP(), 0, _src.c_str(),-1, NULL, 0, 0, FALSE);
char *szBuf = new char[nBufSize];
WideCharToMultiByte(GetACP(), 0, _src.c_str(),-1, szBuf, nBufSize, 0, FALSE);
string strRet(szBuf);
delete []szBuf;
szBuf = NULL;
return strRet;
}
//多字节转宽字符
wstring MutilByteToWide(const string& _src)
{
int nBufSize = MultiByteToWideChar(GetACP(),0,_src.c_str(),-1,NULL,0);
wchar_t *wsBuf = new wchar_t[nBufSize];
MultiByteToWideChar(GetACP(),0,_src.c_str(),-1,wsBuf,nBufSize);
wstring wstrRet(wsBuf);
delete []wsBuf;
wsBuf = NULL;
return wstrRet;
}