组件对象模型与ATL实现
2010-09-04 20:48:02 来源:WEB开发网五 改变默认的索引基数和修改atlcom.h
最后要把以1为基数的索引,改为以0为基数的索引。这需要修改系统的头文件:atlcom.h。首先找到它,复制一份,更名为atlcom0.h,需要修改的地方我用粗体做了标记:
// atlcom.h--->atlcom0.h
template <class T, class CollType, class ItemType, class CopyItem, class EnumType>
class ICollectionOnSTLImpl : public T
{
public:
STDMETHOD(get_Count)(long* pcount)
{
if (pcount == NULL)
return E_POINTER;
ATLASSUME(m_coll.size()<=LONG_MAX);
*pcount = (long)m_coll.size();
return S_OK;
}
STDMETHOD(get_Item)(long Index, ItemType* pvar)
{
#ifdef ITEM_INDEX_0_BASEd
//Index is 0-based
if (pvar == NULL)
return E_POINTER;
if (Index < 0)
return E_INVALIDARG;
HRESULT hr = E_FAIL;
CollType::iterator iter = m_coll.begin();
while (iter != m_coll.end() && Index > 0)
{
iter++;
Index--;
}
if (iter != m_coll.end())
//hr = CopyItem::copy(pvar, &*iter);
hr = CopyItem::copy(pvar, *iter); // CL2
return hr;
#else
//Index is 1-based
if (pvar == NULL)
return E_POINTER;
if (Index < 1)
return E_INVALIDARG;
HRESULT hr = E_FAIL;
Index--;
CollType::const_iterator iter = m_coll.begin();
while (iter != m_coll.end() && Index > 0)
{
iter++;
Index--;
}
if (iter != m_coll.end())
//hr = CopyItem::copy(pvar, &*iter);
hr = CopyItem::copy(pvar, *iter); // CL2
return hr;
#endif
}
更多精彩
赞助商链接