Modifying the Inheritance of RMyProviderRowset

To add the IRowsetLocate interface to the simple read-only provider example, modify the inheritance of RMyProviderRowset. Initially, RMyProviderRowset inherits from CRowsetImpl. You need to modify it to inherit from CRowsetBaseImpl. To do this, create a new class, CMyRowsetImpl, in MyProviderRS.h:

////////////////////////////////////////////////////////////////////////
// MyProviderRS.h

template <class T, class Storage, class CreatorClass, class ArrayType = CSimpleArray<Storage> >
class CMyRowsetImpl:
   public CRowsetBaseImpl<T, Storage, CreatorClass, ArrayType>,
   public IRowsetLocateImpl<T>
{
   typedef CRowsetBaseImpl< T, Storage, CreatorClass, ArrayType> _RowsetBaseClass;

BEGIN_COM_MAP(CMyRowsetImpl)
   COM_INTERFACE_ENTRY_IID(IID_IRowsetLocate, IRowset)
   COM_INTERFACE_ENTRY(IRowset)
   COM_INTERFACE_ENTRY_CHAIN(_RowsetBaseClass)
END_COM_MAP()
};

Now, create a COM interface map that tells CMyRowsetImpl to call QueryInterface for both the IRowset and IRowsetLocate interfaces.

////////////////////////////////////////////////////////////////////////
// MyProviderRS.h

BEGIN_COM_MAP(CMyRowsetImpl)
   COM_INTERFACE_ENTRY_IID(IID_IRowsetLocate, IRowset)
   COM_INTERFACE_ENTRY(IRowset)
END_COM_MAP()

To get all of the implementation for the other rowset classes, link the CMyRowsetImpl class back to the CRowsetBaseImpl class defined by the OLE DB Templates. To do this, use a COM_INTERFACE_ENTRY_CHAIN macro, as shown in the following code. The COM_INTERFACE_ENTRY_CHAIN macro tells OLE DB Templates to scan the COM map in CRowsetBaseImpl in response to a QueryInterface call.

////////////////////////////////////////////////////////////////////////
// MyProviderRS.h

BEGIN_COM_MAP(CMyRowsetImpl)
   COM_INTERFACE_ENTRY_IID(IID_IRowsetLocate, IRowset)
   COM_INTERFACE_ENTRY(IRowset)
   COM_INTERFACE_ENTRY_CHAIN(_RowsetBaseClass)
END_COM_MAP()

Finally, link RAgentRowset to CMyRowsetBaseImpl by modifying RAgentRowset to inherit from CMyRowsetImpl, as shown here:

class RAgentRowset : public CMyRowsetImpl<RAgentRowset, CAgentMan, CMyProviderCommand>

RAgentRowset can now use the IRowsetLocate interface while taking advantage of the rest of the implementation for the rowset class.

When this is done, you are ready to implement IRowsetLocateImpl.