-
[MFC] CString <-> char* 변환 (Unicode Character Set)C, C++/잡기장 | Notebook 2019. 11. 25. 14:50
1. char* -> CString (in Unicode Charater Set)
CString ConvertCharAstToCString(char* strInput)
{
// ## char* -> wchar_t -> CString ##
wchar_t* strWCHAR;
CString strOutput;
int iLength;
iLength = MultiByteToWideChar(CP_ACP, 0, strInput, strlen(strInput), NULL, NULL);
strWCHAR = SysAllocStringLen(NULL, iLength);
MultiByteToWideChar(CP_ACP, 0, strInput, strlen(strInput), strWCHAR, iLength);
strOutput.Format(_T("%s"), strWCHAR);
return strOutput;
}
2. CString -> char* (in Unicode Character Set)
char* ConvertCStringToCharAst(CString strInput)
{
// ## CString -> wchar_t -> char* ##
wchar_t* strWCHAR;
char* strOutput;
int iLength;
strWCHAR = strInput.GetBuffer(strInput.GetLength());
iLength = WideCharToMultiByte(CP_ACP, 0, strWCHAR, -1, NULL, 0, NULL, NULL);
strOutput = new char[iLength];
WideCharToMultiByte(CP_ACP, 0, strWCHAR, -1, strOutput, iLength, 0, 0);
return strOutput;
}
'C, C++ > 잡기장 | Notebook' 카테고리의 다른 글
[Win32 API] Win32 API 프로젝트 생성 및 Hello World (0) 2020.01.07 [C/C++] 파일 입출력 (fwrite, fread) (0) 2019.11.26 [MFC] 프로그램 간의 메시지 송수신 (RegisterWindowMessage, SendMEssage) (0) 2019.11.21 [MFC] Date Time Picker 컨트롤의 날짜 형식 변경 (0) 2019.10.01 [MFC] Cannot obtain CLSID from ProgID 오류 (0) 2019.09.26 댓글