char * ,wchar_t *, CString,unicode之间转来转去!
lostbar吧
全部回复
仅看楼主
level 7
阮Tea 楼主
CString string("I'm a string");
//将CString 转为 wchar_t *
wchar_t* wCharString = string.GetBuffer(string.GetLength()+1);
size_t wCharSize = wcslen(wCharString) + 1;
//const size_t newsize = MAXLEN;
//将wchar_t * 转为 char []
size_t convertedChars = 0;
char temp[MAXLEN];
wcstombs_s(&convertedChars, temp, wCharSize, wCharString , _TRUNCATE);
//char [] 转成 unicode
DWORD dwNum = MultiByteToWideChar (CP_ACP, 0, temp, -1, NULL, 0);
wchar_t *pwText;
pwText = new wchar_t[dwNum];
MultiByteToWideChar (CP_ACP, 0, temp, -1, pwText, dwNum);// 开始转换
2009年10月01日 17点10分 1
level 7
阮Tea 楼主
http://blog.sina.com.cn/s/blog_5ca9d9af0100d5pm.html
但是他自己后来综合的那个代码,运行结果是对的,但是退出的时候会报内存访问错误。
2009年10月01日 17点10分 2
level 7
阮Tea 楼主
char temp[20] = "I'm a char *";
unsigned short port = (unsigned   short)atoi(charString);
2009年10月01日 17点10分 3
1