In order for the service manager to access a data object, you must provide an HREPLITEM handle to the object. HREPLITEM is an important data type because each handle uniquely identifies one object. To the service manager, this handle is a 32-bit number created by the desktop provider module. To the desktop provider module, this handle is a pointer to an internal structure or class instance.
Whenever the service manager needs information about the object, it calls methods in IReplStore or IReplObjHandler and passes the HREPLITEM of the object as a parameter. From the object identifier and the time stamp or version number contained in the HREPLITEM, the desktop provider module can determine whether two handles represent the same object, as well as which of the two handles represents a more recent version of the object.
To compare information, IReplStore::CompareItem checks the object identifiers contained in the two handles. The following table shows the possible return values for this method.
Value |
Condition |
1 | The first object identifier is greater than the second object identifier. |
–1 | The first object identifier is less than the second object identifier. |
0 | The first object identifier is equal to the second object identifier. |
The ordering of the object identifiers allows the service manager to use a binary search on its table of object identifiers.
The following code example shows how to implement IReplStore::CompareItem.
STDMETHODIMP_(int) CStore::CompareItem
(
HREPLITEM hItem1, // Points to the handle of the first object.
HREPLITEM hItem2 // Points to the handle of the second object.
// Both handles are guaranteed to be
// returned by IReplStore::FindFirstObject or
// IReplStore::FindNextObject.
)
{
CItem *pItem1 = (CItem *)hItem1;
CItem *pItem2 = (CItem *)hItem2;
if ( pItem1->m_uid == pItem2->m_uid )
return 0;
if ( pItem1->m_uid < pItem2->m_uid )
return -1;
return 1;
}
CFolder and CItem are COM classes based on CReplObject. The following code example shows the definition of these classes.
#define OT_ITEM 1
#define OT_FOLDER 2
class CReplObject
{
public:
virtual ~CReplObject() {}
UINT m_uType;
};
class CFolder: public CReplObject
{
public:
CFolder( void ) { m_uType = OT_FOLDER; }
virtual ~CFolder() {}
};
class CItem: public CReplObject
{
public:
CItem( void ) { m_uType = OT_ITEM;
memset( &m_ftModified, 0, sizeof( m_ftModified )); }
virtual ~CItem() {}
UINT m_uid;
FILETIME m_ftModified;
};