본문 바로가기
IT-개발,DB

[VC++] 문자열변환 CString LPSTR WCHAR* LPCWSTR

by SB리치퍼슨 2010. 9. 10.

VC++의 문자열 변환중 CString에 관련된 몇가지를 알아보자.


CString LPSTR WCHAR* LPCWSTR

CString to LPSTR

 CollapseCString str = _T("My String");
int nLen = str.GetLength();
LPTSTR lpszBuf = str.GetBuffer(nLen);
// here do something with lpszBuf...........

str.ReleaseBuffer();

 

LPTSTR to LPWSTR

int nLen = MultiByteToWideChar(CP_ACP, 0, lptStr, -1, NULL, NULL);
MultiByteToWideChar(CP_ACP, 0, lptStr, -1, lpwStr, nLen);


CString to WCHAR*

CString str = "A string here" ;
LPWSTR lpszW = new WCHAR[255];

LPTSTR lpStr = str.GetBuffer( str.GetLength() );
int nLen = MultiByteToWideChar(CP_ACP, 0,lpStr, -1, NULL, NULL);

MultiByteToWideChar(CP_ACP, 0, lpStr, -1, lpszW, nLen);
AFunctionUsesWCHAR( lpszW );
delete[] lpszW;


CString to LPCWSTR

CString a;
a.Format(_T("%d"), nDiffTime);
WCHAR *b;
b = a.GetBuffer(a.GetLength());

반응형

댓글