Skip to content

Instantly share code, notes, and snippets.

@MareArts
Last active January 4, 2017 01:01
Show Gist options
  • Save MareArts/2e3adae8672f4b23518dceec483782f6 to your computer and use it in GitHub Desktop.
Save MareArts/2e3adae8672f4b23518dceec483782f6 to your computer and use it in GitHub Desktop.
Unicode CString to char*
http://study.marearts.com/2017/01/unicode-cstring-convert-to-char.html
char * WtoC(CString str)
{
//CString str; //형변환할 문자열이 저장된 CString 변수
wchar_t* wchar_str; //첫번째 단계(CString to wchar_t*)를 위한 변수
char* char_str; //char* 형의 변수
int char_str_len; //char* 형 변수의 길이를 위한 변수
//1. CString to wchar_t* conversion
wchar_str = str.GetBuffer(str.GetLength());
//2. wchar_t* to char* conversion
//char* 형에 대한길이를 구함
char_str_len = WideCharToMultiByte(CP_ACP, 0, wchar_str, -1, NULL, 0, NULL, NULL);
char_str = new char[char_str_len]; //메모리 할당
//wchar_t* to char* conversion
WideCharToMultiByte(CP_ACP, 0, wchar_str, -1, char_str, char_str_len, 0, 0);
//Done.
return char_str;
}
@MareArts
Copy link
Author

MareArts commented Jan 4, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment