LPSTR : Long(32-bit) Pointer to a Character STRing.
이 데이터 형같은 경우 예전에 우리가 사용하던 방식으로 선언하면 char *
유니코드를 지원하지 않기 때문에 각각의 문자는 1바이트
LPCSTR : Long(32-bit) Pointer to a Constant Character STRing.
이 데이터 형같은 경우 예전에 우리가 사용하던 방식으로 선언하면 const char *
이것역시 유니코드를 지원하지 않기 때문에 각각의 문자는 1바이트
LPTSTR : Long(32-bit) Pointer to a Character STRing that is Portable for Unicode and DBCS.
이 데이터 형같은 경우, 윈도우즈가 유니코드를 지원하면서 새로 생긴형식 TCHAR *
이 형은 유니코드를 지원하기 때문에 각 문자가 2바이트
LPCTSTR : Long(32-bit) Pointer to a Constant Character STRing that is Portable for Unicode and DBCS.
이 데이터 형같은 경우, 윈도우즈가 유니코드를 지원하면서 새로 생긴형식 const TCHAR *
이 형은 유니코드를 지원하기 때문에 각 문자가 2바이트
오늘 이 string 형변환땜시 머리 아팠다.
여기 저기 찾아다니고 검색하고.. -_-
결국은 mfc에서는 LPTSTR과 LPCTSTR을 사용하는게 젤 속이 편할 듯 싶다. ㅋ
ex)
CString str = _T("456");
LPTSTR str1 = _T("fdfd");
MessageBox((LPCTSTR)str);
MessageBox((LPCTSTR)str1);
형변환
1.CString => LPTSTR
CString str;
LPTSTR lpsz = new TCHAR[str.GetLength()+1];
_tcscpy(lpsz, str);
3. CString -> char*
CString strData = "감사합니다";
int len = strData.GetLength();
char* sz = new char[len];
strcpy(sz, strData.GetBuffer(0));
5. unsigned char * -> const char *
ubsigned char *a;
const char *b = (const char*)a;
================= 시간표시에 좋은 포맷 ================
char szFileName[256];
char szTime[256]; //시간을 을 나타내가 위한 배열
CTime m_time; //시간을 담기 위한 변수
m_time = CTime::GetCurrentTime(); //현재 시간 얻어 오기
sprintf(szTime, "%04d년 %02d월 %02d일 %02d시 %02d분 %02d초", m_time.GetYear(),
m_time.GetMonth(),m_time.GetDay(),m_time.GetHour(),m_time.GetMinute(),
m_time.GetSecond());
//현재 시간을 szTime에 출력
sprintf(szFileName, "%04d년%02d월%02d일%02d시%02d분%02d초.bmp",
m_time.GetYear(),m_time.GetMonth(),m_time.GetDay(),
m_time.GetHour(),m_time.GetMinute(),m_time.GetSecond());
//파일 명을 현재 날짜와시간으로 저장하기 위해
'Dev > vc++, mfc, c#' 카테고리의 다른 글
[mfc]CString을 이용한 문자열 잘라내기 (0) | 2008.04.11 |
---|---|
unexpected end of file while looking for precompiled header directive (0) | 2008.03.19 |