Февраль 9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Преобразование из UTF-8 в Win-1251
static AnsiString UTF8To1251(AnsiString str)
{
  UINT     pSLen   = str.Length();
  UINT     pBufLen = (pSLen + 1) * 2 * sizeof( wchar_t );
  wchar_t* pBuf    = new wchar_t[ pBufLen ];
  UINT     pResLen = (pSLen + 1) * 2 * sizeof( char );
  char*    pRes    = new char[ pResLen ];
  MultiByteToWideChar( CP_UTF8, 0, str.c_str(), -1, pBuf, pBufLen );
  WideCharToMultiByte( CP_ACP,  0, pBuf,        -1, pRes, pResLen, NULL, FALSE );
  AnsiString Ret(pRes);
  delete[] pBuf;
  delete[] pRes;
  return Ret;
}
//---------------------------------------------------------------------------