[배움]/C++

char <-> String [펌] 출처가 기억이 안남 ...

도영수 2016. 8. 18. 17:49

CString char2CString(char* inp)

{

int len;

CString str;

BSTR buf;


len = MultiByteToWideChar(CP_ACP, 0, inp, (int)strlen(inp), NULL, NULL);

buf = SysAllocStringLen(NULL, len);

MultiByteToWideChar(CP_ACP, 0, inp, (int)strlen(inp), buf, len);

str.Format(_T("%s"), buf);


return str;

}



char* CString2char(CString& str)

{

long len = str.GetLength();

len = len * 2;

char* szTemp = new char[len + 1];

memset(szTemp, 0, len + 1);

USES_CONVERSION;

strcpy(szTemp, T2A(str));

return szTemp;

}