vc下用CFile读取文件时编码的问题 用CFile的成员函数读取一个非unicode文件是否能直接得到unicode编码的字符串呢,还是要自己手动转换 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 自己转换MultiByteToWideChar(); 必须自己转换。//**************************************// ansi字符串转unicode字符串// 返回大于0成功,小于0失败//**************************************intastr_ustr( char *ansistr, WCHAR *unicodestr, int len ){ int result = 0; try { int needlen; if( 0 == len ) { needlen = MultiByteToWideChar( g____ansi_codepage, 0, ansistr, -1, NULL, 0 ); if( needlen < 0 ) { return needlen; } result = MultiByteToWideChar( g____ansi_codepage, 0, ansistr, -1, unicodestr, needlen ); } else { needlen = MultiByteToWideChar( g____ansi_codepage, 0, ansistr, len, NULL, 0 ); if( needlen < 0 ) { return needlen; } result = MultiByteToWideChar( g____ansi_codepage, 0, ansistr, len, unicodestr, needlen ); } if( result < 0 ) { return result; } return result; } catch( ... ) { ShowError(); } return result;} ANSI 转 UNICODE的一种方法: //设置当前地域信息,不设置的话,使用这种方法,中文不会正确显示 //需要#include<locale.h> setlocale(LC_CTYPE, "chs"); wchar_t wcsStr[100]; //注意下面是大写S,在unicode中,代表后面是ansi字符串 //swprintf是sprintf的unicode版本 //格式的前面要加大写L,代表是unicode swprintf(wcsStr, L"%S", szAnsi); g____ansi_codepage最受不了这种风格,看见就烦!^_^ 程序退出的问题 关于Google Maps,想在CHtmlView的派生视里绘图和显示文字的高难度问题! ctreectrl中连续点击相同选项,如何响应? 简单 如何获得文字拷贝的消息事件 请问如何打开一个文件夹并获得其中文件的相关信息 ★★★★★给大家推荐一款局域网最好的通讯软件★★★★★ Linux下串口文件是哪一个?? 怎样实现TCP客户端和TCP服务器端文本信息和文件的同时传输? 各位请说一说对智能指针的理解,谢谢 问下如何查询MSDN问题 关于updatewindow函数
MultiByteToWideChar();
//**************************************
// ansi字符串转unicode字符串
// 返回大于0成功,小于0失败
//**************************************
int
astr_ustr( char *ansistr, WCHAR *unicodestr, int len )
{
int result = 0;
try
{
int needlen;
if( 0 == len )
{
needlen = MultiByteToWideChar( g____ansi_codepage, 0, ansistr, -1, NULL, 0 );
if( needlen < 0 )
{
return needlen;
}
result = MultiByteToWideChar( g____ansi_codepage, 0, ansistr, -1, unicodestr, needlen );
}
else
{
needlen = MultiByteToWideChar( g____ansi_codepage, 0, ansistr, len, NULL, 0 );
if( needlen < 0 )
{
return needlen;
}
result = MultiByteToWideChar( g____ansi_codepage, 0, ansistr, len, unicodestr, needlen );
} if( result < 0 )
{
return result;
}
return result;
}
catch( ... )
{
ShowError();
}
return result;
}
//设置当前地域信息,不设置的话,使用这种方法,中文不会正确显示
//需要#include<locale.h>
setlocale(LC_CTYPE, "chs");
wchar_t wcsStr[100];
//注意下面是大写S,在unicode中,代表后面是ansi字符串
//swprintf是sprintf的unicode版本
//格式的前面要加大写L,代表是unicode
swprintf(wcsStr, L"%S", szAnsi);
最受不了这种风格,看见就烦!^_^