组件对象模型与ATL实现
2010-09-04 20:48:02 来源:WEB开发网原来的atlcom.h中有个小BUG,导致VS2005编译无法通过。在atlcom0.h文件中找到下面的函数:
STDMETHODIMP IEnumOnSTLImpl<Base, piid, T, Copy, CollType>::Next
更正之(只需要改变粗体的地方,一句话而已 ),即将
hr = Copy::copy(pelt, &*m_iter);
改为
hr = Copy::copy(pelt, *m_iter);
改过之后的完整的函数如下:
template <class Base, const IID* piid, class T, class Copy, class CollType>
STDMETHODIMP IEnumOnSTLImpl<Base, piid, T, Copy, CollType>::Next(ULONG celt, T* rgelt,
ULONG* pceltFetched)
{
if (rgelt == NULL || (celt != 1 && pceltFetched == NULL))
return E_POINTER;
if (pceltFetched != NULL)
*pceltFetched = 0;
if (m_pcollection == NULL)
return E_FAIL;
ULONG nActual = 0;
HRESULT hr = S_OK;
T* pelt = rgelt;
while (SUCCEEDED(hr) && m_iter != m_pcollection->end() && nActual < celt)
{
// hr = Copy::copy(pelt, &*m_iter);
hr = Copy::copy(pelt, *m_iter); // cheungmine
if (FAILED(hr))
{
while (rgelt < pelt)
Copy::destroy(rgelt++);
nActual = 0;
}
else
{
pelt++;
m_iter++;
nActual++;
}
}
if (SUCCEEDED(hr))
{
if (pceltFetched)
*pceltFetched = nActual;
if (nActual < celt)
hr = S_FALSE;
}
return hr;
}
这样,在你所有包含atlcom.h的地方,用atlcom0.h替换,并在包含atlcom0.h前面,加入如下的宏:
// stdafx.h
...
// NOT: #include <atlcom.h>
#define ITEM_INDEX_0_BASEd
#include "atlcom0.h" // 0-based index supports
更多精彩
赞助商链接