삽질기초/SW

CString LPSTR WCHAR*

@가을바람 2009. 8. 30. 23:51

CString to LPSTR

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

str.ReleaseBuffer();
LPTSTR to LPWSTR
 Collapse
int nLen = MultiByteToWideChar(CP_ACP, 0, lptStr, -1, NULL, NULL);
MultiByteToWideChar(CP_ACP, 0, lptStr, -1, lpwStr, nLen);

CString to WCHAR*
 Collapse
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;


시리얼 프로그램 짜다가 찾음.





Data conversions with small examples