| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 
| 9 | 10 | 11 | 12 | 13 | 14 | 15 | 
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | 
| 23 | 24 | 25 | 26 | 27 | 28 | 29 | 
| 30 | 
- JPA
 - UE4
 - 삼성의 내구성은 고의인가
 - @JsonView
 - kospi
 - 유학
 - ue5
 - AT&T
 - weblogic
 - spring security
 - 필라델피아
 - 학생비자
 - java
 - 금융공학
 - 월화수목금토익
 - spring
 - rollbackOnly
 - spring message converters
 - 어학연수
 - flex하는게 아니었는데..
 - HRD
 - mastering unreal engine
 - jdk17
 - 펜실베이니아
 - 증시
 - 주식
 - mysql
 - 인물
 - 최근증시
 - paper2d
 
- Today
 
- Total
 
HeBhy, since 1983.
VC++ UTF-8 decode into Unicode 본문
#include <atlconv.h> // For USES_CONVERSION
CString DecodetoUtf8(LPCSTR utf8str)
{
 int size = MultiByteToWideChar(CP_UTF8, 0, utf8str, -1, NULL, 0);
 LPWSTR wStr = new WCHAR[size];
 MultiByteToWideChar(CP_UTF8, 0, utf8str, -1, wStr, size);
 USES_CONVERSION;
 CString str = W2CT(wStr);
 delete[] wStr;
 return str;
}
Encode
 1. 사용하는 문자셋(T) -> wchar(Unicode)
 2. Unicode -> UTF8
Decode
 1. UTF8 -> wchar(Unicode)
 2. Unicode -> 사용하는 문자셋(T)
 FILE* fp;
 
 if( (fp = fopen("c:\\rss.xml", "r")) == NULL)
 {
  AfxMessageBox("핸들링 오류");
  PostQuitMessage(-1);
 }
// TCHAR* tmp = new TCHAR[256];
char tmp[512];
 while(fgets(tmp, sizeof(tmp), fp) != NULL) {
  strcat(buf, tmp);
/************** test***********************/
// tmpstr.Format("tmp = %s", tmp);
// AfxMessageBox(tmpstr);   // -- debug
/*************************************/
 }
 fclose(fp);
/*************** test**********************/
 tmpstr.Format("buf = %s", buf);
TCHAR* des;
 //UTP8 -> ANSI_CHAR
 if(tmpstr.Find("UTF-8") > 30) // UTF-8 Documents
 {
  // ::API Method Calling
  tmpstr = DecodetoUtf8(tmpstr); //Return CString
  // Convert CString into TChar *
  des = new TCHAR[tmpstr.GetLength()+ 1]; 
  _tcscpy(des, tmpstr.GetBuffer(0));
  buf = des;
 
  str.Format("%s", buf);
  str.Replace("\n", "\r\n");
  // depend on XML Structure 
  _parseString->GetItemTitles(buf, strSize, m_li, CODEORDIE);
 }
 else       // For other Documents for now
 {
  str.Format("%s", buf);
  str.Replace("\n", "\r\n");
  _parseString->GetItemTitles(buf, strSize, m_li, _feedType);
 }
'Dev > Dev basics' 카테고리의 다른 글
| WIN32API - 윈도우 생성 기초 (0) | 2008.08.07 | 
|---|---|
| WIN32API - 윈도우 주요 메세지(Window Procedure) (0) | 2008.08.07 | 
| WINAPI - Mysql 연결과 간단한 쿼리 (0) | 2008.08.07 | 
| [AI] reaction이 가능한 AI (0) | 2007.09.13 | 
| [MMORPG] Concept of the Map-Structure (0) | 2007.09.13 |