개발하는 두더지

[C/C++/MFC] Unicode Multibyte UTF8 변환 본문

C,C++

[C/C++/MFC] Unicode Multibyte UTF8 변환

덜지 2016. 7. 22. 03:30

unicode > multibyte

  • wchar_t strUnicode[256] = {0,};
  • char    strMultibyte[256] = {0,};
  • wcscpy_s(strUnicode,256,L"유니코드");
  • int len = WideCharToMultiByte( CP_ACP, 0, strUnicode, -1, NULL, 0, NULL, NULL );    
  • WideCharToMultiByte( CP_ACP, 0, strUnicode, -1, strMultibyte, len, NULL, NULL );

multibyte > unicode
  • wchar_t strUnicode[256] = {0,};
  • char    strMultibyte[256] = {0,};
  • strcpy_s(strMultibyte,256,"멀티바이트");
  • int nLen = MultiByteToWideChar(CP_ACP, 0, strMultibyte, strlen(strMultibyte), NULL, NULL);
  • MultiByteToWideChar(CP_ACP, 0, strMultibyte, strlen(strMultibyte), strUnicode, nLen);


unicode > utf8
  • wchar_t strUni[256] =L"유니코드";
  • char strUtf8[256] ={0,};
  • int nLen = WideCharToMultiByte(CP_UTF8, 0, strUni, lstrlenW(strUni), NULL, 0, NULL, NULL);
  • WideCharToMultiByte (CP_UTF8, 0, strUni, lstrlenW(strUni), strUtf8, nLen, NULL, NULL);

utf8 > unicode
  • wchar_t strUnicode[256] = {0,};
  • char    strUTF8[256] = {0,};
  • strcpy_s(strUTF8,256,"utf-8글자..");
  • int nLen = MultiByteToWideChar(CP_UTF8, 0, strUTF8, strlen(strUTF8), NULL, NULL);
  • MultiByteToWideChar(CP_UTF8, 0, strUTF8, strlen(strUTF8), strUnicode, nLen);


Comments