Example #1
0
LPCWSTR StringUTF8ToWChar(LPCSTR sUTF8, CStringW &sWChar, int iChars/* = -1*/)
{
	if (!sUTF8)
		return NULL;

	sWChar.Empty();
	int iLen = MultiByteToWideChar(CP_UTF8, 0, sUTF8, iChars, NULL, 0);
	if (iLen > 0) {
		LPWSTR sBuf = sWChar.GetBufferSetLength(iLen);
		iLen = MultiByteToWideChar(CP_UTF8, 0, sUTF8, iChars, sBuf, iLen);
		sWChar.ReleaseBufferSetLength(sBuf[iLen - 1] ? iLen : iLen - 1);
		return (iLen > 0) ? sWChar.GetString() : NULL;
	}

	return *sUTF8 != 0 ? sWChar.GetString() : NULL;
}
Example #2
0
LPCWSTR StringCharToWChar(LPCSTR sChar, CStringW &sWChar, int iChars/* = -1*/, UINT codepage/* = CP_ACP*/)
{
	if (!sChar)
		return NULL;

	sWChar.Empty();
	int iLen = MultiByteToWideChar(codepage, 0, sChar, iChars, NULL, 0);
	if (iLen > 0) {
		LPWSTR sBuf = sWChar.GetBufferSetLength(iLen);
		MultiByteToWideChar(codepage, 0, sChar, iChars, sBuf, iLen);
		sWChar.ReleaseBufferSetLength(sBuf[iLen - 1] ? iLen : iLen - 1);
		return (iLen > 0) ? sWChar.GetString() : NULL;
	}

	return (*sChar != 0) ? sWChar.GetString() : NULL;
}
Example #3
0
CStringW ConvertStringToUnicode(const char* pSrc)
{
	CStringW strResult;
	UINT nCodePage = CP_GB18030;
	if (!IsValidCodePage(CP_GB18030))
	{
		nCodePage = _AtlGetConversionACP();
	}
	int iLength = ::MultiByteToWideChar(nCodePage, 0, pSrc, -1, NULL, 0);
	if (iLength)
	{
		iLength = ::MultiByteToWideChar(nCodePage, 0, pSrc, -1, strResult.GetBuffer(iLength), iLength);
		strResult.GetBuffer()[iLength] = 0;
		strResult.ReleaseBufferSetLength(iLength);
	}
	return strResult;
}