Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
To access an object, the service manager needs to pass the object's unique HREPLITEMhandle to an IReplStoreor IReplObjHandlermethod. To the service manager, the handle is a 32-bit number created by the desktop provider. To the desktop provider, the handle is a pointer to an internal structure or class instance.
Using the time stamp or version number in the HREPLITEM, the desktop provider can determine whether two handles represent the same object, as well as which of the two handles represents the more-recent version. IReplStore::CompareItemcompare 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. |
0 |
The first object identifier is equal to the second object identifier. |
–1 |
The first object identifier is less than the second object identifier. |
Because the object identifiers are stored in an ascending-identifier sequence, the service manager can perform an efficient binary search, rather than checking every entry in the table. In the case where both items have changed, you should provide a secondary method of comparing them to determine which one should be kept.
The following code example shows how to implement IReplStore::CompareItem.
Note: |
---|
To make the following code example easier to read, error checking is not included. This code example should not be used in a release configuration unless it has been modified to include secure error handling. |
Copy Code | |
---|---|
STDMETHODIMP_(int) CMySyncClass::CompareItem ( HREPLITEM hItem1, HREPLITEM hItem2 ) { CItem* pObj1 = (CItem*)hItem1; CItem* pObj2 = (CItem*)hItem2; if( pObj1->IsConflictObject() ) { if( !pObj2->IsConflictObject() ) return 1; // Both are conflict objects, so use some other property // to compare the.objets if( pObj1->SecondaryCompareFunc > pObj2->SecondaryCompareFunc ) return 1; if( pObj1->SecondaryCompareFunc < pObj2->SecondaryCompareFunc ) return -1; return 0; } else if( pObj2->IsConflictObject() ) return -1; // Neither are conflict objects, so compare as usual if (pItem1->m_uid == pItem2->m_uid) return 0; if (pItem1->m_uid < pItem2->m_uid) return -1; return 1; } |
CFolderand CItemare COM classes based on CReplObject. The following code example shows the definition of these classes.
Copy Code | |
---|---|
#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)); } BOOL IsConflictObject(); BOOL SecondaryCompareFunc(); virtual ~CItem() {} UINT m_uid; FILETIME m_ftModified; }; |