Article ID: 191738
Article Last Modified on 3/2/2005
int Except(LPEXCEPTION_POINTERS lpEP)
{
EXCEPTION_RECORD* pExcept = lpEP->ExceptionRecord;
if (pExcept->ExceptionCode != EXCEPTION_ACCESS_VIOLATION)
return EXCEPTION_CONTINUE_SEARCH;
BYTE* pAddress = (LPBYTE) pExcept->ExceptionInformation[1];
VirtualAlloc(pAddress, ((BYTE*)m_pTop - (BYTE*)m_pBase), MEM_COMMIT,
PAGE_READWRITE);
return EXCEPTION_CONTINUE_EXECUTION;
}
#include <oledberr.h>
class CDBEndOfRowset
{
};
template <class T, class TRowset = CRowset>
class CArrRowset:
public CVirtualBuffer<T>,
public TRowset
{
public:
CArrRowset(int nMax = 100000) : CVirtualBuffer<T>(nMax)
{
m_nRowsRead = 0;
}
int Except(LPEXCEPTION_POINTERS lpEP)
{
EXCEPTION_RECORD* pExcept = lpEP->ExceptionRecord;
if (pExcept->ExceptionCode != EXCEPTION_ACCESS_VIOLATION)
return EXCEPTION_CONTINUE_SEARCH;
BYTE* pAddress = (LPBYTE) pExcept->ExceptionInformation[1];
VirtualAlloc(pAddress, sizeof(T), MEM_COMMIT, PAGE_READWRITE);
return EXCEPTION_CONTINUE_EXECUTION;
}
T& operator[](int nRow)
{
ATLASSERT(nRow >= 0);
HRESULT hr;
T* m_pCurrent = m_pBase + m_nRowsRead;
T* pTEndofRowset = NULL;
// Retrieve the row if you haven't retrieved it already.
while ((ULONG)nRow >= m_nRowsRead)
{
m_pAccessor->SetBuffer((BYTE*)m_pCurrent);
__try
{
// Get the row.
hr = MoveNext();
if (hr == DB_S_ENDOFROWSET)
throw CDBEndOfRowset();
if (hr != S_OK)
{
*((char*)0) = 0; // Force exception.
}
}
__except(Except(GetExceptionInformation()))
{
}
m_nRowsRead++;
m_pCurrent++;
}
return *(m_pBase + nRow);
}
HRESULT Snapshot()
{
ATLASSERT(m_nRowsRead == 0);
ATLASSERT(m_spRowset != NULL);
HRESULT hr = MoveFirst();
if (FAILED(hr))
return hr;
do
{
Write(*(T*)m_pAccessor->GetBuffer());
m_nRowsRead++;
hr = MoveNext();
} while (SUCCEEDED(hr) && hr != DB_S_ENDOFROWSET);
return (hr == DB_S_ENDOFROWSET) ? S_OK : hr;
}
// Implementation.
ULONG m_nRowsRead;
};
Keywords: kbbug kbfix kbconsumer kbdatabase kbtemplate kbdtl kbmdacnosweep kbvs600sp3fix KB191738