Re: Re: [cpp] 怎样转换一个ASIC字符串到宽字符形式?
DarkSpy
coneos at 21cn.com
Tue Jun 13 20:13:23 CST 2006
卢立璵(bad_fish),您好!
看世界杯吧.......
======= 2006-06-08 您在来信中写道:=======
>1、为什么使用#if defined(_UNICODE) || defined(OLE2ANSI)
>为了区分是否是 UNICODE 版本。
>
>2、在 #else 中函数怎么使用了2次函数MultiByteToWideChar
>第一次是预计算目标串的长度,以用来分配内存时知道大小。
>第二次才是真正的转换。
>
>
>
>On 6/5/06, 王峰 <finalclimber at gmail.com> wrote:
>> 如题,我看了下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
>>
>>
>
>_______________________________________________
>Cpp mailing list
>Cpp at codingnow.com
>http://codingnow.com/mailman/listinfo/cpp
>
= = = = = = = = = = = = = = = = = = = =
致
礼!
DarkSpy
coneos at 21cn.com
2006-06-13
More information about the Cpp
mailing list