[cpp] 胦랠杞ꊍ涓釜ASIC瀛ꚬ涓插낈瀹藉鞭绗舰寮㾏

軧嘲 finalclimber at gmail.com
Mon Jun 5 19:30:52 CST 2006


如题,我看了下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 王峰
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://codingnow.com/pipermail/cpp/attachments/20060605/a8e2f596/attachment.html


More information about the Cpp mailing list