最近写了一个WTL的项目,发现unicode环境下,CString转为char* 还是比较麻烦的。
-
CString str_ReourceText;
-
-
//get resource text
-
-
HWND hWndResourceText = GetDlgItem(IDC_SRC);
-
-
int int_ReourceText=::GetWindowTextLength(hWndResourceText);
-
-
int_ReourceText++;
-
-
LPTSTR lpStr = str_ReourceText.GetBufferSetLength(int_ReourceText);
-
-
::GetWindowText(hWndResourceText, lpStr, int_ReourceText);
-
-
char *output =NULL;
-
char *name= (char *)malloc(int_ReourceText);
-
CT2A ascii(str_ReourceText);
-
-
strcpy_s(name,int_ReourceText, ascii.m_psz);
转为 utf8
-
// Convert to UTF8
-
CString str(_T("Some Unicode goodness"));
-
CT2A ascii(str, CP_UTF8);
-
TRACE(_T("UTF8: %S\n"), ascii.m_psz);
-
-
// Convert to Thai code page
-
CString str(_T("Some Thai text"));
-
CT2A ascii(str, 874);
-
TRACE(_T("Thai: %S\n"), ascii.m_psz);
阅读(1510) | 评论(0) | 转发(0) |