#include "stdafx.h"
#include "CStringToolEx.h"
#include <cstringt.h>
//
// CStringA转CStringW
//
CStringW CStrA2CStrW(const CStringA &cstrSrcA)
{
int len = MultiByteToWideChar(CP_ACP, 0, LPCSTR(cstrSrcA), -1, NULL, 0);
wchar_t *wstr = new wchar_t[len];
memset(wstr, 0, len*sizeof(wchar_t));
MultiByteToWideChar(CP_ACP, 0, LPCSTR(cstrSrcA), -1, wstr, len);
CStringW cstrDestW = wstr;
delete[] wstr;
return cstrDestW;
}
//
// CStringW转CStringA
//
CStringA CStrW2CStrA(const CStringW &cstrSrcW)
{
int len = WideCharToMultiByte(CP_ACP, 0, LPCWSTR(cstrSrcW), -1, NULL, 0, NULL, NULL);
char *str = new char[len];
memset(str, 0, len);
WideCharToMultiByte(CP_ACP, 0, LPCWSTR(cstrSrcW), -1, str, len, NULL, NULL);
CStringA cstrDestA = str;
delete[] str;
return cstrDestA;
}