有木有哪位大侠写了好用的ANSI UNICODE 互转的宏定义。可靠的 安全的
如题。。。。。
我想问的是 方便好用,并且可靠的 宏定义 谢谢
[解决办法]
atlconv.h
[解决办法]
楼上说的就是了 不用ATL或MFC 就把里面的实现全复制下来就行了
[解决办法]
Unicode 转 ASCII
class Chars{public: Chars(const CString &str) { int length=WideCharToMultiByte(CP_ACP,0,str,-1,NULL,0,NULL,FALSE); ch=new char[length]; WideCharToMultiByte(CP_ACP,0,str,-1,ch,length,NULL,FALSE); } char* GetChars() { return ch; } ~Chars() { delete ch; }private: char* ch;};
[解决办法]
int ustr_astr(WCHAR * unicodestr, char *ansistr ){ int result = 0; try { int needlen = WideCharToMultiByte( CP_ACP, 0, unicodestr, -1, NULL, 0, NULL, NULL ); if( needlen < 0 ) { return needlen; } result = WideCharToMultiByte( CP_ACP, 0, unicodestr, -1, ansistr, needlen + 1, NULL, NULL ); if( result < 0 ) { return result; } return strlen( ansistr ); } catch( ... ) { } return result;}
[解决办法]
不是一二句话,用宏容易出问题