回复: [cpp] 怎样转换一个ASIC字符串到宽字符形式?
sunpluto
sunpluto2004 at yahoo.com.cn
Thu Jun 8 21:43:14 CST 2006
第一个 MultiByteToWideChar 是用来获取UNICODE字串的字符长度
第二个 MultiByteToWideChar 是用来实际进行字符转换
不过,为了方便,我一般用
void func( LPSTR lpsz )
{
USES_CONVERSION;
...
LPWSTR x = A2W(lpsz)
// Do something with x
...
}
你可以参考 MSDN 的详细说明。
王峰 <finalclimber at gmail.com> 写道:
如题,我看了下mfc中Cstring的源码:
BSTR CString::AllocSysString() const
{
#if defined(_UNICODE) || defined(OLE2ANSI)
BSTR bstr = ::SysAllocStringLen(m_pchData, GetData()->nDataLength);
if (bstr == NULL)
AfxThrowMemoryException();
#else
int nLen = MultiByteToWideChar(CP_ACP, 0, m_pchData,
GetData()->nDataLength, NULL, NULL);
BSTR bstr = ::SysAllocStringLen(NULL, nLen);
if (bstr == NULL)
AfxThrowMemoryException();
MultiByteToWideChar(CP_ACP, 0, m_pchData, GetData()->nDataLength,
bstr, nLen);
#endif
return bstr;
}
有几点不明白,请各位大虾指点下:
第一:为什么使用
#if defined(_UNICODE) || defined(OLE2ANSI)
宏,使用和不使用时有什么区别
第二:在 #else 中函数怎么使用了2次函数
MultiByteToWideChar
--
>From 王峰 _______________________________________________
Cpp mailing list
Cpp at codingnow.com
http://codingnow.com/mailman/listinfo/cpp
致
礼
__________________________________________________
赶快注册雅虎超大容量免费邮箱?
http://cn.mail.yahoo.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://codingnow.com/pipermail/cpp/attachments/20060608/94bacc65/attachment.html
More information about the Cpp
mailing list