Unicode 转码 Ansi ,用于读取注册表后的值转换

 1 char* UnicodeToAnsi(TCHAR* wstr)     //转换字符编码
 2 {
 3     if( !wstr )
 4         return NULL;
 5 
 6     int strlen = ::WideCharToMultiByte(CP_ACP, NULL, wstr, wcslen(wstr), NULL, 0, NULL, FALSE);
 7     char* str = new char[strlen + 1];
 8     ::WideCharToMultiByte(CP_ACP, NULL, wstr, wcslen(wstr), str, strlen, NULL, FALSE);
 9     str[strlen] = '\0';
10 
11     return str;
12 }

读取注册表后转换为可用的 字符串!!!

posted @ 2016-01-28 18:32  Black丶Crow  阅读(413)  评论(0)    收藏  举报