유니코드 환경에서 변환

CString uni_char_to_CString_Convert(char *data)

{

// Unicode char* -> CString 변환 과정

// char* -> wchar* -> CString 순서로 변환 되어야 함

int len;

CString str;

BSTR buf;

// 1. char* to wchar * conversion

len = MultiByteToWideChar(CP_ACP, 0, data, strlen(data), NULL, NULL);

buf = SysAllocStringLen(NULL, len);

MultiByteToWideChar(CP_ACP, 0, data, strlen(data), buf, len);

// 2. wchar_t* to CString conversion

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

return str;

}

char* CString_to_uni_char_Convert(CString data)

{

// Unicode CString -> char* 변환 과정

// CString -> wchar* -> char* 순서로 변환 되어야 함

wchar_t *wchar_str;

char *char_str;

int char_str_len;

// 1. CString to wchar * conversion

wchar_str = data.GetBuffer(data.GetLength());

char_str_len = WideCharToMultiByte(CP_ACP, 0, wchar_str, -1, NULL, 0, NULL, NULL);

char_str = new char[char_str_len];

// 2. wchar_t* to char* conversion

WideCharToMultiByte(CP_ACP, 0, wchar_str, -1, char_str, char_str_len, 0, 0);

return char_str ;

}

 

출처 : https://blog.naver.com/ikariksj/140186998237

+ Recent posts